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.
Phil
source share