[CMake] Re-setting CMAKE_C_COMPILER on command line discards CMAKE_C_FLAGS

Michael Hertling mhertling at online.de
Fri Aug 26 03:45:14 EDT 2011


On 08/25/2011 06:05 PM, Jed Brown wrote:
> $ cmake .. '-DCMAKE_C_COMPILER:FILEPATH=mpicc' '-DCMAKE_C_FLAGS:STRING=
> -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas'
> [no problems]
> $ grep CMAKE_C_FLAGS:STRING CMakeCache.txt
> CMAKE_C_FLAGS:STRING= -Wall -Wwrite-strings -Wno-strict-aliasing
> -Wno-unknown-pragmas
> $ cmake ..
> [no problems]
> $ grep CMAKE_C_FLAGS:STRING CMakeCache.txt
> CMAKE_C_FLAGS:STRING= -Wall -Wwrite-strings -Wno-strict-aliasing
> -Wno-unknown-pragmas
> $ cmake .. '-DCMAKE_C_FLAGS:STRING= -Wall -Wwrite-strings
> -Wno-strict-aliasing -Wno-unknown-pragmas'
> $ grep CMAKE_C_FLAGS:STRING CMakeCache.txt
> CMAKE_C_FLAGS:STRING= -Wall -Wwrite-strings -Wno-strict-aliasing
> -Wno-unknown-pragmas
> $ cmake .. '-DCMAKE_C_COMPILER:FILEPATH=mpicc' '-DCMAKE_C_FLAGS:STRING=
> -Wall -Wwrite-strings -Wno-strict-aliasing -Wno-unknown-pragmas'
> -- Configuring done
> You have changed variables that require your cache to be deleted.
> Configure will be re-run and you may have to reset some variables.
> The following variables have changed:
> CMAKE_C_COMPILER= mpicc
> [...]
> $ grep CMAKE_C_FLAGS:STRING CMakeCache.txt
> CMAKE_C_FLAGS:STRING=
> 
> 
> In this last case, I would expect CMAKE_C_FLAGS to be the value I set it to.
> I even thought that worked with cmake versions prior to 1.8.5, but I could
> be mistaken.

See [1-3] and additionally [4].

> Is there a way to reset both CMAKE_C_COMPILER and CMAKE_C_FLAGS in the same
> invocation, without just deleting CMakeCache.txt?

No, there isn't, AFAIK, and until 9980 is resolved, my recommendation is
the same as in [5,6]: Use one dedicated build tree per toolchain from
the first, don't change the toolchain after the build tree's initial
configuration and use the -C option if you have numerous settings
usually done via -D on the command line.

Regards

Michael

[1] http://www.mail-archive.com/cmake@cmake.org/msg37403.html
[2] http://www.mail-archive.com/cmake@cmake.org/msg37060.html
[3] http://www.mail-archive.com/cmake@cmake.org/msg34486.html
[4] http://public.kitware.com/Bug/view.php?id=9980
[5] http://www.mail-archive.com/cmake@cmake.org/msg37458.html
[6] http://www.mail-archive.com/cmake@cmake.org/msg37079.html


More information about the CMake mailing list