Description
Hi,
When building the 2.7.0 release tag source statically using CMake on Windows, I found that CMake errored out on installation of the Debug configuration PDB files. The issue seems to stem from the fact that when the GSL libraries are built statically, the PDB files are placed in ${PROJECT_BINARY_DIR}/Debug
, not ${PROJECT_BINARY_DIR}/bin/Debug
as is expected when building DLLs.
Here are some steps to reproduce my observation. I am using Visual Studio 2019 as the generator here, CMake 3.22, and all these commands are run from a Developer Command Prompt from the AMPL GSL top-level directory.
cmake -S . -B build_windows_x64 -A x64 -DGSL_INSTALL_MULTI_CONFIG=ON -DMSVC_RUNTIME_DYNAMIC=ON -DNO_AMPL_BINDINGS=1
cmake --build build_windows_x64 --config Debug -j
cmake --install build_windows_x64 --prefix install_windows_x64 --config Debug
Step 3. will error out with the following message from the generated cmake_install.cmake
:
CMake Error at build_windows_x64/cmake_install.cmake:61 (file):
file INSTALL cannot find
"C:/Users/Derek/START/gsl-2.7.0/build_windows_x64/bin/Debug/gsl.pdb": File
exists.
Fortunately, I was able to quickly trace the problem to this chunk in the top-level CMakeLists.txt
in the master
branch:
Lines 865 to 872 in 60539d2
Since the listed PDB files are rather in ${PROJECT_BINARY_DIR}/Debug
with the GSL .lib
static libraries instead of listed directory ${PROJECT_BINARY_DIR}/bin/Debug
, this install
command fails because the PDB files won't be found. To work around this on my end, I modified the CMakeLists.txt
at that location with some extra logic to instead read as follows:
# PDB file directories for shared GSL build
if(BUILD_SHARED_LIBS)
set(GSL_PDB_BUILD_DIR ${PROJECT_BINARY_DIR}/bin)
set(GSL_PDB_INSTALL_SUBDIR bin)
# PDB file directories for static GSL build
else()
set(GSL_PDB_BUILD_DIR ${PROJECT_BINARY_DIR})
set(GSL_PDB_INSTALL_SUBDIR lib)
endif()
# install PDB files for VS Debug configuration
install(
FILES
${GSL_PDB_BUILD_DIR}/Debug/gsl.pdb
${GSL_PDB_BUILD_DIR}/Debug/gslcblas.pdb
CONFIGURATIONS Debug
DESTINATION ${GSL_PDB_INSTALL_SUBDIR}/$<CONFIG>)
Making this modification resulted in PDB file installation to lib\Debug
of my chosen installation root as desired. However, I decided to make an issue about this to get some feedback on whether or not this is the approach to take here.