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