[CMake] Installing Visual Studio PDB files with CMake

Stephen Torri stephen.torri at gmail.com
Wed Nov 16 09:32:01 EST 2011


On 11/4/11, Michael Hertling <mhertling at online.de> wrote:
>
> 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?

I have finally gotten time to address this problem. In the top
CMakeLists.txt file I have set the CMAKE_ARCHIVE_OUTPUT_DIRECTORY,
CMAKE_LIBRARY_OUTPUT_DIRECTORY and CMAKE_RUNTIME_OUTPUT_DIRECTORY.
Therefore when I do a debug build within Visual Studio 2008 the DLLs,
PDBs and other files are placed in the appropriate directory. In this
case ${PROJECT_BINARY_DIR}/Bin/{CMAKE_BUILD_TYPE}. So for Debug I see
the files in ${PROJECT_BINARY_DIR}/bin/Debug.

So I don't need to specifically use the post build script you provided. What I
am stuck on is the INSTALL command. When I do I find that cpack will
expect the PDB file to exist for any build.

IF(MSVC)
  INSTALL ( FILES ${PROJECT_BINARY_DIR}/Bin/Debug/file.pdb DIRECTORY lib )
ENDIF(MSVC)

As it is written that is true. I am not sure how to make an INSTALL
command to only install the PDB files if the build type equals DEBUG.
At present running 'cpack' without any arguments tries to find the PDB
files. I thought that if I had CONFIGURATIONS set to Debug it would
not try to install the PDBs since cpack defaults to the RELEASE build.
What I got was an error from cpack that said it could not find a PDB
file. I changed the above to read:

IF(MSVC)
  INSTALL ( FILES ${PROJECT_BINARY_DIR}/Bin/Debug/file.pdb DIRECTORY
lib CONFIGURATIONS Debug )
ENDIF(MSVC)

Is this the correct way to restrict the PDB files to only be installed
if someone does "cpack -C Debug"?

Stephen


More information about the CMake mailing list