Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #===============================================================================
- # Copyright 2019-2021 Intel Corporation
- #
- # Licensed under the Apache License, Version 2.0 (the "License");
- # you may not use this file except in compliance with the License.
- # You may obtain a copy of the License at
- #
- # http://www.apache.org/licenses/LICENSE-2.0
- #
- # Unless required by applicable law or agreed to in writing, software
- # distributed under the License is distributed on an "AS IS" BASIS,
- # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- # See the License for the specific language governing permissions and
- # limitations under the License.
- #===============================================================================
- #
- # Intel® Integrated Performance Primitives (Intel® IPP) library detection routine.
- #
- # To use it, add the lines below to your CMakeLists.txt:
- # ~~~
- # find_package(IPP REQUIRED)
- # target_link_libraries(mytarget ${IPP_LIBRARIES})
- # ~~~
- #
- # List of the variables defined in this file:
- #
- # * IPP_FOUND
- # * IPP_LIBRARIES - list of all imported targets
- #
- # Configuration variables available:
- #
- # * IPP_SHARED - set this to TRUE before find_package() to search for shared library.
- # * IPP_ARCH - set this to 'ia32' or 'intel64' before find_package() to use library of particular
- # architecture (this variable can be auto-defined)
- # * IPP_TL_VARIANT - set this to 'OpenMP' or 'TBB' to use the corresponding variant
- # of Intel® IPP Threading Layer (TL) libraries
- # ('OpenMP' variant is used by default if no IPP_TL_VARIANT variable is set)
- #
- if ("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 3.11)
- message(FATAL_ERROR "CMake >= 3.11 required")
- endif ()
- include_guard()
- include("${CMAKE_CURRENT_LIST_DIR}/ipp-path-layout.cmake")
- get_filename_component(ipp_cmake_package_dir "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
- # Initialize to default values
- if (NOT IPP_LIBRARIES)
- set(IPP_LIBRARIES "")
- endif ()
- if (NOT DEFINED IPP_TL_VARIANT)
- set(IPP_TL_VARIANT "OpenMP")
- endif ()
- if (IPP_TL_VARIANT STREQUAL "OpenMP")
- set(ipp_tl_suffix "omp")
- elseif (IPP_TL_VARIANT STREQUAL "TBB")
- set(ipp_tl_suffix "tbb")
- else ()
- message(FATAL_ERROR "Possible values of the variable IPP_TL_VARIANT are 'OpenMP' and 'TBB'.")
- endif ()
- string(TOLOWER "${IPP_TL_VARIANT}" ipp_tl_directory)
- if (NOT IPP_FIND_COMPONENTS)
- set(IPP_FIND_COMPONENTS
- ipp_iw
- ippcore
- ippcc
- ippdc
- ippch
- ippcv
- ippe
- ippi
- ipps
- ippvm)
- set(IPP_TL_FIND_COMPONENTS ippcore ippcc ippcv ippi)
- set(IPP_REQUIRED_COMPONENTS ${IPP_FIND_COMPONENTS})
- foreach (ipp_tl_find_component IN LISTS IPP_TL_FIND_COMPONENTS)
- list(APPEND IPP_REQUIRED_COMPONENTS "${ipp_tl_find_component}_tl")
- endforeach ()
- foreach (_component ${IPP_REQUIRED_COMPONENTS})
- set(IPP_FIND_REQUIRED_${_component} 1)
- endforeach ()
- endif ()
- # Determine ARCH if not defined outside
- if (NOT DEFINED IPP_ARCH)
- set(IPP_ARCH "ia32")
- if (CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
- set(IPP_ARCH "intel64")
- endif ()
- if (CMAKE_SIZEOF_VOID_P)
- set(IPP_ARCH "intel64")
- endif ()
- endif ()
- function (add_imported_library_target _component PATH_TO_LIBRARY PATH_TO_IMPORT_LIB LINKAGE_TYPE)
- if (EXISTS "${PATH_TO_LIBRARY}")
- if (NOT TARGET IPP::${_component})
- add_library(IPP::${_component} ${LINKAGE_TYPE} IMPORTED)
- get_filename_component(_include_dir "${ipp_cmake_package_dir}/${IPP_INC_REL_PATH}"
- REALPATH)
- if (EXISTS "${_include_dir}")
- set_target_properties(
- IPP::${_component} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_include_dir}"
- IMPORTED_LOCATION "${PATH_TO_LIBRARY}")
- if (WIN32)
- set_target_properties(IPP::${_component} PROPERTIES IMPORTED_IMPLIB
- "${PATH_TO_IMPORT_LIB}")
- endif ()
- else ()
- message(
- WARNING
- "IPP: Include directory does not exist: '${_include_dir}'. Intel IPP installation might be broken."
- )
- endif ()
- unset(_include_dir)
- endif ()
- list(APPEND IPP_LIBRARIES IPP::${_component})
- set(IPP_${_component}_FOUND 1)
- elseif (IPP_FIND_REQUIRED AND IPP_FIND_REQUIRED_${_component})
- message(STATUS "Missed required Intel IPP component: ${_component}")
- message(STATUS " library not found:\n ${PATH_TO_LIBRARY}")
- if (${LINKAGE_TYPE} MATCHES "SHARED")
- message(
- STATUS "You may try to search for static library by unsetting IPP_SHARED variable.")
- endif ()
- set(IPP_FOUND FALSE)
- endif ()
- endfunction (add_imported_library_target)
- function (add_components list_of_components tl_path tl_suffix)
- if (WIN32)
- set(_ipp_library_prefix "")
- set(_ipp_static_library_suffix "mt${tl_suffix}.lib")
- set(_ipp_shared_library_suffix "${tl_suffix}.dll")
- set(_ipp_import_library_suffix "${tl_suffix}.lib")
- else ()
- set(_ipp_library_prefix "lib")
- set(_ipp_static_library_suffix "${tl_suffix}.a")
- if (APPLE)
- set(_ipp_shared_library_suffix "${tl_suffix}.dylib")
- else ()
- set(_ipp_shared_library_suffix "${tl_suffix}.so")
- endif ()
- set(_ipp_import_library_suffix "${tl_suffix}")
- endif ()
- foreach (_component IN LISTS list_of_components)
- set(full_component_name "${_component}")
- if (tl_suffix)
- string(APPEND full_component_name "_tl")
- endif ()
- set(IPP_${full_component_name}_FOUND 0)
- if (IPP_SHARED)
- set(_ipp_library_suffix "${_ipp_shared_library_suffix}")
- set(_linkage_type "SHARED")
- else ()
- set(_ipp_library_suffix "${_ipp_static_library_suffix}")
- set(_linkage_type "STATIC")
- endif ()
- if (full_component_name STREQUAL "ipp_iw")
- if (WIN32)
- set(_ipp_library_suffix ".lib")
- else ()
- set(_ipp_library_suffix ".a")
- endif ()
- set(_linkage_type "STATIC")
- endif ()
- if (WIN32 AND ${_linkage_type} MATCHES "SHARED")
- get_filename_component(
- _lib
- "${ipp_cmake_package_dir}/${IPP_REDIST_REL_PATH}/${IPP_ARCH}/${tl_path}${_ipp_library_prefix}${_component}${_ipp_library_suffix}"
- REALPATH)
- get_filename_component(
- _imp_lib
- "${ipp_cmake_package_dir}/${IPP_LIB_REL_PATH}/${IPP_ARCH}/${tl_path}${_ipp_library_prefix}${_component}${_ipp_import_library_suffix}"
- REALPATH)
- else ()
- get_filename_component(
- _lib
- "${ipp_cmake_package_dir}/${IPP_LIB_REL_PATH}/${IPP_ARCH}/${tl_path}${_ipp_library_prefix}${_component}${_ipp_library_suffix}"
- REALPATH)
- set(_imp_lib "")
- endif ()
- add_imported_library_target("${full_component_name}" "${_lib}" "${_imp_lib}"
- "${_linkage_type}")
- endforeach ()
- endfunction ()
- add_components("${IPP_FIND_COMPONENTS}" "" "")
- add_components("${IPP_TL_FIND_COMPONENTS}" "tl/${ipp_tl_directory}/" "_tl_${ipp_tl_suffix}")
- function (add_ipp_iw_include_directory iw_include_directory language)
- get_filename_component(
- _include_dir "${ipp_cmake_package_dir}/${IPP_INC_REL_PATH}/${iw_include_directory}"
- REALPATH)
- if (EXISTS "${_include_dir}")
- target_include_directories(IPP::ipp_iw
- INTERFACE $<$<COMPILE_LANGUAGE:${language}>:${_include_dir}>)
- else ()
- message(
- WARNING
- "IPP: Include directory does not exist: '${_include_dir}'. Intel IPP installation might be broken."
- )
- endif ()
- endfunction ()
- add_ipp_iw_include_directory(iw C)
- add_ipp_iw_include_directory(iw++ CXX)
- list(REMOVE_DUPLICATES IPP_LIBRARIES)
- # Dependencies between Intel® IPP libraries
- target_link_libraries(IPP::ippvm INTERFACE IPP::ippcore)
- target_link_libraries(IPP::ipps INTERFACE IPP::ippvm)
- target_link_libraries(IPP::ippch INTERFACE IPP::ipps)
- target_link_libraries(IPP::ippdc INTERFACE IPP::ipps)
- target_link_libraries(IPP::ippi INTERFACE IPP::ipps)
- target_link_libraries(IPP::ippcc INTERFACE IPP::ippi)
- target_link_libraries(IPP::ippcv INTERFACE IPP::ippi)
- target_link_libraries(IPP::ippi_tl INTERFACE IPP::ippi IPP::ippcore_tl)
- target_link_libraries(IPP::ippcc_tl INTERFACE IPP::ippcc IPP::ippi_tl)
- target_link_libraries(IPP::ippcv_tl INTERFACE IPP::ippcv IPP::ippi_tl)
- # 3rd party dependencies
- include(CMakeFindDependencyMacro)
- if (NOT IPP_SHARED)
- if (IPP_TL_VARIANT STREQUAL "TBB")
- find_dependency(TBB)
- if (TBB_FOUND)
- target_link_libraries(IPP::ippcore_tl INTERFACE TBB::tbb)
- endif ()
- endif ()
- endif ()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement