| 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 (MINGW) |
| 16 |
set(TBB_LINK_DEF_FILE_FLAG "") |
| 17 |
set(TBB_DEF_FILE_PREFIX "") |
| 18 |
elseif (APPLE) |
| 19 |
set(TBB_LINK_DEF_FILE_FLAG -Wl,-exported_symbols_list,) |
| 20 |
set(TBB_DEF_FILE_PREFIX mac${TBB_ARCH}) |
| 21 |
|
| 22 |
# For correct ucontext.h structures layout |
| 23 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -D_XOPEN_SOURCE) |
| 24 |
else() |
| 25 |
set(TBB_LINK_DEF_FILE_FLAG -Wl,--version-script=) |
| 26 |
set(TBB_DEF_FILE_PREFIX lin${TBB_ARCH}) |
| 27 |
endif() |
| 28 |
|
| 29 |
set(TBB_WARNING_LEVEL -Wall -Wextra $<$<BOOL:${TBB_STRICT}>:-Werror> -Wfatal-errors) |
| 30 |
set(TBB_TEST_WARNING_FLAGS -Wshadow -Wcast-qual -Woverloaded-virtual -Wnon-virtual-dtor) |
| 31 |
|
| 32 |
# Depfile options (e.g. -MD) are inserted automatically in some cases. |
| 33 |
# Don't add -MMD to avoid conflicts in such cases. |
| 34 |
if (NOT CMAKE_GENERATOR MATCHES "Ninja" AND NOT CMAKE_CXX_DEPENDS_USE_COMPILER) |
| 35 |
set(TBB_MMD_FLAG -MMD) |
| 36 |
endif() |
| 37 |
|
| 38 |
|
| 39 |
# Binutils < 2.31.1 do not support the tpause instruction. When compiling with |
| 40 |
# a modern version of GCC (supporting it) but relying on an outdated assembler, |
| 41 |
# will result in an error reporting "no such instruction: tpause". |
| 42 |
# The following code invokes the GNU assembler to extract the version number |
| 43 |
# and convert it to an integer that can be used in the C++ code to compare |
| 44 |
# against, and conditionally disable the __TBB_WAITPKG_INTRINSICS_PRESENT |
| 45 |
# macro if the version is incompatible. Binutils only report the version in the |
| 46 |
# MAJOR.MINOR format, therefore the version checked is >=2.32 (instead of |
| 47 |
# >=2.31.1). Capturing the output in CMake can be done like below. The version |
| 48 |
# information is written to either stdout or stderr. To not make any |
| 49 |
# assumptions, both are captured. |
| 50 |
execute_process( |
| 51 |
COMMAND ${CMAKE_COMMAND} -E env "LANG=C" ${CMAKE_CXX_COMPILER} -xc -c /dev/null -Wa,-v -o/dev/null |
| 52 |
OUTPUT_VARIABLE ASSEMBLER_VERSION_LINE_OUT |
| 53 |
ERROR_VARIABLE ASSEMBLER_VERSION_LINE_ERR |
| 54 |
OUTPUT_STRIP_TRAILING_WHITESPACE |
| 55 |
ERROR_STRIP_TRAILING_WHITESPACE |
| 56 |
) |
| 57 |
set(ASSEMBLER_VERSION_LINE ${ASSEMBLER_VERSION_LINE_OUT}${ASSEMBLER_VERSION_LINE_ERR}) |
| 58 |
string(REGEX REPLACE ".*GNU assembler version ([0-9]+)\\.([0-9]+).*" "\\1" _tbb_gnu_asm_major_version "${ASSEMBLER_VERSION_LINE}") |
| 59 |
string(REGEX REPLACE ".*GNU assembler version ([0-9]+)\\.([0-9]+).*" "\\2" _tbb_gnu_asm_minor_version "${ASSEMBLER_VERSION_LINE}") |
| 60 |
unset(ASSEMBLER_VERSION_LINE_OUT) |
| 61 |
unset(ASSEMBLER_VERSION_LINE_ERR) |
| 62 |
unset(ASSEMBLER_VERSION_LINE) |
| 63 |
message(TRACE "Extracted GNU assembler version: major=${_tbb_gnu_asm_major_version} minor=${_tbb_gnu_asm_minor_version}") |
| 64 |
|
| 65 |
math(EXPR _tbb_gnu_asm_version_number "${_tbb_gnu_asm_major_version} * 1000 + ${_tbb_gnu_asm_minor_version}") |
| 66 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} "-D__TBB_GNU_ASM_VERSION=${_tbb_gnu_asm_version_number}") |
| 67 |
message(STATUS "GNU Assembler version: ${_tbb_gnu_asm_major_version}.${_tbb_gnu_asm_minor_version} (${_tbb_gnu_asm_version_number})") |
| 68 |
|
| 69 |
# Enable Intel(R) Transactional Synchronization Extensions (-mrtm) and WAITPKG instructions support (-mwaitpkg) on relevant processors |
| 70 |
if (CMAKE_SYSTEM_PROCESSOR MATCHES "(AMD64|amd64|i.86|x86)" AND NOT EMSCRIPTEN) |
| 71 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -mrtm $<$<AND:$<NOT:$<CXX_COMPILER_ID:Intel>>,$<NOT:$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},11.0>>>:-mwaitpkg>) |
| 72 |
endif() |
| 73 |
|
| 74 |
set(TBB_COMMON_LINK_LIBS ${CMAKE_DL_LIBS}) |
| 75 |
|
| 76 |
# Ignore -Werror set through add_compile_options() or added to CMAKE_CXX_FLAGS if TBB_STRICT is disabled. |
| 77 |
if (NOT TBB_STRICT AND COMMAND tbb_remove_compile_flag) |
| 78 |
tbb_remove_compile_flag(-Werror) |
| 79 |
endif() |
| 80 |
|
| 81 |
if (NOT ${CMAKE_CXX_COMPILER_ID} STREQUAL Intel) |
| 82 |
# gcc 6.0 and later have -flifetime-dse option that controls elimination of stores done outside the object lifetime |
| 83 |
set(TBB_DSE_FLAG $<$<NOT:$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},6.0>>:-flifetime-dse=1>) |
| 84 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} $<$<NOT:$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},8.0>>:-fstack-clash-protection>) |
| 85 |
|
| 86 |
# Suppress GCC 12.x-14.x warning here that to_wait_node(n)->my_is_in_list might have size 0 |
| 87 |
set(TBB_COMMON_LINK_FLAGS ${TBB_COMMON_LINK_FLAGS} $<$<AND:$<NOT:$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},12.0>>,$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},15.0>>:-Wno-stringop-overflow>) |
| 88 |
endif() |
| 89 |
|
| 90 |
# Workaround for heavy tests and too many symbols in debug (rellocation truncated to fit: R_MIPS_CALL16) |
| 91 |
if ("${CMAKE_SYSTEM_PROCESSOR}" MATCHES "mips") |
| 92 |
set(TBB_TEST_COMPILE_FLAGS ${TBB_TEST_COMPILE_FLAGS} -DTBB_TEST_LOW_WORKLOAD $<$<CONFIG:DEBUG>:-fPIE -mxgot>) |
| 93 |
set(TBB_TEST_LINK_FLAGS ${TBB_TEST_LINK_FLAGS} $<$<CONFIG:DEBUG>:-pie>) |
| 94 |
endif() |
| 95 |
|
| 96 |
set(TBB_IPO_COMPILE_FLAGS $<$<NOT:$<CONFIG:Debug>>:-flto>) |
| 97 |
set(TBB_IPO_LINK_FLAGS $<$<NOT:$<CONFIG:Debug>>:-flto>) |
| 98 |
|
| 99 |
|
| 100 |
if (MINGW AND CMAKE_SYSTEM_PROCESSOR MATCHES "i.86") |
| 101 |
list (APPEND TBB_COMMON_COMPILE_FLAGS -msse2) |
| 102 |
endif () |
| 103 |
|
| 104 |
# Gnu flags to prevent compiler from optimizing out security checks |
| 105 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -fno-strict-overflow -fno-delete-null-pointer-checks -fwrapv) |
| 106 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security |
| 107 |
-fstack-protector-strong ) |
| 108 |
# -z switch is not supported on MacOS and MinGW |
| 109 |
if (NOT APPLE AND NOT MINGW) |
| 110 |
set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} -Wl,-z,relro,-z,now,-z,noexecstack) |
| 111 |
endif() |
| 112 |
if (NOT CMAKE_CXX_FLAGS MATCHES "_FORTIFY_SOURCE") |
| 113 |
set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} $<$<NOT:$<CONFIG:Debug>>:-D_FORTIFY_SOURCE=2> ) |
| 114 |
endif () |
| 115 |
|
| 116 |
if (TBB_FILE_TRIM AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 8) |
| 117 |
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}/=) |
| 118 |
endif () |
| 119 |
|
| 120 |
# TBB malloc settings |
| 121 |
set(TBBMALLOC_LIB_COMPILE_FLAGS -fno-rtti -fno-exceptions) |
| 122 |
set(TBB_OPENMP_FLAG -fopenmp) |