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