1# Copyright (c) 2020-2023 Intel Corporation 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15if (DEFINED CMAKE_SKIP_BUILD_RPATH) 16 set(CMAKE_SKIP_BUILD_RPATH_OLD_VALUE ${CMAKE_SKIP_BUILD_RPATH}) 17endif() 18set(CMAKE_SKIP_BUILD_RPATH TRUE) 19 20function(tbbbind_build TBBBIND_NAME REQUIRED_HWLOC_TARGET) 21 if (NOT TARGET ${REQUIRED_HWLOC_TARGET}) 22 message(STATUS "HWLOC target ${REQUIRED_HWLOC_TARGET} doesn't exist." 23 " The ${TBBBIND_NAME} target cannot be created") 24 return() 25 endif() 26 add_library(${TBBBIND_NAME} tbb_bind.cpp) 27 28 if (WIN32) 29 target_sources(${TBBBIND_NAME} PRIVATE tbb_bind.rc) 30 endif() 31 32 add_library(TBB::${TBBBIND_NAME} ALIAS ${TBBBIND_NAME}) 33 34 target_compile_definitions(${TBBBIND_NAME} 35 PUBLIC 36 $<$<CONFIG:DEBUG>:TBB_USE_DEBUG> 37 PRIVATE 38 __TBBBIND_BUILD) 39 target_include_directories(${TBBBIND_NAME} 40 PUBLIC 41 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../include> 42 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> 43 ${HWLOC_INCLUDE_DIRS} # pkg-config defined 44 ) 45 46 target_compile_options(${TBBBIND_NAME} 47 PRIVATE 48 ${TBB_CXX_STD_FLAG} # TODO: consider making it PUBLIC. 49 ${TBB_MMD_FLAG} 50 ${TBB_DSE_FLAG} 51 ${TBB_WARNING_LEVEL} 52 ${TBB_LIB_COMPILE_FLAGS} 53 ${TBB_COMMON_COMPILE_FLAGS} 54 ) 55 56 # Avoid use of target_link_libraries here as it changes /DEF option to \DEF on Windows. 57 set_target_properties(${TBBBIND_NAME} PROPERTIES 58 DEFINE_SYMBOL "" 59 VERSION ${TBBBIND_BINARY_VERSION}.${TBB_BINARY_MINOR_VERSION} 60 SOVERSION ${TBBBIND_BINARY_VERSION} 61 ) 62 63 tbb_handle_ipo(${TBBBIND_NAME}) 64 65 if (TBB_DEF_FILE_PREFIX) # If there's no prefix, assume we're using export directives 66 set_target_properties(${TBBBIND_NAME} PROPERTIES 67 LINK_FLAGS "${TBB_LINK_DEF_FILE_FLAG}\"${CMAKE_CURRENT_SOURCE_DIR}/def/${TBB_DEF_FILE_PREFIX}-tbbbind.def\"" 68 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/def/${TBB_DEF_FILE_PREFIX}-tbbbind.def" 69 ) 70 endif() 71 72 # Prefer using target_link_options instead of target_link_libraries to specify link options because 73 # target_link_libraries may incorrectly handle some options (on Windows, for example). 74 if (COMMAND target_link_options) 75 target_link_options(${TBBBIND_NAME} 76 PRIVATE 77 ${TBB_LIB_LINK_FLAGS} 78 ${TBB_COMMON_LINK_FLAGS} 79 ) 80 else() 81 target_link_libraries(${TBBBIND_NAME} 82 PRIVATE 83 ${TBB_LIB_LINK_FLAGS} 84 ${TBB_COMMON_LINK_FLAGS} 85 ) 86 endif() 87 88 target_link_libraries(${TBBBIND_NAME} 89 PUBLIC 90 ${REQUIRED_HWLOC_TARGET} 91 PRIVATE 92 ${TBB_LIB_LINK_LIBS} 93 ${TBB_COMMON_LINK_LIBS} 94 ) 95 96 tbb_install_target(${TBBBIND_NAME}) 97 98endfunction() 99 100if (NOT DEFINED HWLOC_TARGET_EXPLICITLY_DEFINED AND TARGET PkgConfig::HWLOC) 101 message(STATUS "The ${TBBBIND_LIBRARY_NAME} target will be configured using the HWLOC ${HWLOC_VERSION}") 102 tbbbind_build(${TBBBIND_LIBRARY_NAME} PkgConfig::HWLOC) 103else() 104 tbbbind_build(tbbbind HWLOC::hwloc_1_11) 105 tbbbind_build(tbbbind_2_0 HWLOC::hwloc_2 ) 106 tbbbind_build(tbbbind_2_5 HWLOC::hwloc_2_5 ) 107endif() 108 109 110if (DEFINED CMAKE_SKIP_BUILD_RPATH_OLD_VALUE) 111 set(CMAKE_SKIP_BUILD_RPATH ${CMAKE_SKIP_BUILD_RPATH_OLD_VALUE}) 112 unset(CMAKE_SKIP_BUILD_RPATH_OLD_VALUE) 113else() 114 unset(CMAKE_SKIP_BUILD_RPATH) 115endif() 116