The following CMakeLists.txt
SET(CMAKE_CXX_FLAGS "/DWIN32")
SET(CMAKE_C_FLAGS ${CMAKE_CXX_FLAGS})
add_executable(hello hello.cpp)
ends up running
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\x86_amd64\CL.exe /c /nologo /W1 /WX- /O2 /Ob2 /D WIN32 /D NDEBUG /D "CMAKE_INTDIR=\"Release\"" /D _MBCS /Gm- /MD /GS /fp:precise /Zc:wchar_t /Zc:forScope /Fo"hello.dir\Release\\" /Fd"C:/Users/monso/code/playground/cmakeworld/build/Release /hello.pdb" /Gd /TP /errorReport:queue ..\hello.cpp
with flags /c /nologo /W1 /WX- /O2 /Ob2 /D WIN32 /D NDEBUG
.
How can I remove them to put my own? setting CMAKE_CXX_FLAGS
appends any flag I put (/w
for example). While printing CMAKE_CXX_FLAGS
before and after the set
call does change its values.
CMake uses distinct variables for each build type. They are called CMAKE_CXX_FLAGS_<BUILDTYPE>
and CMAKE_C_FLAGS_<BUILDTYPE>
So, for CXX, this would be
CMAKE_CXX_FLAGS_DEBUG
CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_CXX_FLAGS_MINSIZEREL
Additionally, it uses the settings in the "general" variable CMAKE_CXX_FLAGS
and CMAKE_C_FLAGS
So in order to get rid of the defaults, you would need to set the global or specific variable and clear the other one (or configure them as you need).
Note: If you want those changes in the cache, you need to use the FORCE
parameter. Otherwise, they are locally employed to this project and its child projects.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With