Append compiler flags through command line
I'd like to append C/C++ flags from command line (when invoking cmake) so they append to default ones and not overwrite them.
In my environment the default C-flags are CMAKE_C_FLAGS:STRING=/DWIN32 /D_WINDOWS /W3
(according to the generated CMakeCache.txt
).
When I try to "customize" the build with a command like cmake -DCMAKE_C_FLAGS="-DDEFINED_IN_CLI" ..
, the default C-flags are lost and replaced with CMAKE_C_FLAGS:STRING=-DDEFINED_IN_CLI
(I guess, it may be an expected behavior, but loosing default flags is bad).
After that reverting to the "standard" build with cmake ..
isn't possible - the flags aren't restored to default state (not a big issue though - I can start from scratch).
The expected behavior: the flags specified in the command line should be added to the default ones.
Probably this functionality is already available through other means.
The tricky approach with modifying environment doesn't work either:
...\build>cmake -E env "CFLAGS=/DDEFINED_IN_CLI" ..
Access is denied
But this seems to be another story.
Version: CMake 3.21.4
Generator: VS2019 16.11.2
C compiler: MSVC 19.29.30133.0
OS: Windows 10 x64