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 (NOT BUILD_SHARED_LIBS) 16 return() 17endif() 18 19add_library(tbbmalloc_proxy 20 function_replacement.cpp 21 proxy.cpp) 22 23if (WIN32) 24 target_sources(tbbmalloc_proxy PRIVATE tbbmalloc_proxy.rc) 25endif() 26 27add_library(TBB::tbbmalloc_proxy ALIAS tbbmalloc_proxy) 28 29target_compile_definitions(tbbmalloc_proxy 30 PUBLIC 31 $<$<CONFIG:DEBUG>:TBB_USE_DEBUG> 32 PRIVATE 33 __TBBMALLOCPROXY_BUILD) 34 35target_include_directories(tbbmalloc_proxy 36 PUBLIC 37 $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../../include> 38 $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) 39 40if (NOT APPLE AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") 41 # gcc 5.0 and later have -Wno-sized-deallocation options 42 set(TBB_WARNING_SUPPRESS ${TBB_WARNING_SUPPRESS} 43 $<$<NOT:$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},5.0>>:-Wno-sized-deallocation>) 44endif() 45 46target_compile_options(tbbmalloc_proxy 47 PRIVATE 48 ${TBB_CXX_STD_FLAG} # TODO: consider making it PUBLIC. 49 ${TBB_MMD_FLAG} 50 ${TBB_DSE_FLAG} 51 ${TBB_WARNING_LEVEL} 52 ${TBB_WARNING_SUPPRESS} 53 ${TBB_LIB_COMPILE_FLAGS} 54 ${TBB_COMMON_COMPILE_FLAGS} 55) 56 57set_target_properties(tbbmalloc_proxy PROPERTIES 58 VERSION ${TBBMALLOC_BINARY_VERSION}.${TBB_BINARY_MINOR_VERSION} 59 SOVERSION ${TBBMALLOC_BINARY_VERSION}) 60 61if (UNIX AND NOT APPLE) 62 # Avoid use of target_link_libraries here as it changes /DEF option to \DEF on Windows. 63 set_target_properties(tbbmalloc_proxy PROPERTIES 64 LINK_FLAGS "${TBB_LINK_DEF_FILE_FLAG}\"${CMAKE_CURRENT_SOURCE_DIR}/def/${TBB_DEF_FILE_PREFIX}-proxy.def\"" 65 LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/def/${TBB_DEF_FILE_PREFIX}-proxy.def" 66 DEFINE_SYMBOL "") 67endif() 68 69# Prefer using target_link_options instead of target_link_libraries to specify link options because 70# target_link_libraries may incorrectly handle some options (on Windows, for example). 71if (COMMAND target_link_options) 72 target_link_options(tbbmalloc_proxy 73 PRIVATE 74 ${TBB_LIB_LINK_FLAGS} 75 ${TBB_COMMON_LINK_FLAGS} 76 ) 77else() 78 target_link_libraries(tbbmalloc_proxy 79 PRIVATE 80 ${TBB_LIB_LINK_FLAGS} 81 ${TBB_COMMON_LINK_FLAGS} 82 ) 83endif() 84 85target_link_libraries(tbbmalloc_proxy 86 PRIVATE 87 TBB::tbbmalloc 88 Threads::Threads 89 ${TBB_LIB_LINK_LIBS} 90 ${TBB_COMMON_LINK_LIBS} 91) 92 93tbb_install_target(tbbmalloc_proxy) 94