Reputation: 2135
I use CMake to generate build files (makefile or project files) across Windows, OSX and Linux, with C and C++ compilers native to those platforms. On Windows I gnerate VS 2010 project, and in Release configuration a following error occures:
Command line error D8016: '/ZI' and '/Ob2' command-line options are incompatible
Clearly, CMake generates optimization and debug information options which are not compatible. This is default CMake configuration, I do not setup any special flags.
I fix this by altering /ZI to /Z7 in the project options in Visual Studio, but this makes it annoying to setup continous integration system - I would need to add script to modify a project file.
Can I force CMake to gnerate /Z7 (C7 Compatible debug info) instead of /ZI?
In addition, how can I make it generate this only in Release configuration and not in Debug?
Upvotes: 1
Views: 4481
Reputation: 78270
I don't think CMake applies /ZI
to Release flags by default - it's probably being applied elsewhere in your CMakeLists.txt or one of the CMake files included by it.
Nonetheless, you can switch the flag by doing something like:
if(MSVC)
string(REGEX REPLACE "/Z[iI7]" ""
CMAKE_CXX_FLAGS_RELEASE
"${CMAKE_CXX_FLAGS_RELEASE}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Z7")
endif()
The first line strips all /Zi
, /ZI
and /Z7
flags if they already exist in the Release flags. Note the use of "
round "${CMAKE_CXX_FLAGS_RELEASE}"
. It's important that this CMake variable remains a single string. If the quotes are removed, the variable becomes a semi-colon separated list (i.e. each space is replaced by a semi-colon) and this is unsuitable for passing to the compiler.
You can give conflicting flags here if you want. So if you removed the string(REGEX REPLACE ...)
command and simply left the set
command, ${CMAKE_CXX_FLAGS_RELEASE}
could contain ... /ZI ... /Z7 ..."
, but as long as /Z7
is the last debug info flag, it "wins" and is the one which finally gets applied.
However, for the tiny amount of effort to clean up the variable first, I feel it's worth stripping conflicting flags.
Upvotes: 7