Specifying path to pdb symbol file in cmake

954 views Asked by At

I want to change the pdb symbol file path according to this doc and set /PDBALTPATH:%_PDB%. However, if I write

set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG
    /OPT:REF /OPT:ICF /PDBALTPATH:%_PDB%")

and check the result in the project properties, it reads /PDBALTPATH:%%_PDB%%. Leaving the percent signs out results in /PDBALTPATH:_PDB.

How do I achieve /PDBALTPATH:%_PDB% ?

Patterns I've tried so far (all of them turn a % into %% ):

  1. /PDBALTPATH:%_PDB%
  2. /PDBALTPATH:_PDB
  3. /PDBALTPATH:%25_PDB%25
  4. /PDBALTPATH:%%_PDB%%
1

There are 1 answers

0
IS3NY On

Since CMake 3.1 there is a TARGET_PDB_FILE_NAME generator expression (doc). It evaluates just to the name of the file, without the path.

So, you can achieve the effect of %_PDB% by replacing it with the actual name of the pdb file at generation-time. You'll need to specify the linker flags for each target of interest, though.

The command will be like so

# Suppose
add_library(foo ${foo_sources}) # or add_executable

# Then
target_link_options(foo PRIVATE /DEBUG /OPT:REF /OPT:ICF /PDBALTPATH:$<TARGET_PDB_FILE_NAME:foo>)