[CMake] Installing Visual Studio PDB files with CMake

Michael Hertling mhertling at online.de
Fri Nov 4 01:08:25 EDT 2011


On 11/03/2011 10:02 PM, Stephen Torri wrote:
> Searching the net for how to install PDB files with CMake comes up with no real solution. I can see from the mailing list archives that this issue had been brought up before. What is am acceptable way to install PDB files when compiling on Windows?
> 
> Stephen

The problem is that PDB files are usually generated next to their binary
in a configuration-specific directory which can not be accessed smoothly
by INSTALL(FILES ...). However, you can use a POST_BUILD custom command
in conjunction with generator expressions to copy the PDB files to a
well-known location where INSTALL(FILES ...) will find them, e.g.:

ADD_EXECUTABLE(main ...)
ADD_CUSTOM_COMMAND(TARGET main POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy_if_different
        $<TARGET_FILE_DIR:main>/main.pdb
        ${CMAKE_BINARY_DIR}/main.pdb)
INSTALL(FILES ${CMAKE_BINARY_DIR}/main.pdb DESTINATION ...)

Possibly, you might need to use a convenient CMake script or the
like instead of copy_if_different to account for missing PDB
files in non-debug configurations.

While this should work quite well, it would be nice if INSTALL()
has an idea of generator expressions, too, so it can find non-
target files residing in configuration-specific locations.
Perhaps, that's worth a feature request?

Regards,

Michael


More information about the CMake mailing list