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