[CMake] set(... CACHE ) broken for CMAKE_C_FLAGS_{DEBUG, RELEASE, ...} ?

Alexander Neundorf a.neundorf-work at gmx.net
Wed Jul 6 12:22:31 EDT 2011


On Wednesday 06 July 2011, Jerry Gagelman wrote:
> I'm redistributing a library for which the original authors have hand coded
> their own Makefile, but I would like to streamline everything with CMake.
> Their Makefile provides for Debug and Release flavored configurations, each
> has its own set of CFLAGS, and for consistency I would like to incorporate
> the same set of flags.
> 
> Using the following commands, the configuration can be selected in the
> cache:
> 
> if( DEFINED CMAKE_BUILD_TYPE )
> 
> set( CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "Options are: Debug
> Release")
> 
> else( DEFINED CMAKE_BUILD_TYPE )
> 
> set(CMAKE_BUILD_TYPE Debug CACHE STRING "Options are: Debug Release")
> 
> endif( DEFINED CMAKE_BUILD_TYPE )
> 
> 
> That works. Next, I tried to update the C_FLAGS :
> 
> 
> set( CMAKE_C_FLAGS_DEBUG "-Wall -Wno-format -g -DDEBUG" CACHE STRING
> "Recommended debug flags." )
> 
> set( CMAKE_C_FLAGS_RELEASE "-Wall -Wno-unknown-pragmas -Wno-format -O3"
> CACHE STRING "Recommended release flags." )


If these variables exist already in the cache, then a simple 
set(... CACHE ...)
does not override the value which is already in the cache.
You can only override a value in the cache from a CMakeLists.txt by using
set(... CACHE... FORCE)
This will put the given value always in the cache. Which also means if the 
user changes the value using "make edit_cache", the set(...CACHE ... FORCE) 
will override his changes again.

Is this the behaviour you are seeing ?

Alex


More information about the CMake mailing list