[CMake] MSVC71 problems when upgrading to CMake 2.6.2

Luke Kucalaba lkucalaba at dsci.com
Thu Oct 9 11:53:04 EDT 2008


Our software team is having problems upgrading to CMake 2.6.2 from our
current working build system that uses CMake 2.4.7.  In particular, we
are using the "Visual Studio 7 .NET 2003", "NMake Makefiles", "Unix
Makefiles", and "CodeBlocks - Unix Makefiles" project/makefile
generators.

 

We are having a problem generating "Visual Studio 7 .NET 2003" project
files. The primary symptom (among others) is that the compiler
definitions are not being set properly for the Debug and Release build
configurations.  We do not create RelWithDebugInfo and MinSizeRel build
configurations (not useful for us), by specifically calling
Set(CMAKE_CONFIGURATION_TYPES "Debug;Release").  Anyway, the strategy we
have used to set the compiler definitions for each build configuration
is to (1) construct a "debug" string that contains all the debug
compiler switches, (2) construct a "release" string that contains all
the release compiler switches, (3) set CMAKE_CXX_FLAGS_DEBUG and
CMAKE_CXX_FLAGS_RELEASE to use these switches, then call (4)
Add_Library() or Add_Executable() to use those switches for the build
configurations.  We have a main executable project that depends on
several static library projects, each of which are brought into the
solution using the Add_Subdirectory() cmake command before calling
Add_Executable().  

 

Our actual CMakeLists.txt are pretty complex, and we have a ton of
wrapper macros, so I'll just provide some pseudocode of the relevant
portions instead (I'll call the executable project "Exec" and the static
library project "Util"):

 

------------------------------------------------------------------------

Util/CMakeLists.txt

------------------------------------------------------------------------

Project("Util")

...

Set(sources Util.cpp)

Set(compilerFlagsDebug "/D _DEBUG /D WIN32 /DENABLE_UTIL_FLAG1
/DENABLE_UTIL_FLAG2") 

Set(compilerFlagsRelease "/D NDEBUG /D WIN32 /DENABLE_UTIL_FLAG1
/DENABLE_UTIL_FLAG2")

Set(CMAKE_CXX_FLAGS_DEBUG "${compilerFlagsDebug}" CACHE INTERNAL ""
FORCE)

Set(CMAKE_CXX_FLAGS_RELEASE "${compilerFlagsRelease}" CACHE INTERNAL ""
FORCE)  

Add_Library(Util STATIC ${sources})

 

Set_Target_Properties(Util 

    DEBUG_OUTPUT_NAME       "${targetFilenameDebug}"

    RELEASE_OUTPUT_NAME     "${targetFilenameRelease}"

    COMPILE_FLAGS_DEBUG     "${compilerFlagsDebug}"

    COMPILE_FLAGS_RELEASE   "${compilerFlagsRelease}"

    LINK_FLAGS_DEBUG        "${linkerFlagsDebug}"

    LINK_FLAGS_RELEASE      "${linkerFlagsRelease}"

)

 

------------------------------------------------------------------------

Exec/CMakeLists.txt

------------------------------------------------------------------------

Project("Exec")

Add_Subdirectory("${ABSOLUTE_PATH_UTIL_PROJECT_DIR}"
"${CMAKE_CURRENT_BINARY_DIR}/Util")

...

Set(sources Exec.cpp) 

Set(compilerFlagsDebug "/D _DEBUG /D WIN32 /DENABLE_EXEC_FLAG1
/DENABLE_EXEC_FLAG2") 

Set(compilerFlagsRelease "/D NDEBUG /D WIN32 /DENABLE_EXEC_FLAG1
/DENABLE_EXEC_FLAG2")

Set(CMAKE_CXX_FLAGS_DEBUG "${compilerFlagsDebug}" CACHE INTERNAL ""
FORCE)

Set(CMAKE_CXX_FLAGS_RELEASE "${compilerFlagsRelease}" CACHE INTERNAL ""
FORCE)  

Add_Executable(Exec WIN32 ${sources})

 

Set_Target_Properties(Exec 

    DEBUG_OUTPUT_NAME       "${targetFilenameDebug}"

    RELEASE_OUTPUT_NAME     "${targetFilenameRelease}"

    COMPILE_FLAGS_DEBUG     "${compilerFlagsDebug}"

    COMPILE_FLAGS_RELEASE   "${compilerFlagsRelease}"

    LINK_FLAGS_DEBUG        "${linkerFlagsDebug}"

    LINK_FLAGS_RELEASE      "${linkerFlagsRelease}"

)

 

Target_Link_Libraries(Exec Util)

Add_Dependencies(Exec Util)

 

------------------------------------------------------------------------

 

After we run cmake 2.6.2 for MSVC 7.1 successfully, the project/solution
files are generated.  The compiler definitions are set correctly in the
Exec project, but now the Util project contains the same exact flags as
the Exec project, as if the Exec project's CMAKE_CXX_FLAGS_DEBUG and
CMAKE_CXX_FLAGS_RELEASE were applied to both the Exec and Util projects.
With CMake 2.4.7, by setting the CMAKE_CXX_FLAGS just prior to the
Add_Library() or Add_Executable() command, it would apply the flags to
just that library or executable.  But now it seems like the Exec
project's CXX flags are overriding the Util project's CXX flags.

 

If anyone can look into these issues and offer some insight into why
this behavior has changed since 2.4.7, it would be greatly appreciated.
If we are doing something wrong with respect to setting specific
debug/release flags for visual studio build configuration, please let us
know what we need to do to get this to work again.  I tried a variety of
different solutions but I'm completely stumped at this point.  I tried
applying debug/release flags to each source file independently using
Set_Source_Files_Properties(), and setting the target properties using
Set_Target_Properties(), but nothing seems to work for cmake 2.6.2.  The
only way we could get this to work using CMake 2.4.7 is by setting the
CMAKE_CXX_FLAGS_<CONFIG> properties.

 

Thanks in advance!

 

Luke K

Senior Software Engineer

D&S Consultants, Inc

Columbus, Ohio

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20081009/20cff1cf/attachment-0001.htm>


More information about the CMake mailing list