From adc088052098823e72f053bfa0c190bb3a46ed0c Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Thu, 9 Nov 2023 02:56:37 +0100
Subject: [PATCH] cmake: also install pdb files of static libraries
---
CMakeLists.txt | 13 +++++++++++--
cmake/macros.cmake | 20 ++++++++++++++++++++
test/CMakeLists.txt | 2 +-
3 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2dba6ca6d594..42a50609f18c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -3510,8 +3510,8 @@ if(NOT SDL2_DISABLE_INSTALL)
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
- if(MSVC AND NOT CMAKE_VERSION VERSION_LESS "3.1")
- install(FILES $<TARGET_PDB_FILE:SDL2> DESTINATION "${CMAKE_INSTALL_BINDIR}" OPTIONAL)
+ if(MSVC)
+ SDL_install_pdb(SDL2 "${CMAKE_INSTALL_BINDIR}")
endif()
endif()
@@ -3520,6 +3520,9 @@ if(NOT SDL2_DISABLE_INSTALL)
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
+ if(MSVC)
+ SDL_install_pdb(SDL2main "${CMAKE_INSTALL_LIBDIR}")
+ endif()
endif()
if(SDL_STATIC)
@@ -3527,6 +3530,9 @@ if(NOT SDL2_DISABLE_INSTALL)
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
+ if(MSVC)
+ SDL_install_pdb(SDL2-static "${CMAKE_INSTALL_LIBDIR}")
+ endif()
endif()
if(SDL_TEST)
@@ -3534,6 +3540,9 @@ if(NOT SDL2_DISABLE_INSTALL)
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}"
ARCHIVE DESTINATION "${CMAKE_INSTALL_LIBDIR}"
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}")
+ if(MSVC)
+ SDL_install_pdb(SDL2_test "${CMAKE_INSTALL_LIBDIR}")
+ endif()
endif()
##### Export files #####
diff --git a/cmake/macros.cmake b/cmake/macros.cmake
index 69a5d5464ac9..2087e54b681d 100644
--- a/cmake/macros.cmake
+++ b/cmake/macros.cmake
@@ -124,3 +124,23 @@ if(CMAKE_VERSION VERSION_LESS 3.13.0)
link_directories(${ARGN})
endmacro()
endif()
+
+# CMP0087: install(CODE) and install(SCRIPT) support generator expressions.
+cmake_policy(SET CMP0087 NEW)
+function(SDL_install_pdb TARGET DIRECTORY)
+ get_property(type TARGET ${TARGET} PROPERTY TYPE)
+ if(type MATCHES "^(SHARED_LIBRARY|EXECUTABLE)$")
+ if(NOT CMAKE_VERSION VERSION_LESS 3.1)
+ install(FILES $<TARGET_PDB_FILE:${TARGET}> DESTINATION "${DIRECTORY}" OPTIONAL)
+ endif()
+ elseif(type STREQUAL "STATIC_LIBRARY")
+ if(NOT CMAKE_VERSION VERSION_LESS 3.15)
+ # FIXME: Use $<TARGET_COMPILE_PDB_FILE:${TARGET} once it becomes available (https://gitlab.kitware.com/cmake/cmake/-/issues/25244)
+ if(CMAKE_GENERATOR MATCHES "^Visual Studio.*")
+ install(CODE "file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${DIRECTORY}\" TYPE FILE OPTIONAL FILES \"${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/${TARGET}.pdb\")")
+ else()
+ install(CODE "file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${DIRECTORY}\" TYPE FILE OPTIONAL FILES \"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET}.dir/${TARGET}.pdb\")")
+ endif()
+ endif()
+ endif()
+endfunction()
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index 17bf76402d0b..07ebf3426b4a 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -481,7 +481,7 @@ if(SDL_INSTALL_TESTS)
endif()
if(MSVC)
foreach(test ${SDL_TEST_EXECUTABLES})
- install(FILES $<TARGET_PDB_FILE:${test}> DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2" OPTIONAL)
+ SDL_install_pdb(${test} "${CMAKE_INSTALL_LIBEXECDIR}/installed-tests/SDL2")
endforeach()
endif()
install(