| 1 |
# Copyright (c) 2020-2024 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 |
|
| 15 |
if (EMSCRIPTEN) |
| 16 |
set(TBB_EMSCRIPTEN 1) |
| 17 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -fexceptions) |
| 18 |
set(TBB_TEST_LINK_FLAGS ${TBB_COMMON_LINK_FLAGS} -fexceptions -sINITIAL_MEMORY=65536000 -sALLOW_MEMORY_GROWTH=1 -sMALLOC=mimalloc -sEXIT_RUNTIME=1) |
| 19 |
if (NOT EMSCRIPTEN_WITHOUT_PTHREAD) |
| 20 |
set_property(TARGET Threads::Threads PROPERTY INTERFACE_LINK_LIBRARIES "-pthread") |
| 21 |
endif() |
| 22 |
set(TBB_EMSCRIPTEN_STACK_SIZE 65536) |
| 23 |
set(TBB_LIB_COMPILE_FLAGS -D__TBB_EMSCRIPTEN_STACK_SIZE=${TBB_EMSCRIPTEN_STACK_SIZE}) |
| 24 |
set(TBB_TEST_LINK_FLAGS ${TBB_TEST_LINK_FLAGS} -sTOTAL_STACK=${TBB_EMSCRIPTEN_STACK_SIZE}) |
| 25 |
unset(TBB_EMSCRIPTEN_STACK_SIZE) |
| 26 |
endif() |
| 27 |
|
| 28 |
if (MINGW) |
| 29 |
set(TBB_LINK_DEF_FILE_FLAG "") |
| 30 |
set(TBB_DEF_FILE_PREFIX "") |
| 31 |
elseif (APPLE) |
| 32 |
set(TBB_LINK_DEF_FILE_FLAG -Wl,-exported_symbols_list,) |
| 33 |
set(TBB_DEF_FILE_PREFIX mac${TBB_ARCH}) |
| 34 |
|
| 35 |
# For correct ucontext.h structures layout |
| 36 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -D_XOPEN_SOURCE) |
| 37 |
elseif (MSVC) |
| 38 |
include(${CMAKE_CURRENT_LIST_DIR}/MSVC.cmake) |
| 39 |
return() |
| 40 |
else() |
| 41 |
set(TBB_LINK_DEF_FILE_FLAG -Wl,--version-script=) |
| 42 |
set(TBB_DEF_FILE_PREFIX lin${TBB_ARCH}) |
| 43 |
set(TBB_TEST_COMPILE_FLAGS ${TBB_TEST_COMPILE_FLAGS} $<$<NOT:$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},10.0>>:-ffp-model=precise>) |
| 44 |
endif() |
| 45 |
|
| 46 |
# Depfile options (e.g. -MD) are inserted automatically in some cases. |
| 47 |
# Don't add -MMD to avoid conflicts in such cases. |
| 48 |
if (NOT CMAKE_GENERATOR MATCHES "Ninja" AND NOT CMAKE_CXX_DEPENDS_USE_COMPILER) |
| 49 |
set(TBB_MMD_FLAG -MMD) |
| 50 |
endif() |
| 51 |
|
| 52 |
set(TBB_WARNING_LEVEL -Wall -Wextra $<$<BOOL:${TBB_STRICT}>:-Werror>) |
| 53 |
set(TBB_TEST_WARNING_FLAGS -Wshadow -Wcast-qual -Woverloaded-virtual -Wnon-virtual-dtor) |
| 54 |
|
| 55 |
# Ignore -Werror set through add_compile_options() or added to CMAKE_CXX_FLAGS if TBB_STRICT is disabled. |
| 56 |
if (NOT TBB_STRICT AND COMMAND tbb_remove_compile_flag) |
| 57 |
tbb_remove_compile_flag(-Werror) |
| 58 |
endif() |
| 59 |
|
| 60 |
# Enable Intel(R) Transactional Synchronization Extensions (-mrtm) and WAITPKG instructions support (-mwaitpkg) on relevant processors |
| 61 |
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(AMD64|amd64|i.86|x86)" AND NOT EMSCRIPTEN) |
| 62 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -mrtm $<$<NOT:$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},12.0>>:-mwaitpkg>) |
| 63 |
endif() |
| 64 |
|
| 65 |
# Clang flags to prevent compiler from optimizing out security checks |
| 66 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security -fPIC $<$<NOT:$<BOOL:${EMSCRIPTEN}>>:-fstack-protector-strong>) |
| 67 |
|
| 68 |
# -z switch is not supported on MacOS |
| 69 |
if (NOT APPLE) |
| 70 |
set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} -Wl,-z,relro,-z,now) |
| 71 |
endif() |
| 72 |
|
| 73 |
set(TBB_COMMON_LINK_LIBS ${CMAKE_DL_LIBS}) |
| 74 |
|
| 75 |
if (NOT CMAKE_CXX_FLAGS MATCHES "_FORTIFY_SOURCE") |
| 76 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} $<$<NOT:$<CONFIG:Debug>>:-D_FORTIFY_SOURCE=2>) |
| 77 |
endif () |
| 78 |
|
| 79 |
if (MINGW) |
| 80 |
list(APPEND TBB_COMMON_COMPILE_FLAGS -U__STRICT_ANSI__) |
| 81 |
endif() |
| 82 |
|
| 83 |
if (TBB_FILE_TRIM AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10) |
| 84 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -ffile-prefix-map=${NATIVE_TBB_PROJECT_ROOT_DIR}/= -ffile-prefix-map=${NATIVE_TBB_RELATIVE_BIN_PATH}/=) |
| 85 |
endif () |
| 86 |
|
| 87 |
set(TBB_IPO_COMPILE_FLAGS $<$<NOT:$<CONFIG:Debug>>:-flto>) |
| 88 |
set(TBB_IPO_LINK_FLAGS $<$<NOT:$<CONFIG:Debug>>:-flto>) |
| 89 |
|
| 90 |
# TBB malloc settings |
| 91 |
set(TBBMALLOC_LIB_COMPILE_FLAGS -fno-rtti -fno-exceptions) |