Fix Windows Clang compiler flags in CMake configuration #1936
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes Windows build compatibility issues when using Clang as the compiler on Windows (with the MSVC toolchain). The build system was previously attempting to use Linux-specific compiler and linker flags that are not supported on Windows, causing build failures or warnings. This change adds conditional logic to use platform-appropriate flags based on the target platform.
Context:
When Clang is used on Windows (not MSVC compiler, but Clang with MSVC toolchain), it has different capabilities and limitations compared to Clang on Linux. The previous code assumed a Linux-like environment, which caused issues on Windows.
Key Changes:
DEF File Format Handling (lines 41-48):
.deffile format viaCMAKE_LINK_DEF_FILE_FLAGinstead of Linux version-script formatwin${TBB_ARCH}prefix for Windows DEF files instead oflin${TBB_ARCH}Compile Flags (lines 72-78):
-fPICon Windows (not supported by Clang with MSVC toolchain)-fstack-clash-protectionand-fcf-protectionon Windows (not supported)-D_CRT_SECURE_NO_WARNINGSto suppress CRT security warnings for deprecated functions (e.g.,getenv,strncpy) that TBB uses-fstack-protector-strongand format security checks on WindowsLibrary Compile Flags (line 80):
-fstack-clash-protectionand-fcf-protection=fullflagsLinker Flags (lines 84-88):
-zlinker options (relro, now, noexecstack)lld-linkon Windows-zswitch is not supported on both macOS and WindowsImpact:
.deffile format is used instead of Linux version-scriptFixes # - issue number(s) if exists
Type of change
Choose one or multiple, leave empty if none of the other choices apply
Add a respective label(s) to PR if you have permissions
Tests
Documentation
Breaks backward compatibility
Notify the following users
List users with
@to send notificationsOther information
Testing:
Technical Details:
WIN32CMake variable to detect Windows platform (works for both native Windows and cross-compilation)WIN32is true, ensuring other platforms are unaffected-zlinker options are Linux ELF-specific and not supported bylld-linkon Windows-fPICis not needed on Windows as DLLs use a different linking model