From 784c8436fd3dcc44560652df78d261eef949a4f0 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Mon, 9 Apr 2018 16:21:27 +0300 Subject: [PATCH] cmake: update PDB installation --- 3rdparty/protobuf/CMakeLists.txt | 2 ++ cmake/OpenCVUtils.cmake | 51 ++++++++++++++++++-------------- 2 files changed, 30 insertions(+), 23 deletions(-) diff --git a/3rdparty/protobuf/CMakeLists.txt b/3rdparty/protobuf/CMakeLists.txt index e506fe9642..0ebbd11e38 100644 --- a/3rdparty/protobuf/CMakeLists.txt +++ b/3rdparty/protobuf/CMakeLists.txt @@ -142,6 +142,8 @@ set_target_properties(libprotobuf FOLDER "3rdparty" OUTPUT_NAME libprotobuf DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}" + COMPILE_PDB_NAME libprotobuf + COMPILE_PDB_NAME_DEBUG "libprotobuf${OPENCV_DEBUG_POSTFIX}" ARCHIVE_OUTPUT_DIRECTORY ${3P_LIBRARY_OUTPUT_PATH} ) diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index a43d39df66..19f05b8d52 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -1027,14 +1027,17 @@ function(ocv_install_target) set(${__package}_TARGETS "${${__package}_TARGETS}" CACHE INTERNAL "List of ${__package} targets") endif() - if(MSVS) - if(NOT INSTALL_IGNORE_PDB AND - (INSTALL_PDB OR - (INSTALL_CREATE_DISTRIB AND NOT BUILD_SHARED_LIBS) - )) + if(MSVC) + if(INSTALL_PDB AND (NOT INSTALL_IGNORE_PDB)) set(__target "${ARGV0}") - set(isArchive 0) + set(__location_key "ARCHIVE") # static libs + get_target_property(__target_type ${__target} TYPE) + if("${__target_type}" STREQUAL "SHARED_LIBRARY") + set(__location_key "RUNTIME") # shared libs (.DLL) + endif() + + set(processDst 0) set(isDst 0) unset(__dst) foreach(e ${ARGN}) @@ -1042,34 +1045,36 @@ function(ocv_install_target) set(__dst "${e}") break() endif() - if(isArchive EQUAL 1 AND e STREQUAL "DESTINATION") + if(processDst EQUAL 1 AND e STREQUAL "DESTINATION") set(isDst 1) endif() - if(e STREQUAL "ARCHIVE") - set(isArchive 1) + if(e STREQUAL "${__location_key}") + set(processDst 1) else() - set(isArchive 0) + set(processDst 0) endif() endforeach() # message(STATUS "Process ${__target} dst=${__dst}...") if(DEFINED __dst) - # If CMake version is >=3.1.0 or <2.8.12. - if(NOT CMAKE_VERSION VERSION_LESS 3.1.0 OR CMAKE_VERSION VERSION_LESS 2.8.12) - get_target_property(fname ${__target} LOCATION_DEBUG) - if(fname MATCHES "\\.lib$") - string(REGEX REPLACE "\\.lib$" ".pdb" fname "${fname}") - install(FILES "${fname}" DESTINATION "${__dst}" CONFIGURATIONS Debug OPTIONAL) + if(NOT CMAKE_VERSION VERSION_LESS 3.1.0) + set(__pdb_install_component "pdb") + if(DEFINED INSTALL_PDB_COMPONENT AND INSTALL_PDB_COMPONENT) + set(__pdb_install_component "${INSTALL_PDB_COMPONENT}") endif() - - get_target_property(fname ${__target} LOCATION_RELEASE) - if(fname MATCHES "\\.lib$") - string(REGEX REPLACE "\\.lib$" ".pdb" fname "${fname}") - install(FILES "${fname}" DESTINATION "${__dst}" CONFIGURATIONS Release OPTIONAL) +# message(STATUS "Adding PDB file installation rule: target=${__target} dst=${__dst} component=${__pdb_install_component}") + if("${__target_type}" STREQUAL "SHARED_LIBRARY") + install(FILES "$" DESTINATION "${__dst}" COMPONENT ${__pdb_install_component} OPTIONAL) + else() + # There is no generator expression similar to TARGET_PDB_FILE and TARGET_PDB_FILE can't be used: https://gitlab.kitware.com/cmake/cmake/issues/16932 + # However we still want .pdb files like: 'lib/Debug/opencv_core341d.pdb' or '3rdparty/lib/zlibd.pdb' + install(FILES "$/$/$>,$,$>.pdb" + DESTINATION "${__dst}" CONFIGURATIONS Debug COMPONENT ${__pdb_install_component} OPTIONAL) + install(FILES "$/$/$>,$,$>.pdb" + DESTINATION "${__dst}" CONFIGURATIONS Release COMPONENT ${__pdb_install_component} OPTIONAL) endif() else() - # CMake 2.8.12 broke PDB support for STATIC libraries from MSVS, fix was introduced in CMake 3.1.0. - message(WARNING "PDB's are not supported from this version of CMake, use CMake version later then 3.1.0 or before 2.8.12.") + message(WARNING "PDB files installation is not supported (need CMake >= 3.1.0)") endif() endif() endif()