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