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

Alexander Neundorf a.neundorf-work at gmx.net
Wed Jul 6 14:08:28 EDT 2011


On Wednesday 06 July 2011, Jerry Gagelman wrote:
> 2011/7/6 Alexander Neundorf <a.neundorf-work at gmx.net>
> 
> > On Wednesday 06 July 2011, Jerry Gagelman wrote:
> > 
> > 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 ?
> 
> Thanks. That is the behavior I'm seeing. But it's still not satisfactory.
> Is it not possible to "initialize" variables in the cache with values
> using the set() command?
> 
> I just tried the following, ignoring the cache altogether:
> 
> set( CMAKE_C_FLAGS_DEBUG "-Wall -Wno-format -g -DDEBUG" )
> set( CMAKE_C_FLAGS_RELEASE "-Wall -Wno-unknown-pragmas -Wno-format -O3" )


Should work. Are you sure there is not typo ?
 
> I rebuilt everything, ensured that the CMAKE_BUILD_TYPE variable in the
> cache is set to "Debug," 

I'm not quite sure about case-sensitivity here, would have to check.
Does it work if you set the buildtype tp "DEBUG" instead of "Debug" ?

> and built the library using verbose Makefiles. The
> compilation commands don't include the extra CMAKE_C_FLAGS_DEBUG flags as
> directed.
> 
> I even tried it without quotes around the flag strings.
> 
> Evidently the cache is overriding commands in CMakeLists.txt.

No, it's not. Non-cache variables basically shadow the cache variables.

You know that the variables above are for C, and there is the same set of 
variables also for C++ ? CMAKE_CXX_FLAGS_DEBUG etc.
Could it be that you have a C++ project and you did set only the C variables ?

Alex


More information about the CMake mailing list