From bb873b1de5094dbc177e6687451d2ffa36d6c307 Mon Sep 17 00:00:00 2001 From: Boaz Stolk Date: Fri, 12 Dec 2014 14:21:47 +0100 Subject: [PATCH] add option to link to dynamic IPP libraries --- CMakeLists.txt | 4 +++ cmake/OpenCVFindIPP.cmake | 52 +++++++++++++++++++++++++++------------ 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index efe56c1693..cda38164da 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,6 +181,7 @@ OCV_OPTION(BUILD_PERF_TESTS "Build performance tests" OCV_OPTION(BUILD_TESTS "Build accuracy & regression tests" ON IF (NOT IOS) ) OCV_OPTION(BUILD_WITH_DEBUG_INFO "Include debug info into debug libs (not MSCV only)" ON ) OCV_OPTION(BUILD_WITH_STATIC_CRT "Enables use of staticaly linked CRT for staticaly linked OpenCV" ON IF MSVC ) +OCV_OPTION(BUILD_WITH_DYNAMIC_IPP "Enables dynamic linking of IPP (only for standalone IPP)" OFF ) OCV_OPTION(BUILD_FAT_JAVA_LIB "Create fat java wrapper containing the whole OpenCV library" ON IF NOT BUILD_SHARED_LIBS AND CMAKE_COMPILER_IS_GNUCXX ) OCV_OPTION(BUILD_ANDROID_SERVICE "Build OpenCV Manager for Google Play" OFF IF ANDROID AND ANDROID_SOURCE_TREE ) OCV_OPTION(BUILD_ANDROID_PACKAGE "Build platform-specific package for Google Play" OFF IF ANDROID ) @@ -960,6 +961,9 @@ status(" Other third-party libraries:") if(WITH_IPP AND HAVE_IPP) status(" Use IPP:" "${IPP_VERSION_STR} [${IPP_VERSION_MAJOR}.${IPP_VERSION_MINOR}.${IPP_VERSION_BUILD}]") status(" at:" "${IPP_ROOT_DIR}") + if(NOT HAVE_IPP_ICV_ONLY) + status(" linked:" BUILD_WITH_DYNAMIC_IPP THEN "dynamic" ELSE "static") + endif() else() status(" Use IPP:" WITH_IPP AND NOT HAVE_IPP THEN "IPP not found" ELSE NO) endif() diff --git a/cmake/OpenCVFindIPP.cmake b/cmake/OpenCVFindIPP.cmake index 036f598639..cf50cf1437 100644 --- a/cmake/OpenCVFindIPP.cmake +++ b/cmake/OpenCVFindIPP.cmake @@ -34,9 +34,6 @@ unset(IPP_VERSION_MAJOR) unset(IPP_VERSION_MINOR) unset(IPP_VERSION_BUILD) -set(IPP_LIB_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX}) -set(IPP_LIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX}) - set(IPP_X64 0) if(CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8) set(IPP_X64 1) @@ -125,19 +122,34 @@ macro(ipp_detect_version) endif() macro(_ipp_add_library name) + # dynamic linking is only supported for standalone version of IPP + if (BUILD_WITH_DYNAMIC_IPP AND NOT HAVE_IPP_ICV_ONLY) + set(IPP_LIB_PREFIX ${CMAKE_SHARED_LIBRARY_PREFIX}) + set(IPP_LIB_SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX}) + else () + set(IPP_LIB_PREFIX ${CMAKE_STATIC_LIBRARY_PREFIX}) + set(IPP_LIB_SUFFIX ${CMAKE_STATIC_LIBRARY_SUFFIX}) + endif () if (EXISTS ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}) - add_library(ipp${name} STATIC IMPORTED) - set_target_properties(ipp${name} PROPERTIES + if (BUILD_WITH_DYNAMIC_IPP AND NOT HAVE_IPP_ICV_ONLY) + add_library(${IPP_PREFIX}${name} STATIC IMPORTED) + else () + add_library(${IPP_PREFIX}${name} SHARED IMPORTED) + endif () + set_target_properties(${IPP_PREFIX}${name} PROPERTIES IMPORTED_LINK_INTERFACE_LIBRARIES "" IMPORTED_LOCATION ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX} ) - list(APPEND IPP_LIBRARIES ipp${name}) - # CMake doesn't support "install(TARGETS ipp${name} " command with imported targets - install(FILES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX} - DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) - string(TOUPPER ${name} uname) - set(IPP${uname}_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_3P_LIB_INSTALL_PATH}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}" CACHE INTERNAL "" FORCE) - set(IPP${uname}_LOCATION_PATH "${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}" CACHE INTERNAL "" FORCE) + list(APPEND IPP_LIBRARIES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}) + # CMake doesn't support "install(TARGETS ${IPP_PREFIX}${name} " command with imported targets + # When using dynamic libraries from standalone IPP it is your responsibility to install those on the target system + if (NOT BUILD_WITH_DYNAMIC_IPP) + install(FILES ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX} + DESTINATION ${OPENCV_3P_LIB_INSTALL_PATH} COMPONENT main) + string(TOUPPER ${name} uname) + set(IPP${uname}_INSTALL_PATH "${CMAKE_INSTALL_PREFIX}/${OPENCV_3P_LIB_INSTALL_PATH}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}" CACHE INTERNAL "" FORCE) + set(IPP${uname}_LOCATION_PATH "${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}" CACHE INTERNAL "" FORCE) + endif () else() message(STATUS "Can't find IPP library: ${name} at ${IPP_LIBRARY_DIR}/${IPP_LIB_PREFIX}${IPP_PREFIX}${name}${IPP_SUFFIX}${IPP_LIB_SUFFIX}") endif() @@ -145,10 +157,18 @@ macro(ipp_detect_version) set(IPP_PREFIX "ipp") if(${IPP_VERSION_STR} VERSION_LESS "8.0") - set(IPP_SUFFIX "_l") # static not threaded libs suffix IPP 7.x - else() + if (BUILD_WITH_DYNAMIC_IPP AND NOT HAVE_IPP_ICV_ONLY) + set(IPP_SUFFIX "") # dynamic not threaded libs suffix IPP 7.x + else () + set(IPP_SUFFIX "_l") # static not threaded libs suffix IPP 7.x + endif () + else () if(WIN32) - set(IPP_SUFFIX "mt") # static not threaded libs suffix IPP 8.x for Windows + if (BUILD_WITH_DYNAMIC_IPP AND NOT HAVE_IPP_ICV_ONLY) + set(IPP_SUFFIX "") # dynamic not threaded libs suffix IPP 8.x for Windows + else () + set(IPP_SUFFIX "mt") # static not threaded libs suffix IPP 8.x for Windows + endif () else() set(IPP_SUFFIX "") # static not threaded libs suffix IPP 8.x for Linux/OS X endif() @@ -191,7 +211,7 @@ macro(ipp_detect_version) if (EXISTS ${INTEL_COMPILER_LIBRARY_DIR}/${IPP_LIB_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}) list(APPEND IPP_LIBRARIES ${INTEL_COMPILER_LIBRARY_DIR}/${IPP_LIB_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}) else() - message(STATUS "Can't find compiler library: ${name}") + message(STATUS "Can't find compiler library: ${name} at ${INTEL_COMPILER_LIBRARY_DIR}/${IPP_LIB_PREFIX}${name}${CMAKE_SHARED_LIBRARY_SUFFIX}") endif() endmacro()