diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index e0c740caf9..3ae6162ba6 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -999,6 +999,15 @@ function(ocv_convert_to_lib_name var) set(${var} ${tmp} PARENT_SCOPE) endfunction() +if(MSVC AND BUILD_SHARED_LIBS) # no defaults for static libs (modern CMake is required) + if(NOT CMAKE_VERSION VERSION_LESS 3.6.0) + option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default" ON) + option(INSTALL_PDB "Add install PDB rules" ON) + elseif(NOT CMAKE_VERSION VERSION_LESS 3.1.0) + option(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL "Don't install PDB files by default (not supported)" OFF) + option(INSTALL_PDB "Add install PDB rules" OFF) + endif() +endif() # add install command function(ocv_install_target) @@ -1030,9 +1039,10 @@ function(ocv_install_target) endif() if(MSVC) - if(INSTALL_PDB AND (NOT INSTALL_IGNORE_PDB)) - set(__target "${ARGV0}") - + set(__target "${ARGV0}") + if(INSTALL_PDB AND NOT INSTALL_IGNORE_PDB + AND NOT OPENCV_${__target}_PDB_SKIP + ) set(__location_key "ARCHIVE") # static libs get_target_property(__target_type ${__target} TYPE) if("${__target_type}" STREQUAL "SHARED_LIBRARY") @@ -1064,16 +1074,28 @@ function(ocv_install_target) if(DEFINED INSTALL_PDB_COMPONENT AND INSTALL_PDB_COMPONENT) set(__pdb_install_component "${INSTALL_PDB_COMPONENT}") endif() + set(__pdb_exclude_from_all "") + if(INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL) + if(NOT CMAKE_VERSION VERSION_LESS 3.6.0) + set(__pdb_exclude_from_all EXCLUDE_FROM_ALL) + else() + message(WARNING "INSTALL_PDB_COMPONENT_EXCLUDE_FROM_ALL requires CMake 3.6+") + endif() + endif() + # 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) + install(FILES "$" DESTINATION "${__dst}" + COMPONENT ${__pdb_install_component} OPTIONAL ${__pdb_exclude_from_all}) 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) + DESTINATION "${__dst}" CONFIGURATIONS Debug + COMPONENT ${__pdb_install_component} OPTIONAL ${__pdb_exclude_from_all}) install(FILES "$/$/$>,$,$>.pdb" - DESTINATION "${__dst}" CONFIGURATIONS Release COMPONENT ${__pdb_install_component} OPTIONAL) + DESTINATION "${__dst}" CONFIGURATIONS Release + COMPONENT ${__pdb_install_component} OPTIONAL ${__pdb_exclude_from_all}) endif() else() message(WARNING "PDB files installation is not supported (need CMake >= 3.1.0)")