Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get CMake to install PDB files for targets

How do I get CMake to install the companion PDB files needed to debug Visual Studio generated DLL files and EXE files?

like image 707
Phil Avatar asked Nov 29 '16 07:11

Phil


1 Answers

I have struggled for a while trying to get a good answer to this question. I now think I have found one: use an install file command with the $<TARGET_PDB_FILE:tgt> generator expression (available in CMake 3.1.3 and newer). Specifically, the install command below seems to work. The command will copy the target ${PROJECT_NAME} pdb file to the target's installation bin directory.

install(FILES $<TARGET_PDB_FILE:${PROJECT_NAME}> DESTINATION bin OPTIONAL) 

The command will install the pdb file for each configuration that generates a pdb file. By using OPTIONAL the install command will not generate an error if the source pdb file does not exist. This command is meant to be used for targets created with add_library(${PROJECT_NAME} ...) or add_executable(${PROJECT_NAME} ...) commands.

This is the best answer I have found. Please let me know if there is a better one. I found some difficult to understand documentation of the TARGET_PDB_FILE generator experession at the "Informational Expressions" section of the cmake-generator-expressions documentation.

like image 186
Phil Avatar answered Sep 17 '22 20:09

Phil