From f3eff00bf7615e31e36b4dbf82db86af3711f842 Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Tue, 25 Apr 2017 16:48:50 +0300 Subject: [PATCH] cmake: update handling of IPPICV/IPPIW --- cmake/OpenCVFindIPPIW.cmake | 19 ++++++++- cmake/OpenCVGenConfig.cmake | 16 +++++++- cmake/OpenCVUtils.cmake | 44 +++++++++++++++------ cmake/templates/OpenCVConfig-IPPIW.cmake.in | 7 ++++ cmake/templates/OpenCVConfig.cmake.in | 1 + 5 files changed, 70 insertions(+), 17 deletions(-) create mode 100644 cmake/templates/OpenCVConfig-IPPIW.cmake.in diff --git a/cmake/OpenCVFindIPPIW.cmake b/cmake/OpenCVFindIPPIW.cmake index e74c2fb324..c7927f58e2 100644 --- a/cmake/OpenCVFindIPPIW.cmake +++ b/cmake/OpenCVFindIPPIW.cmake @@ -68,6 +68,7 @@ macro(ippiw_setup PATH BUILD) set(IPP_IW_LIBRARIES ${IPP_IW_LIBRARY}) execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OpenCV_SOURCE_DIR}/3rdparty/ippicv/CMakeLists.txt" "${IPP_IW_PATH}/") add_subdirectory("${IPP_IW_PATH}/" ${OpenCV_BINARY_DIR}/3rdparty/ippiw) + set(HAVE_IPP_IW 1) return() endif() @@ -84,8 +85,22 @@ macro(ippiw_setup PATH BUILD) message(STATUS "found Intel IPP IW binaries: ${IW_VERSION_MAJOR}.${IW_VERSION_MINOR}.${IW_VERSION_UPDATE}") message(STATUS "at: ${IPP_IW_PATH}") + add_library(ippiw STATIC IMPORTED) + set_target_properties(ippiw PROPERTIES + IMPORTED_LINK_INTERFACE_LIBRARIES "" + IMPORTED_LOCATION "${FILE}" + ) + if (NOT BUILD_SHARED_LIBS) + # CMake doesn't support "install(TARGETS ${name} ...)" command with imported targets + install(FILES "${FILE}" + DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT dev) + set(IPPIW_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_3P_LIB_INSTALL_PATH}/${CMAKE_STATIC_LIBRARY_PREFIX}ipp_iw${CMAKE_STATIC_LIBRARY_SUFFIX}" CACHE INTERNAL "" FORCE) + set(IPPIW_LOCATION_PATH "${FILE}" CACHE INTERNAL "" FORCE) + endif() + set(IPP_IW_INCLUDES "${IPP_IW_PATH}/include") - set(IPP_IW_LIBRARIES ${FILE}) + set(IPP_IW_LIBRARIES ippiw) + set(HAVE_IPP_IW 1) set(BUILD_IPP_IW 0) return() @@ -104,7 +119,7 @@ elseif((UNIX AND NOT ANDROID) OR (UNIX AND ANDROID_ABI MATCHES "x86")) elseif(WIN32 AND NOT ARM) set(IW_PACKAGE_SUBDIR "ippiw_win") else() - message(SEND_ERROR "Improper system for Intel IPP Integrations Wrappers. This message shouldn't appera. Check Intel IPP configurations steps") + message(SEND_ERROR "Improper system for Intel IPP Integrations Wrappers. This message shouldn't appear. Check Intel IPP configurations steps") return() endif() diff --git a/cmake/OpenCVGenConfig.cmake b/cmake/OpenCVGenConfig.cmake index 206acfdad9..fb62638b4b 100644 --- a/cmake/OpenCVGenConfig.cmake +++ b/cmake/OpenCVGenConfig.cmake @@ -45,12 +45,20 @@ export(TARGETS ${OpenCVModules_TARGETS} FILE "${CMAKE_BINARY_DIR}/OpenCVModules. if(TARGET ippicv AND NOT BUILD_SHARED_LIBS) set(USE_IPPICV TRUE) - file(RELATIVE_PATH IPPICV_INSTALL_PATH_RELATIVE_CONFIGCMAKE ${CMAKE_BINARY_DIR} ${IPPICV_LOCATION_PATH}) + file(RELATIVE_PATH IPPICV_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_BINARY_DIR}" "${IPPICV_LOCATION_PATH}") ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-IPPICV.cmake.in" IPPICV_CONFIGCMAKE @ONLY) else() set(USE_IPPICV FALSE) endif() +if(TARGET ippiw AND NOT BUILD_SHARED_LIBS AND IPPIW_INSTALL_PATH) + set(USE_IPPIW TRUE) + file(RELATIVE_PATH IPPIW_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_BINARY_DIR}" "${IPPIW_LOCATION_PATH}") + ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-IPPIW.cmake.in" IPPIW_CONFIGCMAKE @ONLY) +else() + set(USE_IPPIW FALSE) +endif() + configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig.cmake" @ONLY) #support for version checking when finding opencv. find_package(OpenCV 2.3.1 EXACT) should now work. configure_file("${OpenCV_SOURCE_DIR}/cmake/templates/OpenCVConfig-version.cmake.in" "${CMAKE_BINARY_DIR}/OpenCVConfig-version.cmake" @ONLY) @@ -62,9 +70,13 @@ file(RELATIVE_PATH OpenCV_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_INSTALL_PRE set(OpenCV_INCLUDE_DIRS_CONFIGCMAKE "\"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_INSTALL_PATH}\" \"\${OpenCV_INSTALL_PATH}/${OPENCV_INCLUDE_INSTALL_PATH}/opencv\"") if(USE_IPPICV) - file(RELATIVE_PATH IPPICV_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_INSTALL_PREFIX}" ${IPPICV_INSTALL_PATH}) + file(RELATIVE_PATH IPPICV_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_INSTALL_PREFIX}" "${IPPICV_INSTALL_PATH}") ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-IPPICV.cmake.in" IPPICV_CONFIGCMAKE @ONLY) endif() +if(USE_IPPIW) + file(RELATIVE_PATH IPPIW_INSTALL_PATH_RELATIVE_CONFIGCMAKE "${CMAKE_INSTALL_PREFIX}" "${IPPIW_INSTALL_PATH}") + ocv_cmake_configure("${CMAKE_CURRENT_LIST_DIR}/templates/OpenCVConfig-IPPIW.cmake.in" IPPIW_CONFIGCMAKE @ONLY) +endif() function(ocv_gen_config TMP_DIR NESTED_PATH ROOT_NAME) ocv_path_join(__install_nested "${OPENCV_CONFIG_INSTALL_PATH}" "${NESTED_PATH}") diff --git a/cmake/OpenCVUtils.cmake b/cmake/OpenCVUtils.cmake index ccb87311f5..4879eb699c 100644 --- a/cmake/OpenCVUtils.cmake +++ b/cmake/OpenCVUtils.cmake @@ -1003,6 +1003,13 @@ function(ocv_add_library target) _ocv_append_target_includes(${target}) endfunction() + +macro(ocv_get_libname var_name) + get_filename_component(__libname "${ARGN}" NAME) + string(REGEX REPLACE "^lib(.+).(a|so)(.[.0-9]+)?$" "\\1" __libname "${__libname}") + set(${var_name} "${__libname}") +endmacro() + # build the list of opencv libs and dependencies for all modules # _modules - variable to hold list of all modules # _extra - variable to hold list of extra dependencies @@ -1030,11 +1037,31 @@ macro(ocv_get_all_libs _modules _extra _3rdparty) foreach (dep ${deps} ${OPENCV_LINKER_LIBS}) if (NOT DEFINED OPENCV_MODULE_${dep}_LOCATION) if (TARGET ${dep}) - get_target_property(_output ${dep} ARCHIVE_OUTPUT_DIRECTORY) - if ("${_output}" STREQUAL "${3P_LIBRARY_OUTPUT_PATH}") - list(INSERT ${_3rdparty} 0 ${dep}) + get_target_property(_type ${dep} TYPE) + if(_type STREQUAL "STATIC_LIBRARY" AND BUILD_SHARED_LIBS) + # nothing else() - list(INSERT ${_extra} 0 ${dep}) + get_target_property(_output ${dep} IMPORTED_LOCATION) + if(NOT _output) + get_target_property(_output ${dep} ARCHIVE_OUTPUT_DIRECTORY) + get_target_property(_output_name ${dep} OUTPUT_NAME) + if(NOT _output_name) + set(_output_name "${dep}") + endif() + else() + get_filename_component(_output_name "${_output}" NAME) + endif() + string(FIND "${_output}" "${CMAKE_BINARY_DIR}" _POS) + if (_POS EQUAL 0) + ocv_get_libname(_libname "${_output_name}") + list(INSERT ${_3rdparty} 0 ${_libname}) + else() + if(_output) + list(INSERT ${_extra} 0 ${_output}) + else() + list(INSERT ${_extra} 0 ${dep}) + endif() + endif() endif() else() list(INSERT ${_extra} 0 ${dep}) @@ -1043,15 +1070,6 @@ macro(ocv_get_all_libs _modules _extra _3rdparty) endforeach() endforeach() - # ippicv specific handling - list(FIND ${_extra} "ippicv" ippicv_idx) - if (${ippicv_idx} GREATER -1) - list(REMOVE_ITEM ${_extra} "ippicv") - if(NOT BUILD_SHARED_LIBS) - list(INSERT ${_3rdparty} 0 "ippicv") - endif() - endif() - ocv_list_filterout(${_modules} "^[\$]<") ocv_list_filterout(${_3rdparty} "^[\$]<") ocv_list_filterout(${_extra} "^[\$]<") diff --git a/cmake/templates/OpenCVConfig-IPPIW.cmake.in b/cmake/templates/OpenCVConfig-IPPIW.cmake.in new file mode 100644 index 0000000000..36cfed060b --- /dev/null +++ b/cmake/templates/OpenCVConfig-IPPIW.cmake.in @@ -0,0 +1,7 @@ +if(NOT TARGET ippiw) + add_library(ippiw STATIC IMPORTED) + set_target_properties(ippiw PROPERTIES + IMPORTED_LINK_INTERFACE_LIBRARIES "" + IMPORTED_LOCATION "${OpenCV_INSTALL_PATH}/@IPPIW_INSTALL_PATH_RELATIVE_CONFIGCMAKE@" + ) +endif() diff --git a/cmake/templates/OpenCVConfig.cmake.in b/cmake/templates/OpenCVConfig.cmake.in index 47751f55cf..c0a58389ff 100644 --- a/cmake/templates/OpenCVConfig.cmake.in +++ b/cmake/templates/OpenCVConfig.cmake.in @@ -97,6 +97,7 @@ endif() @ANDROID_CONFIGCMAKE@ @IPPICV_CONFIGCMAKE@ +@IPPIW_CONFIGCMAKE@ # Some additional settings are required if OpenCV is built as static libs set(OpenCV_SHARED @BUILD_SHARED_LIBS@)