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 15add_library(tbb 16 address_waiter.cpp 17 allocator.cpp 18 arena.cpp 19 arena_slot.cpp 20 concurrent_bounded_queue.cpp 21 dynamic_link.cpp 22 exception.cpp 23 governor.cpp 24 global_control.cpp 25 itt_notify.cpp 26 main.cpp 27 market.cpp 28 tcm_adaptor.cpp 29 misc.cpp 30 misc_ex.cpp 31 observer_proxy.cpp 32 parallel_pipeline.cpp 33 private_server.cpp 34 profiling.cpp 35 rml_tbb.cpp 36 rtm_mutex.cpp 37 rtm_rw_mutex.cpp 38 semaphore.cpp 39 small_object_pool.cpp 40 task.cpp 41 task_dispatcher.cpp 42 task_group_context.cpp 43 thread_dispatcher.cpp 44 thread_request_serializer.cpp 45 threading_control.cpp 46 version.cpp 47 queuing_rw_mutex.cpp) 48 49add_library(TBB::tbb ALIAS tbb) 50 51if (WIN32) 52 target_sources(tbb PRIVATE tbb.rc) 53 set_target_properties(tbb PROPERTIES OUTPUT_NAME "tbb${TBB_BINARY_VERSION}") 54endif() 55 56# TODO: Add statistics.cpp 57 58target_compile_definitions(tbb 59 PUBLIC 60 $<$<CONFIG:DEBUG>:TBB_USE_DEBUG> 61 PRIVATE 62 __TBB_BUILD 63 ${TBB_RESUMABLE_TASKS_USE_THREADS} 64 $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:__TBB_DYNAMIC_LOAD_ENABLED=0> 65 $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:__TBB_SOURCE_DIRECTLY_INCLUDED=1>) 66 67if (NOT ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(armv7-a|aarch64|mips|arm64|riscv)" OR 68 "${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm64" OR 69 WINDOWS_STORE OR 70 TBB_WINDOWS_DRIVER)) 71 target_compile_definitions(tbb PRIVATE __TBB_USE_ITT_NOTIFY) 72endif() 73 74target_include_directories(tbb 75 PUBLIC 76 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../include> 77 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) 78 79target_compile_options(tbb 80 PRIVATE 81 ${TBB_CXX_STD_FLAG} # TODO: consider making it PUBLIC. 82 ${TBB_MMD_FLAG} 83 ${TBB_DSE_FLAG} 84 ${TBB_WARNING_LEVEL} 85 ${TBB_WARNING_SUPPRESS} 86 ${TBB_LIB_COMPILE_FLAGS} 87 ${TBB_COMMON_COMPILE_FLAGS} 88) 89 90# Avoid use of target_link_libraries here as it changes /DEF option to \DEF on Windows. 91set_target_properties(tbb PROPERTIES 92 DEFINE_SYMBOL "" 93 VERSION ${TBB_BINARY_VERSION}.${TBB_BINARY_MINOR_VERSION} 94 SOVERSION ${TBB_BINARY_VERSION} 95) 96 97tbb_handle_ipo(tbb) 98 99if (TBB_DEF_FILE_PREFIX) # If there's no prefix, assume we're using export directives 100 set_target_properties(tbb PROPERTIES 101 LINK_FLAGS "${TBB_LINK_DEF_FILE_FLAG}\"${CMAKE_CURRENT_SOURCE_DIR}/def/${TBB_DEF_FILE_PREFIX}-tbb.def\"" 102 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/def/${TBB_DEF_FILE_PREFIX}-tbb.def" 103 ) 104endif() 105 106# Prefer using target_link_options instead of target_link_libraries to specify link options because 107# target_link_libraries may incorrectly handle some options (on Windows, for example). 108if (COMMAND target_link_options) 109 target_link_options(tbb 110 PRIVATE 111 ${TBB_LIB_LINK_FLAGS} 112 ${TBB_COMMON_LINK_FLAGS} 113 ) 114else() 115 target_link_libraries(tbb 116 PRIVATE 117 ${TBB_LIB_LINK_FLAGS} 118 ${TBB_COMMON_LINK_FLAGS} 119 ) 120endif() 121 122target_link_libraries(tbb 123 PRIVATE 124 Threads::Threads 125 ${TBB_LIB_LINK_LIBS} 126 ${TBB_COMMON_LINK_LIBS} 127) 128 129tbb_install_target(tbb) 130 131if (TBB_INSTALL) 132 if (MSVC) 133 # Create a copy of target linker file (tbb<ver>[_debug].lib) with legacy name (tbb[_debug].lib) 134 # to support previous user experience for linkage. 135 install(FILES 136 $<TARGET_LINKER_FILE:tbb> 137 DESTINATION lib 138 CONFIGURATIONS RelWithDebInfo Release MinSizeRel 139 RENAME tbb.lib 140 COMPONENT devel 141 ) 142 143 install(FILES 144 $<TARGET_LINKER_FILE:tbb> 145 DESTINATION lib 146 CONFIGURATIONS Debug 147 RENAME tbb_debug.lib 148 COMPONENT devel 149 ) 150 endif() 151 152 set(_tbb_pc_lib_name tbb) 153 154 if (WIN32) 155 set(_tbb_pc_lib_name ${_tbb_pc_lib_name}${TBB_BINARY_VERSION}) 156 endif() 157 158 if (CMAKE_SIZEOF_VOID_P EQUAL 8) 159 set(TBB_PC_NAME tbb) 160 else() 161 set(TBB_PC_NAME tbb32) 162 endif() 163 164 set(_prefix_for_pc_file "${CMAKE_INSTALL_PREFIX}") 165 166 if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}") 167 set(_libdir_for_pc_file "${CMAKE_INSTALL_LIBDIR}") 168 else() 169 set(_libdir_for_pc_file "\${prefix}/${CMAKE_INSTALL_LIBDIR}") 170 endif() 171 172 if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}") 173 set(_includedir_for_pc_file "${CMAKE_INSTALL_INCLUDEDIR}") 174 else() 175 set(_includedir_for_pc_file "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}") 176 endif() 177 178 configure_file(${PROJECT_SOURCE_DIR}/integration/pkg-config/tbb.pc.in ${CMAKE_CURRENT_BINARY_DIR}/${TBB_PC_NAME}.pc @ONLY) 179 install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${TBB_PC_NAME}.pc 180 DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig/ 181 COMPONENT devel) 182endif() 183 184if (COMMAND tbb_gen_vars) 185 tbb_gen_vars(tbb) 186endif() 187