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 15set(CMAKE_SKIP_BUILD_RPATH TRUE) 16 17function(tbbbind_build TBBBIND_NAME REQUIRED_HWLOC_TARGET) 18 if (NOT TARGET ${REQUIRED_HWLOC_TARGET}) 19 message(STATUS "HWLOC target ${REQUIRED_HWLOC_TARGET} doesn't exist." 20 " The ${TBBBIND_NAME} target cannot be created") 21 return() 22 endif() 23 add_library(${TBBBIND_NAME} tbb_bind.cpp) 24 25 if (WIN32) 26 target_sources(${TBBBIND_NAME} PRIVATE tbb_bind.rc) 27 endif() 28 29 add_library(TBB::${TBBBIND_NAME} ALIAS ${TBBBIND_NAME}) 30 31 target_compile_definitions(${TBBBIND_NAME} 32 PUBLIC 33 $<$<CONFIG:DEBUG>:TBB_USE_DEBUG> 34 PRIVATE 35 __TBBBIND_BUILD) 36 target_include_directories(${TBBBIND_NAME} 37 PUBLIC 38 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../include> 39 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}> 40 ${HWLOC_INCLUDE_DIRS} # pkg-config defined 41 ) 42 43 target_compile_options(${TBBBIND_NAME} 44 PRIVATE 45 ${TBB_CXX_STD_FLAG} # TODO: consider making it PUBLIC. 46 ${TBB_MMD_FLAG} 47 ${TBB_DSE_FLAG} 48 ${TBB_WARNING_LEVEL} 49 ${TBB_LIB_COMPILE_FLAGS} 50 ${TBB_COMMON_COMPILE_FLAGS} 51 ) 52 53 # Avoid use of target_link_libraries here as it changes /DEF option to \DEF on Windows. 54 set_target_properties(${TBBBIND_NAME} PROPERTIES 55 DEFINE_SYMBOL "" 56 VERSION ${TBBBIND_BINARY_VERSION}.${TBB_BINARY_MINOR_VERSION} 57 SOVERSION ${TBBBIND_BINARY_VERSION} 58 ) 59 60 tbb_handle_ipo(${TBBBIND_NAME}) 61 62 if (TBB_DEF_FILE_PREFIX) # If there's no prefix, assume we're using export directives 63 set_target_properties(${TBBBIND_NAME} PROPERTIES 64 LINK_FLAGS "${TBB_LINK_DEF_FILE_FLAG}\"${CMAKE_CURRENT_SOURCE_DIR}/def/${TBB_DEF_FILE_PREFIX}-tbbbind.def\"" 65 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/def/${TBB_DEF_FILE_PREFIX}-tbbbind.def" 66 ) 67 endif() 68 69 # Prefer using target_link_options instead of target_link_libraries to specify link options because 70 # target_link_libraries may incorrectly handle some options (on Windows, for example). 71 if (COMMAND target_link_options) 72 target_link_options(${TBBBIND_NAME} 73 PRIVATE 74 ${TBB_LIB_LINK_FLAGS} 75 ${TBB_COMMON_LINK_FLAGS} 76 ) 77 else() 78 target_link_libraries(${TBBBIND_NAME} 79 PRIVATE 80 ${TBB_LIB_LINK_FLAGS} 81 ${TBB_COMMON_LINK_FLAGS} 82 ) 83 endif() 84 85 target_link_libraries(${TBBBIND_NAME} 86 PUBLIC 87 ${REQUIRED_HWLOC_TARGET} 88 PRIVATE 89 ${TBB_LIB_LINK_LIBS} 90 ${TBB_COMMON_LINK_LIBS} 91 ) 92 93 tbb_install_target(${TBBBIND_NAME}) 94 95endfunction() 96 97if (NOT DEFINED HWLOC_TARGET_EXPLICITLY_DEFINED AND TARGET PkgConfig::HWLOC) 98 message(STATUS "The ${TBBBIND_LIBRARY_NAME} target will be configured using the HWLOC ${HWLOC_VERSION}") 99 tbbbind_build(${TBBBIND_LIBRARY_NAME} PkgConfig::HWLOC) 100else() 101 tbbbind_build(tbbbind HWLOC::hwloc_1_11) 102 tbbbind_build(tbbbind_2_0 HWLOC::hwloc_2 ) 103 tbbbind_build(tbbbind_2_5 HWLOC::hwloc_2_5 ) 104endif() 105 106