How to get CMake to install PDB files for purposes

How to get CMake to install related PDB files needed to debug Visual Studio DLL and EXE files?

+16
c ++ visual-studio cmake
source share
2 answers

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

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

The command will install a pdb file for each configuration that generates a pdb file. Using OPTIONAL , the install command will not OPTIONAL error if the original pdb file does not exist. This command is intended to be used for purposes created using add_library(${PROJECT_NAME}...) or add_executable(${PROJECT_NAME}...) .

This is the best answer I have found. Please let me know if there is a better one. I found the TARGET_PDB_FILE documentation for the TARGET_PDB_FILE generator difficult to understand in the "Information Expressions" section of the cmake-generator-expression expression documentation.

+18
source share

In addition, if you do not need a separate PDB file, you can use the Generate Debug Information optimized for sharing and publishing (/DEBUG:FULL) function for happy debugging. To do this, you need to set LINK_FLAGS for the target ${PROJECT_NAME} :

 set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS_DEBUG "-DEBUG:FULL" ) 

Or, if for some reason you cannot edit CMakeLists.txt you can set the cmake parameter:

+2
source share

All Articles