Advertisement
Guest User

Untitled

a guest
May 12th, 2021
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CMake 9.25 KB | None | 0 0
  1. #===============================================================================
  2. # Copyright 2019-2021 Intel Corporation
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. #     http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. #===============================================================================
  16.  
  17. #
  18. # Intel® Integrated Performance Primitives (Intel® IPP) library detection routine.
  19. #
  20. # To use it, add the lines below to your CMakeLists.txt:
  21. # ~~~
  22. #     find_package(IPP REQUIRED)
  23. #     target_link_libraries(mytarget ${IPP_LIBRARIES})
  24. # ~~~
  25. #
  26. # List of the variables defined in this file:
  27. #
  28. # * IPP_FOUND
  29. # * IPP_LIBRARIES - list of all imported targets
  30. #
  31. # Configuration variables available:
  32. #
  33. # * IPP_SHARED     - set this to TRUE before find_package() to search for shared library.
  34. # * IPP_ARCH       - set this to 'ia32' or 'intel64' before find_package() to use library of particular
  35. #                    architecture (this variable can be auto-defined)
  36. # * IPP_TL_VARIANT - set this to 'OpenMP' or 'TBB' to use the corresponding variant
  37. #                    of Intel® IPP Threading Layer (TL) libraries
  38. #                    ('OpenMP' variant is used by default if no IPP_TL_VARIANT variable is set)
  39. #
  40.  
  41. if ("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" LESS 3.11)
  42.     message(FATAL_ERROR "CMake >= 3.11 required")
  43. endif ()
  44.  
  45. include_guard()
  46.  
  47. include("${CMAKE_CURRENT_LIST_DIR}/ipp-path-layout.cmake")
  48.  
  49. get_filename_component(ipp_cmake_package_dir "${CMAKE_CURRENT_LIST_DIR}" REALPATH)
  50.  
  51. # Initialize to default values
  52. if (NOT IPP_LIBRARIES)
  53.     set(IPP_LIBRARIES "")
  54. endif ()
  55.  
  56. if (NOT DEFINED IPP_TL_VARIANT)
  57.     set(IPP_TL_VARIANT "OpenMP")
  58. endif ()
  59.  
  60. if (IPP_TL_VARIANT STREQUAL "OpenMP")
  61.     set(ipp_tl_suffix "omp")
  62. elseif (IPP_TL_VARIANT STREQUAL "TBB")
  63.     set(ipp_tl_suffix "tbb")
  64. else ()
  65.     message(FATAL_ERROR "Possible values of the variable IPP_TL_VARIANT are 'OpenMP' and 'TBB'.")
  66. endif ()
  67.  
  68. string(TOLOWER "${IPP_TL_VARIANT}" ipp_tl_directory)
  69.  
  70. if (NOT IPP_FIND_COMPONENTS)
  71.     set(IPP_FIND_COMPONENTS
  72.         ipp_iw
  73.         ippcore
  74.         ippcc
  75.         ippdc
  76.         ippch
  77.         ippcv
  78.         ippe
  79.         ippi
  80.         ipps
  81.         ippvm)
  82.     set(IPP_TL_FIND_COMPONENTS ippcore ippcc ippcv ippi)
  83.  
  84.     set(IPP_REQUIRED_COMPONENTS ${IPP_FIND_COMPONENTS})
  85.  
  86.     foreach (ipp_tl_find_component IN LISTS IPP_TL_FIND_COMPONENTS)
  87.         list(APPEND IPP_REQUIRED_COMPONENTS "${ipp_tl_find_component}_tl")
  88.     endforeach ()
  89.  
  90.     foreach (_component ${IPP_REQUIRED_COMPONENTS})
  91.         set(IPP_FIND_REQUIRED_${_component} 1)
  92.     endforeach ()
  93. endif ()
  94.  
  95. # Determine ARCH if not defined outside
  96. if (NOT DEFINED IPP_ARCH)
  97.     set(IPP_ARCH "ia32")
  98.     if (CMAKE_CXX_SIZEOF_DATA_PTR EQUAL 8)
  99.         set(IPP_ARCH "intel64")
  100.     endif ()
  101.     if (CMAKE_SIZEOF_VOID_P)
  102.         set(IPP_ARCH "intel64")
  103.     endif ()
  104. endif ()
  105.  
  106. function (add_imported_library_target _component PATH_TO_LIBRARY PATH_TO_IMPORT_LIB LINKAGE_TYPE)
  107.     if (EXISTS "${PATH_TO_LIBRARY}")
  108.         if (NOT TARGET IPP::${_component})
  109.             add_library(IPP::${_component} ${LINKAGE_TYPE} IMPORTED)
  110.             get_filename_component(_include_dir "${ipp_cmake_package_dir}/${IPP_INC_REL_PATH}"
  111.                                    REALPATH)
  112.             if (EXISTS "${_include_dir}")
  113.                 set_target_properties(
  114.                     IPP::${_component} PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${_include_dir}"
  115.                                                   IMPORTED_LOCATION "${PATH_TO_LIBRARY}")
  116.                 if (WIN32)
  117.                     set_target_properties(IPP::${_component} PROPERTIES IMPORTED_IMPLIB
  118.                                                                         "${PATH_TO_IMPORT_LIB}")
  119.                 endif ()
  120.             else ()
  121.                 message(
  122.                     WARNING
  123.                         "IPP: Include directory does not exist: '${_include_dir}'. Intel IPP installation might be broken."
  124.                 )
  125.             endif ()
  126.             unset(_include_dir)
  127.         endif ()
  128.         list(APPEND IPP_LIBRARIES IPP::${_component})
  129.         set(IPP_${_component}_FOUND 1)
  130.     elseif (IPP_FIND_REQUIRED AND IPP_FIND_REQUIRED_${_component})
  131.         message(STATUS "Missed required Intel IPP  component: ${_component}")
  132.         message(STATUS "  library not found:\n   ${PATH_TO_LIBRARY}")
  133.         if (${LINKAGE_TYPE} MATCHES "SHARED")
  134.             message(
  135.                 STATUS "You may try to search for static library by unsetting IPP_SHARED variable.")
  136.         endif ()
  137.         set(IPP_FOUND FALSE)
  138.     endif ()
  139. endfunction (add_imported_library_target)
  140.  
  141. function (add_components list_of_components tl_path tl_suffix)
  142.     if (WIN32)
  143.         set(_ipp_library_prefix "")
  144.         set(_ipp_static_library_suffix "mt${tl_suffix}.lib")
  145.         set(_ipp_shared_library_suffix "${tl_suffix}.dll")
  146.         set(_ipp_import_library_suffix "${tl_suffix}.lib")
  147.     else ()
  148.         set(_ipp_library_prefix "lib")
  149.         set(_ipp_static_library_suffix "${tl_suffix}.a")
  150.         if (APPLE)
  151.             set(_ipp_shared_library_suffix "${tl_suffix}.dylib")
  152.         else ()
  153.             set(_ipp_shared_library_suffix "${tl_suffix}.so")
  154.         endif ()
  155.         set(_ipp_import_library_suffix "${tl_suffix}")
  156.     endif ()
  157.     foreach (_component IN LISTS list_of_components)
  158.         set(full_component_name "${_component}")
  159.         if (tl_suffix)
  160.             string(APPEND full_component_name "_tl")
  161.         endif ()
  162.         set(IPP_${full_component_name}_FOUND 0)
  163.  
  164.         if (IPP_SHARED)
  165.             set(_ipp_library_suffix "${_ipp_shared_library_suffix}")
  166.             set(_linkage_type "SHARED")
  167.         else ()
  168.             set(_ipp_library_suffix "${_ipp_static_library_suffix}")
  169.             set(_linkage_type "STATIC")
  170.         endif ()
  171.         if (full_component_name STREQUAL "ipp_iw")
  172.             if (WIN32)
  173.                 set(_ipp_library_suffix ".lib")
  174.             else ()
  175.                 set(_ipp_library_suffix ".a")
  176.             endif ()
  177.             set(_linkage_type "STATIC")
  178.         endif ()
  179.  
  180.         if (WIN32 AND ${_linkage_type} MATCHES "SHARED")
  181.             get_filename_component(
  182.                 _lib
  183.                 "${ipp_cmake_package_dir}/${IPP_REDIST_REL_PATH}/${IPP_ARCH}/${tl_path}${_ipp_library_prefix}${_component}${_ipp_library_suffix}"
  184.                 REALPATH)
  185.             get_filename_component(
  186.                 _imp_lib
  187.                 "${ipp_cmake_package_dir}/${IPP_LIB_REL_PATH}/${IPP_ARCH}/${tl_path}${_ipp_library_prefix}${_component}${_ipp_import_library_suffix}"
  188.                 REALPATH)
  189.         else ()
  190.             get_filename_component(
  191.                 _lib
  192.                 "${ipp_cmake_package_dir}/${IPP_LIB_REL_PATH}/${IPP_ARCH}/${tl_path}${_ipp_library_prefix}${_component}${_ipp_library_suffix}"
  193.                 REALPATH)
  194.             set(_imp_lib "")
  195.         endif ()
  196.         add_imported_library_target("${full_component_name}" "${_lib}" "${_imp_lib}"
  197.                                     "${_linkage_type}")
  198.     endforeach ()
  199. endfunction ()
  200.  
  201. add_components("${IPP_FIND_COMPONENTS}" "" "")
  202. add_components("${IPP_TL_FIND_COMPONENTS}" "tl/${ipp_tl_directory}/" "_tl_${ipp_tl_suffix}")
  203.  
  204. function (add_ipp_iw_include_directory iw_include_directory language)
  205.     get_filename_component(
  206.         _include_dir "${ipp_cmake_package_dir}/${IPP_INC_REL_PATH}/${iw_include_directory}"
  207.         REALPATH)
  208.     if (EXISTS "${_include_dir}")
  209.         target_include_directories(IPP::ipp_iw
  210.                                    INTERFACE $<$<COMPILE_LANGUAGE:${language}>:${_include_dir}>)
  211.     else ()
  212.         message(
  213.             WARNING
  214.                 "IPP: Include directory does not exist: '${_include_dir}'. Intel IPP installation might be broken."
  215.         )
  216.     endif ()
  217. endfunction ()
  218.  
  219. add_ipp_iw_include_directory(iw C)
  220. add_ipp_iw_include_directory(iw++ CXX)
  221.  
  222. list(REMOVE_DUPLICATES IPP_LIBRARIES)
  223.  
  224. # Dependencies between Intel® IPP libraries
  225. target_link_libraries(IPP::ippvm INTERFACE IPP::ippcore)
  226.  
  227. target_link_libraries(IPP::ipps INTERFACE IPP::ippvm)
  228.  
  229. target_link_libraries(IPP::ippch INTERFACE IPP::ipps)
  230. target_link_libraries(IPP::ippdc INTERFACE IPP::ipps)
  231. target_link_libraries(IPP::ippi INTERFACE IPP::ipps)
  232.  
  233. target_link_libraries(IPP::ippcc INTERFACE IPP::ippi)
  234. target_link_libraries(IPP::ippcv INTERFACE IPP::ippi)
  235.  
  236. target_link_libraries(IPP::ippi_tl INTERFACE IPP::ippi IPP::ippcore_tl)
  237. target_link_libraries(IPP::ippcc_tl INTERFACE IPP::ippcc IPP::ippi_tl)
  238. target_link_libraries(IPP::ippcv_tl INTERFACE IPP::ippcv IPP::ippi_tl)
  239.  
  240. # 3rd party dependencies
  241. include(CMakeFindDependencyMacro)
  242.  
  243. if (NOT IPP_SHARED)
  244.     if (IPP_TL_VARIANT STREQUAL "TBB")
  245.         find_dependency(TBB)
  246.         if (TBB_FOUND)
  247.             target_link_libraries(IPP::ippcore_tl INTERFACE TBB::tbb)
  248.         endif ()
  249.     endif ()
  250. endif ()
  251.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement