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