cmake: update PDB installation
authorAlexander Alekhin <alexander.alekhin@intel.com>
Mon, 9 Apr 2018 13:21:27 +0000 (16:21 +0300)
committerAlexander Alekhin <alexander.alekhin@intel.com>
Mon, 9 Apr 2018 15:50:58 +0000 (18:50 +0300)
3rdparty/protobuf/CMakeLists.txt
cmake/OpenCVUtils.cmake

index e506fe9..0ebbd11 100644 (file)
@@ -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}
     )
 
index a43d39d..19f05b8 100644 (file)
@@ -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 "$<TARGET_PDB_FILE:${__target}>" 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 "$<TARGET_PROPERTY:${__target},ARCHIVE_OUTPUT_DIRECTORY>/$<CONFIG>/$<IF:$<BOOL:$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_DEBUG>>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_DEBUG>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME>>.pdb"
+                DESTINATION "${__dst}" CONFIGURATIONS Debug COMPONENT ${__pdb_install_component} OPTIONAL)
+            install(FILES "$<TARGET_PROPERTY:${__target},ARCHIVE_OUTPUT_DIRECTORY>/$<CONFIG>/$<IF:$<BOOL:$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_RELEASE>>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME_RELEASE>,$<TARGET_PROPERTY:${__target},COMPILE_PDB_NAME>>.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()