xref: /oneTBB/cmake/compilers/Clang.cmake (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
15if (APPLE)
16    set(TBB_LINK_DEF_FILE_FLAG -Wl,-exported_symbols_list,)
17    set(TBB_DEF_FILE_PREFIX mac${TBB_ARCH})
18
19    # For correct ucontext.h structures layout
20    set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -D_XOPEN_SOURCE)
21else()
22    set(TBB_LINK_DEF_FILE_FLAG -Wl,--version-script=)
23    set(TBB_DEF_FILE_PREFIX lin${TBB_ARCH})
24endif()
25
26# Depfile options (e.g. -MD) are inserted automatically in some cases.
27# Don't add -MMD to avoid conflicts in such cases.
28if (NOT CMAKE_GENERATOR MATCHES "Ninja" AND NOT CMAKE_CXX_DEPENDS_USE_COMPILER)
29    set(TBB_MMD_FLAG -MMD)
30endif()
31
32set(TBB_WARNING_LEVEL -Wall -Wextra $<$<BOOL:${TBB_STRICT}>:-Werror>)
33set(TBB_TEST_WARNING_FLAGS -Wshadow -Wcast-qual -Woverloaded-virtual -Wnon-virtual-dtor)
34
35# Ignore -Werror set through add_compile_options() or added to CMAKE_CXX_FLAGS if TBB_STRICT is disabled.
36if (NOT TBB_STRICT AND COMMAND tbb_remove_compile_flag)
37    tbb_remove_compile_flag(-Werror)
38endif()
39
40# Enable Intel(R) Transactional Synchronization Extensions (-mrtm) and WAITPKG instructions support (-mwaitpkg) on relevant processors
41if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86|AMD64)")
42    set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -mrtm $<$<NOT:$<VERSION_LESS:${CMAKE_CXX_COMPILER_VERSION},12.0>>:-mwaitpkg>)
43endif()
44
45set(TBB_COMMON_LINK_LIBS dl)
46
47if (ANDROID_PLATFORM)
48    set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} $<$<NOT:$<CONFIG:Debug>>:-D_FORTIFY_SOURCE=2>)
49endif()
50
51# Enabling LTO on Android causes the NDK bug.
52# NDK throws the warning: "argument unused during compilation: '-Wa,--noexecstack'"
53if (NOT ANDROID_PLATFORM)
54    set(TBB_IPO_COMPILE_FLAGS $<$<NOT:$<CONFIG:Debug>>:-flto>)
55    set(TBB_IPO_LINK_FLAGS $<$<NOT:$<CONFIG:Debug>>:-flto>)
56endif()
57
58# TBB malloc settings
59set(TBBMALLOC_LIB_COMPILE_FLAGS -fno-rtti -fno-exceptions)
60