Debian Codegraph @

third-party/tbb/cmake/compilers/MSVC.cmake

raw
1 # Copyright (c) 2020-2025 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 set(TBB_LINK_DEF_FILE_FLAG ${CMAKE_LINK_DEF_FILE_FLAG})
16 set(TBB_DEF_FILE_PREFIX win${TBB_ARCH})
17
18 # Workaround for CMake issue https://gitlab.kitware.com/cmake/cmake/issues/18317.
19 # TODO: consider use of CMP0092 CMake policy.
20 string(REGEX REPLACE "/W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
21
22 set(TBB_WARNING_LEVEL $<$<NOT:$<CXX_COMPILER_ID:Intel>>:/W4> $<$<BOOL:${TBB_STRICT}>:/WX>)
23
24 # Warning suppression C4324: structure was padded due to alignment specifier
25 set(TBB_WARNING_SUPPRESS /wd4324)
26
27 set(TBB_TEST_COMPILE_FLAGS ${TBB_TEST_COMPILE_FLAGS} /bigobj)
28 if (MSVC_VERSION LESS_EQUAL 1900)
29 # Warning suppression C4503 for VS2015 and earlier:
30 # decorated name length exceeded, name was truncated.
31 # More info can be found at
32 # https://docs.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4503
33 set(TBB_TEST_COMPILE_FLAGS ${TBB_TEST_COMPILE_FLAGS} /wd4503)
34 endif()
35 set(TBB_LIB_COMPILE_FLAGS -D_CRT_SECURE_NO_WARNINGS /GS)
36 set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} /volatile:iso /FS /EHsc)
37
38 set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} /DEPENDENTLOADFLAG:0x2000 /DYNAMICBASE /NXCOMPAT)
39
40 if (TBB_ARCH EQUAL 32)
41 set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} /SAFESEH )
42 endif()
43
44 # Ignore /WX set through add_compile_options() or added to CMAKE_CXX_FLAGS if TBB_STRICT is disabled.
45 if (NOT TBB_STRICT AND COMMAND tbb_remove_compile_flag)
46 tbb_remove_compile_flag(/WX)
47 endif()
48
49 if (WINDOWS_STORE OR TBB_WINDOWS_DRIVER)
50 set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} /D_WIN32_WINNT=0x0A00)
51 set(TBB_COMMON_LINK_FLAGS -NODEFAULTLIB:kernel32.lib -INCREMENTAL:NO)
52 set(TBB_COMMON_LINK_LIBS OneCore.lib)
53 endif()
54
55 if (WINDOWS_STORE)
56 if (NOT CMAKE_SYSTEM_VERSION EQUAL 10.0)
57 message(FATAL_ERROR "CMAKE_SYSTEM_VERSION must be equal to 10.0")
58 endif()
59
60 set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} /ZW /ZW:nostdlib)
61
62 # CMake define this extra lib, remove it for this build type
63 string(REGEX REPLACE "WindowsApp.lib" "" CMAKE_CXX_STANDARD_LIBRARIES "${CMAKE_CXX_STANDARD_LIBRARIES}")
64
65 if (TBB_NO_APPCONTAINER)
66 set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} -APPCONTAINER:NO)
67 endif()
68 endif()
69
70 if (TBB_WINDOWS_DRIVER)
71 # Since this is universal driver disable this variable
72 set(CMAKE_SYSTEM_PROCESSOR "")
73
74 # CMake define list additional libs, remove it for this build type
75 set(CMAKE_CXX_STANDARD_LIBRARIES "")
76
77 set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} /D _UNICODE /DUNICODE /DWINAPI_FAMILY=WINAPI_FAMILY_APP /D__WRL_NO_DEFAULT_LIB__)
78 endif()
79
80 if (TBB_FILE_TRIM AND NOT CMAKE_CXX_COMPILER_ID MATCHES "(Intel|IntelLLVM|Clang)")
81 add_compile_options(
82 "$<$<COMPILE_LANGUAGE:CXX>:/d1trimfile:${NATIVE_TBB_PROJECT_ROOT_DIR}\\>"
83 "$<$<COMPILE_LANGUAGE:CXX>:/d1trimfile:${CMAKE_SOURCE_DIR}/>")
84 endif()
85
86 if (TBB_CONTROL_FLOW_GUARD)
87 set(TBB_LIB_COMPILE_FLAGS ${TBB_LIB_COMPILE_FLAGS} /guard:cf)
88 set(TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} /guard:cf)
89 endif()
90
91 if (CMAKE_CXX_COMPILER_ID MATCHES "(Clang|IntelLLVM)")
92 if (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86|AMD64|i.86)")
93 set(TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -mrtm -mwaitpkg)
94 endif()
95 set(TBB_IPO_COMPILE_FLAGS $<$<NOT:$<CONFIG:Debug>>:-flto>)
96 set(TBB_IPO_LINK_FLAGS $<$<NOT:$<CONFIG:Debug>>:-flto>)
97 else()
98 set(TBB_IPO_COMPILE_FLAGS $<$<NOT:$<CONFIG:Debug>>:/GL>)
99 set(TBB_IPO_LINK_FLAGS $<$<NOT:$<CONFIG:Debug>>:-LTCG> $<$<NOT:$<CONFIG:Debug>>:-INCREMENTAL:NO>)
100 endif()
101
102 set(TBB_OPENMP_FLAG /openmp)
103 set(TBB_OPENMP_NO_LINK_FLAG TRUE) # TBB_OPENMP_FLAG will be used only on compilation but not on linkage