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(tbbmalloc 16 backend.cpp 17 backref.cpp 18 frontend.cpp 19 large_objects.cpp 20 tbbmalloc.cpp 21 ../tbb/itt_notify.cpp) 22 23if (WIN32) 24 target_sources(tbbmalloc PRIVATE tbbmalloc.rc) 25endif() 26 27add_library(TBB::tbbmalloc ALIAS tbbmalloc) 28 29target_compile_definitions(tbbmalloc 30 PUBLIC 31 $<$<CONFIG:DEBUG>:TBB_USE_DEBUG> 32 PRIVATE 33 __TBBMALLOC_BUILD 34 $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:__TBB_DYNAMIC_LOAD_ENABLED=0> 35 $<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:__TBB_SOURCE_DIRECTLY_INCLUDED=1>) 36 37if (NOT ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "(armv7-a|aarch64|mips|arm64|riscv)" OR 38 "${CMAKE_OSX_ARCHITECTURES}" MATCHES "arm64" OR 39 WINDOWS_STORE OR 40 TBB_WINDOWS_DRIVER OR 41 TBB_SANITIZE MATCHES "thread")) 42 target_compile_definitions(tbbmalloc PRIVATE __TBB_USE_ITT_NOTIFY) 43endif() 44 45target_include_directories(tbbmalloc 46 PUBLIC 47 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../include> 48 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) 49 50# TODO: fix warnings 51if (MSVC) 52 # signed unsigned mismatch, declaration hides class member 53 set(TBB_WARNING_SUPPRESS ${TBB_WARNING_SUPPRESS} /wd4267 /wd4244 /wd4245 /wd4458) 54endif() 55 56target_compile_options(tbbmalloc 57 PRIVATE 58 ${TBB_CXX_STD_FLAG} # TODO: consider making it PUBLIC. 59 ${TBB_MMD_FLAG} 60 ${TBB_DSE_FLAG} 61 ${TBB_WARNING_LEVEL} 62 ${TBB_WARNING_SUPPRESS} 63 ${TBB_LIB_COMPILE_FLAGS} 64 ${TBBMALLOC_LIB_COMPILE_FLAGS} 65 ${TBB_COMMON_COMPILE_FLAGS} 66) 67 68enable_language(C) 69 70# Avoid use of target_link_libraries here as it changes /DEF option to \DEF on Windows. 71set_target_properties(tbbmalloc PROPERTIES 72 DEFINE_SYMBOL "" 73 VERSION ${TBBMALLOC_BINARY_VERSION}.${TBB_BINARY_MINOR_VERSION} 74 SOVERSION ${TBBMALLOC_BINARY_VERSION} 75 LINKER_LANGUAGE C 76) 77 78tbb_handle_ipo(tbbmalloc) 79 80if (TBB_DEF_FILE_PREFIX) # If there's no prefix, assume we're using export directives 81 set_target_properties(tbbmalloc PROPERTIES 82 LINK_FLAGS "${TBB_LINK_DEF_FILE_FLAG}\"${CMAKE_CURRENT_SOURCE_DIR}/def/${TBB_DEF_FILE_PREFIX}-tbbmalloc.def\"" 83 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/def/${TBB_DEF_FILE_PREFIX}-tbbmalloc.def" 84 ) 85endif() 86 87set(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES "") 88 89# Prefer using target_link_options instead of target_link_libraries to specify link options because 90# target_link_libraries may incorrectly handle some options (on Windows, for example). 91if (COMMAND target_link_options) 92 target_link_options(tbbmalloc 93 PRIVATE 94 ${TBB_LIB_LINK_FLAGS} 95 ${TBB_COMMON_LINK_FLAGS} 96 ) 97else() 98 target_link_libraries(tbbmalloc 99 PRIVATE 100 ${TBB_LIB_LINK_FLAGS} 101 ${TBB_COMMON_LINK_FLAGS} 102 ) 103endif() 104 105target_link_libraries(tbbmalloc 106 PRIVATE 107 Threads::Threads 108 ${TBB_LIB_LINK_LIBS} 109 ${TBB_COMMON_LINK_LIBS} 110) 111 112tbb_install_target(tbbmalloc) 113 114