From 9989c9f8f1fac87798160203b8e674cbc44f5ff6 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Wed, 28 Oct 2020 20:57:35 +0300 Subject: common.cmake: add install_pdbs() --- common.cmake | 20 ++++++++++++++++++++ examples/boost/CMakeLists.txt | 4 +--- examples/dynamic/CMakeLists.txt | 4 +--- examples/simple/CMakeLists.txt | 4 +--- examples/static/CMakeLists.txt | 4 +--- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/common.cmake b/common.cmake index c67f983..546db7d 100644 --- a/common.cmake +++ b/common.cmake @@ -222,3 +222,23 @@ if(NOT parent_dir) _cc_apply_settings("${target}") endmacro() endif() + +function(install_pdbs) + if(NOT is_msvc) + return() + endif() + cmake_parse_arguments(INSTALL_PDBS "" "DESTINATION" "TARGETS" ${ARGN}) + if(NOT INSTALL_PDBS_DESTINATION) + message(FATAL_ERROR "common.cmake: install_pdbs: please specify DESTINATION") + endif() + if(NOT INSTALL_PDBS_TARGETS) + message(FATAL_ERROR "common.cmake: install_pdbs: please specify TARGETS") + endif() + if(INSTALL_PDBS_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "common.cmake: install_pdbs: unrecognized arguments: ${INSTALL_PDBS_UNPARSED_ARGUMENTS}") + endif() + foreach(target ${INSTALL_PDBS_TARGETS}) + list(APPEND pdbs "$") + endforeach() + install(FILES ${pdbs} DESTINATION ${INSTALL_PDBS_DESTINATION} OPTIONAL) +endfunction() diff --git a/examples/boost/CMakeLists.txt b/examples/boost/CMakeLists.txt index 8c076c9..c4d5edb 100644 --- a/examples/boost/CMakeLists.txt +++ b/examples/boost/CMakeLists.txt @@ -9,6 +9,4 @@ add_executable(foo foo.cpp) target_link_libraries(foo PRIVATE Boost::disable_autolinking Boost::filesystem) install(TARGETS foo RUNTIME DESTINATION bin) -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - install(FILES "$" DESTINATION bin OPTIONAL) -endif() +install_pdbs(TARGETS foo DESTINATION bin) diff --git a/examples/dynamic/CMakeLists.txt b/examples/dynamic/CMakeLists.txt index 4602adb..190b1c9 100644 --- a/examples/dynamic/CMakeLists.txt +++ b/examples/dynamic/CMakeLists.txt @@ -11,6 +11,4 @@ add_executable(foo foo.cpp) target_link_libraries(foo PRIVATE baz) install(TARGETS foo baz RUNTIME DESTINATION bin LIBRARY DESTINATION lib) -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - install(FILES "$" "$" DESTINATION bin OPTIONAL) -endif() +install_pdbs(TARGETS foo baz DESTINATION bin) diff --git a/examples/simple/CMakeLists.txt b/examples/simple/CMakeLists.txt index 4f8859e..268b5db 100644 --- a/examples/simple/CMakeLists.txt +++ b/examples/simple/CMakeLists.txt @@ -7,6 +7,4 @@ include(../../common.cmake) add_executable(foo foo.cpp) install(TARGETS foo RUNTIME DESTINATION bin) -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - install(FILES "$" DESTINATION bin OPTIONAL) -endif() +install_pdbs(TARGETS foo DESTINATION bin) diff --git a/examples/static/CMakeLists.txt b/examples/static/CMakeLists.txt index 8a6acb8..e418aab 100644 --- a/examples/static/CMakeLists.txt +++ b/examples/static/CMakeLists.txt @@ -11,6 +11,4 @@ add_executable(foo foo.cpp) target_link_libraries(foo PRIVATE bar) install(TARGETS foo bar RUNTIME DESTINATION bin ARCHIVE DESTINATION lib) -if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - install(FILES "$" DESTINATION bin OPTIONAL) -endif() +install_pdbs(TARGETS foo DESTINATION bin) -- cgit v1.2.3