[Cmake] CMake SET + CMakeCache.txt
Neil Killeen
Neil.Killeen at atnf.csiro.au
Mon Apr 7 21:25:22 EDT 2003
Brad
On Mon, 7 Apr 2003, Brad King wrote:
> > I am looking for a mechanism for use in a CMakeLists.txt file by which I
> > can APPEND to- rather than INITIALIZE- the contents of a cmake variable
> > , in this case CMAKE_CXX_FLAGS so that when so that when I run ccmake,
> > what I appended and what was already there will appear.
> >
> > Is that possible ? I would have expected this is a common thing to want
> > to do, since how else can the ccmake user know what has been set if it
> > does not appear in the GUI ?
>
> If you really want to do this, you can write
>
> SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -foo -bar" CACHE STRING "" FORCE)
>
> However, this will append the values EVERY TIME cmake runs. You'll then
> need some check to see if the flags are already there:
>
> IF(CMAKE_CXX_FLAGS MATCHES "-foo")
> # Flag already there.
> ELSE(CMAKE_CXX_FLAGS MATCHES "-foo")
> SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -foo"
> CACHE STRING "" FORCE)
> ENDIF(CMAKE_CXX_FLAGS MATCHES "-foo")
>
> This is strongly discouraged, however. Adding compiler flags is very
> platform-specific. If it is detected that a certain platform is running,
> and it is known that a certain compiler flags is needed (such as
> -ftemplate-depth-50 on g++) then you should just append the flag using
>
> SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftemplate-depth-50")
>
> and it will show up in the makefiles. There is no need to expose this
> requirement to the user, however. Having CMAKE_CXX_FLAGS in the GUI is
> mostly there to allow users to select warning/optimization/debug levels.
>
> -Brad
>
perhaps i am exposing some more lack of understanding in cmake (seems
likely !) but...
If I do
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")
then the ccmake user does not see the new string -Wno-deprecated. OK,
but what if they then decide to put some text on the line themselves
with the ccmake GUI interface.
Is this new text that they type in appended to what I had set above or
does it replace it ?
I had assumed that whatever the user types via the ccmake interface
is a replacement value. Clearly, in this case, a replacement value
would be the wrong thing.
Thus, this is why I wanted them to be able to see what I had put there
so that they wouldn't accidentally overwrite it.
cheers
Neil
More information about the CMake
mailing list