@@ -38,8 +38,14 @@ elseif (MSVC)
3838 include (${CMAKE_CURRENT_LIST_DIR} /MSVC .cmake)
3939 return ()
4040else ()
41- set (TBB_LINK_DEF_FILE_FLAG -Wl,--version -script=)
42- set (TBB_DEF_FILE_PREFIX lin${TBB_ARCH} )
41+ # On Windows, use Windows .def file format, not Linux version-script
42+ if (WIN32 )
43+ set (TBB_LINK_DEF_FILE_FLAG ${CMAKE_LINK_DEF_FILE_FLAG} )
44+ set (TBB_DEF_FILE_PREFIX win${TBB_ARCH} )
45+ else ()
46+ set (TBB_LINK_DEF_FILE_FLAG -Wl,--version -script=)
47+ set (TBB_DEF_FILE_PREFIX lin${TBB_ARCH} )
48+ endif ()
4349 set (TBB_TEST_COMPILE_FLAGS ${TBB_TEST_COMPILE_FLAGS} $<$<NOT :$<VERSION_LESS :${CMAKE_CXX_COMPILER_VERSION} ,10.0>>:-ffp-model=precise>)
4450endif ()
4551
@@ -63,14 +69,21 @@ if (CMAKE_SYSTEM_PROCESSOR MATCHES "(AMD64|amd64|i.86|x86)" AND NOT EMSCRIPTEN)
6369endif ()
6470
6571# 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>)
72+ # Don't use -fPIC, -fstack-clash-protection, -fcf-protection on Windows (not supported by Clang with MSVC toolchain)
73+ # Also disable CRT security warnings on Windows (getenv, strncpy, etc. are deprecated but TBB uses them)
74+ if (WIN32 )
75+ set (TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security -D_CRT_SECURE_NO_WARNINGS $<$<NOT :$<BOOL :${EMSCRIPTEN} >>:-fstack-protector-strong>)
76+ else ()
77+ set (TBB_COMMON_COMPILE_FLAGS ${TBB_COMMON_COMPILE_FLAGS} -Wformat -Wformat-security -Werror=format-security -fPIC $<$<NOT :$<BOOL :${EMSCRIPTEN} >>:-fstack-protector-strong>)
78+ endif ()
6779
68- if (NOT APPLE AND NOT ANDROID_PLATFORM AND CMAKE_SYSTEM_PROCESSOR MATCHES "(AMD64|amd64|i.86|x86)" )
80+ if (NOT APPLE AND NOT ANDROID_PLATFORM AND CMAKE_SYSTEM_PROCESSOR MATCHES "(AMD64|amd64|i.86|x86)" AND NOT WIN32 )
6981 set (TBB_LIB_COMPILE_FLAGS ${TBB_LIB_COMPILE_FLAGS} -fstack-clash-protection $<$<NOT :$<BOOL :${EMSCRIPTEN} >>:-fcf-protection=full>)
7082endif ()
7183
72- # -z switch is not supported on MacOS
73- if (NOT APPLE )
84+ # -z switch is not supported on MacOS and Windows
85+ # On Windows, lld-link doesn't support -z options (Linux-specific)
86+ if (NOT APPLE AND NOT WIN32 )
7487 set (TBB_LIB_LINK_FLAGS ${TBB_LIB_LINK_FLAGS} -Wl,-z,relro,-z,now,-z,noexecstack)
7588endif ()
7689
0 commit comments