[CMake] Variable scope
Jorge Rodriguez
jrodriguez at providencesoftware.com
Mon Mar 21 14:49:09 EST 2005
I'm experiencing some strange behavior with variable scope in cmake 2.0.5.
To explain the situation, say I have this directory structure:
CMakeLists.txt
include.cmake
src/CMakeLists.txt
include.cmake has this:
# Figure out what version of the C++ compiler we're using so we
# can tag dlls with it later.
SET(VS_COMPILER "60")
IF(WIN32)
EXEC_PROGRAM(cl OUTPUT_VARIABLE COMPILER_VERSION)
IF(COMPILER_VERSION MATCHES ".*13\\.10.*")
SET(VS_COMPILER "71")
ENDIF(COMPILER_VERSION MATCHES ".*13\\.10.*")
ENDIF(WIN32)
in CMakeLists.txt (top-level) you have this:
PROJET(PROJ)
SET(VS_COMPILER "60")
INCLUDE(${PROJ_SOURCE_DIR}/include.cmake)
MESSAGE("Compiler 1: ${VS_COMPILER}")
SUBDIRS(src)
and in srcs/CMakeLists.txt:
MESSAGE("Compiler 2: ${VS_COMPILER}")
The output of this when cmake is run is:
Compiler 1: 71
Compiler 2: 60
So, it seems that the value of VS_COMPILER set in include.cmake is reset
in the srcs subdirectory to what it was originally set to. Am I
hallucinating?
Also, it's fairly apparent that the goal of this arrangement is to
determine what version of Microsoft's Visual Studio compiler is being
used. Is there a better way of doing that which I should be using instead?
More information about the CMake
mailing list