MantisBT - CMake
View Issue Details
0015239CMakeCMakepublic2014-11-11 06:532015-04-06 09:07
DavidSto 
 
normalmajoralways
closedno change required 
CMake 2.8.12 
 
0015239: Escape %3B in preprocessor definitions
Bug fix:
http://www.cmake.org/pipermail/cmake-commits/2013-April/014836.html [^]
(Escape ; as %3B in preprocessor definitions - replace ; with %3B)
breaks the preprocessor definitions in Visual Studio 2012 (VS11)

It generates one line instead line breaks.
For example: "NDEBUG%3BwxDEBUG_LEVEL=0%3BFULLVERSION" instead of
NDEBUG
wxDEBUG_LEVEL=0
FULLVERSION
(with line breaks)
set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} "wxDEBUG_LEVEL=0;FULLVERSION")
set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} "wxDEBUG_LEVEL=0;FULLVERSION")
No tags attached.
related to 0014073closed Brad King VS2010 / VS2012 - Improper escape of semicolon in compile definition 
Issue History
2014-11-11 06:53DavidStoNew Issue
2014-11-11 08:33Brad KingRelationship addedrelated to 0014073
2014-11-11 08:36Brad KingNote Added: 0037171
2014-11-11 08:58DavidStoNote Added: 0037172
2014-11-11 09:04Brad KingNote Added: 0037173
2014-11-11 09:07Brad KingNote Added: 0037174
2014-11-11 09:08Brad KingNote Edited: 0037173bug_revision_view_page.php?bugnote_id=37173#r1616
2014-11-11 09:28DavidStoNote Added: 0037175
2014-11-11 09:29Brad KingNote Added: 0037176
2014-11-11 09:32Brad KingNote Added: 0037177
2014-11-11 10:30DavidStoNote Added: 0037179
2014-11-11 10:34Brad KingStatusnew => resolved
2014-11-11 10:34Brad KingResolutionopen => no change required
2015-04-06 09:07Robert MaynardNote Added: 0038441
2015-04-06 09:07Robert MaynardStatusresolved => closed

Notes
(0037171)
Brad King   
2014-11-11 08:36   
Add the definition using add_definitions or by setting a COMPILE_DEFINITIONS property. CMake knows how to escape those.

The *_FLAGS_* variable values go through without interpretation by CMake, and then the VS IDE project file format divides flags on ;.
(0037172)
DavidSto   
2014-11-11 08:58   
But this was not usable with custom CMAKE_CONFIGURATION_TYPES with the same or different preprocessor flags.
add_definitions are for all targets and all configuration types.
COMPILE_DEFINITIONS are for one target.
cmake 2.8.11 is the latest version it works.

For example:
        set(CMAKE_CONFIGURATION_TYPES "Debug;Release;Release_Full" CACHE STRING "limited configs" FORCE)
#release has the flag debug level = 0 for all targets
        set(CMAKE_CXX_FLAGS_RELEASE ${CMAKE_CXX_FLAGS_RELEASE} "wxDEBUG_LEVEL=0")
        set(CMAKE_C_FLAGS_RELEASE ${CMAKE_C_FLAGS_RELEASE} "wxDEBUG_LEVEL=0")
#release full -> grab release c and cxx flags and add some custom flags
        set(CMAKE_CXX_FLAGS_RELEASE_FULL ${CMAKE_CXX_FLAGS_RELEASE} "FULLVERSION;wxDEBUG_LEVEL=0")
        set(CMAKE_C_FLAGS_RELEASE_FULL ${CMAKE_C_FLAGS_RELEASE} "FULLVERSION;wxDEBUG_LEVEL=0")
(0037173)
Brad King   
2014-11-11 09:04   
(edited on: 2014-11-11 09:08)
The COMPILE_DEFINITIONS property is available at directory scope too. That's where add_definitions puts things. We've had COMPILE_DEFINITIONS_<CONFIG> properties for a long time to get per-config defintions. Since 2.8.10 the preferred way is to use generator expressions:

set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS $<$<CONFIG:Release_Full>:FULLVERSION>)

(0037174)
Brad King   
2014-11-11 09:07   
Re 0015239:0037171: Oops, I read the description backwards. CMake 2.8.12 is correctly escaping the ; in the flags as %3B. The *_FLAGS_* variables are considered to be command-line fragments and therefore space-separated. If you really don't want to use COMPILE_DEFINITIONS then add "-DFULLVERSION -DwxDEBUG_LEVEL=0" to the flags values.
(0037175)
DavidSto   
2014-11-11 09:28   
No problem.
Checked something:
I added "-DFULLVERSION -DwxDEBUG_LEVEL=0" to the compile variables.
Result:
set(CMAKE_CXX_FLAGS_RELEASE_FULL ${CMAKE_CXX_FLAGS_RELEASE} "-DFULLVERSION -DwxDEBUG_LEVEL=0")
set(CMAKE_C_FLAGS_RELEASE_FULL ${CMAKE_C_FLAGS_RELEASE} "-DFULLVERSION -DwxDEBUG_LEVEL=0")

cmake version 2.8.11.2 (not 2.8.12) generates -DwxDEBUG_LEVEL=0 -DFULLVERSION with an break (right)
cmake version 2.8.12.2 and higher -> after your patch generates: %3B-DwxDEBUG_LEVEL=0%3B-DFULLVERSION
it's not working with an space. And -D is for *nix flags.
(0037176)
Brad King   
2014-11-11 09:29   
set(CMAKE_CXX_FLAGS_RELEASE_FULL "${CMAKE_CXX_FLAGS_RELEASE} -DFULLVERSION -DwxDEBUG_LEVEL=0")
set(CMAKE_C_FLAGS_RELEASE_FULL "${CMAKE_C_FLAGS_RELEASE} -DFULLVERSION -DwxDEBUG_LEVEL=0")
(0037177)
Brad King   
2014-11-11 09:32   
The *_FLAGS_* variables have always been treated as a single string to put on the command line. The fact that ; worked before in the VS IDE generator before the fix in 2.8.12 was an accident, and it was actually the IDE that separated on ;. The fix made it possible to pass ; in definition values.
(0037179)
DavidSto   
2014-11-11 10:30   
set(CMAKE_CXX_FLAGS_RELEASE_FULL "${CMAKE_CXX_FLAGS_RELEASE} -DFULLVERSION -DwxDEBUG_LEVEL=0")
set(CMAKE_C_FLAGS_RELEASE_FULL "${CMAKE_C_FLAGS_RELEASE} -DFULLVERSION -DwxDEBUG_LEVEL=0")

works. :) so we can close the ticket.
(0038441)
Robert Maynard   
2015-04-06 09:07   
Closing resolved issues that have not been updated in more than 4 months.