[Cmake] Setting Variables in CMAKE

William A. Hoffman billlist at nycap.rr.com
Mon, 26 Apr 2004 15:57:55 -0400


There really should not be any commands before the PROJECT command,
and after the project command CMakeDetermineSystem.cmake will have
been included automatically.

I just tried this and it worked:

PROJECT(TRY)
SET(MYFLAG "default")
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
       SET(MYFLAG "linuxValue")
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
SUBDIRS(a b) # if the system is Linux then MYFLAG should be set in both a and b.


What version of cmake are you using?  

-Bill


At 11:13 PM 4/22/2004, Linton, Tom wrote:
>I have a source tree with a top level CMakeLists.txt file that contains
>something like:
>
>    INCLUDE(${CMAKE_ROOT}/Modules/CMakeDetermineSystem.cmake)
>    SET(MYFLAG "defaultValue")
>    IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
>       SET(MYFLAG "linuxValue")
>    ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
>    PROJECT(TRY)
>    SUBDIRS(a b)
>
>The behavior of CMAKE is that (1) in the top-level CMakeLists.txt the variable
>"MYFLAG" gets set to "linuxValue" wherease (2) in the subdirectories
>"MYFLAG" is left at "defaultValue". 
>
>I tried changing the SET command like: 
>    SET(MYFLAG "defaultValue" CACHE INTERNAL "myflag")
>but this had no effect.
>
>I want to set variables at top-level based on the system name and have these
>variables propagate to the subdirectories and it seems like what I'm doing is
>correct, according to section 3.4 in the CMake book, which say that variable
>scope is limited to a CMakeList file and any subdirectory CMakeList files.
>
>This seems like a really basic thing to want to do. Any suggestions on
>what's going wrong?
>
>Thanks
>
>Tom
>
>_______________________________________________
>Cmake mailing list
>Cmake at www.cmake.org
>http://www.cmake.org/mailman/listinfo/cmake