How do I get CMake to install the companion PDB files needed to debug Visual Studio generated DLL files and EXE files?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With