MantisBT - CMake
View Issue Details
0015865CMakeCMakepublic2015-11-26 14:112016-06-10 14:31
temp4746 
Kitware Robot 
normalmajoralways
closedmoved 
WindowsWindows 77 SP1
CMake 3.4 
 
0015865: Can't use /PDBALTPATH:%_PDB% in MSVC IDE generator due to CMake escaping percent signs
When using the MSVC generator and using a linker flag that is added to the AdditionalOptions of the linker in the vcxproj, CMake will escape the linker flag.

For example it will double up percent signs in a flag such as:

/PDBALTPATH:%_PDB%

Resuling in:

/PDBALTPATH:%%_PDB%%

Which is wrong in the MSVC IDE but might be correct for makefile generators. This prevents using this flag properly.

Any fix for this need to be carefully thought out to prevent introducing an escaping bug in a different location in CMake.

BTW if you try using percent signs in a compiler option it will escape it TWICE meaning you get FOUR percent signs for one percent sign.
Try the following:

cmake_minimum_required(VERSION 3.4)
project(Bug)
add_executable(bug main.cpp)
set_target_properties(bug PROPERTIES LINK_FLAGS "/PDBALTPATH:%_PDB%")

And look in the IDE under linker->Command Line
No tags attached.
Issue History
2015-11-26 14:11temp4746New Issue
2015-12-18 15:10Davy DurhamNote Added: 0039998
2015-12-18 15:15Davy DurhamNote Edited: 0039998bug_revision_view_page.php?bugnote_id=39998#r1980
2015-12-18 15:18Brad KingNote Added: 0039999
2015-12-18 15:21Davy DurhamNote Added: 0040000
2015-12-21 08:56Brad KingNote Added: 0040010
2016-06-10 14:29Kitware RobotNote Added: 0042893
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0039998)
Davy Durham   
2015-12-18 15:10   
(edited on: 2015-12-18 15:15)
+1
I am also running into this.

I've tried 3.4.0 and 3.3.2.
I've tried various ways of attempting to escape or give the percent signs in other ways. No success.

(0039999)
Brad King   
2015-12-18 15:18   
The problem here is that CMake knows how to ensure that a literal "%" in a command line option is properly escaped, and there is no way for it to know that in this case you don't want a literal "%". To what do you expect %PDB% to evaluate if it were written to the project file without escaping?
(0040000)
Davy Durham   
2015-12-18 15:21   
Last paragraph: https://msdn.microsoft.com/en-us/library/dd998269.aspx [^]

It can be used to have the linker supply the filename (without the path) of the pdb file it's writing for the final exe/dll. This is more convenient as a general linker flag rather than something to do per target. I my case, the general linker flags are set up front and dozens of targets are later defined.
(0040010)
Brad King   
2015-12-21 08:56   
Thanks for explaining. The LINK_FLAGS property is meant as a last resort to add flags not supported by other means, and so generically supports strings. In this case I think the best solution is to offer a first-class interface, such as a target property, to activate this behavior. That way it can be implemented properly by each generator as needed. If interested in this, please read CONTRIBUTING.rst and raise this for discussion on the developer mailing list.
(0042893)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.