Skip to content

Commit

Permalink
Wrap linker flags on Windows for IntelLLVM
Browse files Browse the repository at this point in the history
The Intel C++ compiler requires linker flags to be wrapped, because
CMake passes them through the compiler driver.
Prefix Linker options with `${CMAKE_CXX_LINKER_WRAPPER_FLAG}`.
This variable is set to the option to pass a linker flag through the
compiler driver by CMake. For MSVC and clang-cl or IntelLLVM pre cmake
3.25 this will be empty, so the patch will work in these cases too.

Fixes: #205
Signed-off-by: Gergely Meszaros <[email protected]>
  • Loading branch information
Maetveis authored and lisanna-dettwyler committed Oct 4, 2024
1 parent 65a95d9 commit b757f43
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:cf")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /DYNAMICBASE")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /DYNAMICBASE")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /DYNAMICBASE")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /guard:cf")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_CXX_LINKER_WRAPPER_FLAG}/DYNAMICBASE")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_CXX_LINKER_WRAPPER_FLAG}/guard:cf")
# enable Spectre Mitigation, not supported by clang-cl
if((NOT CMAKE_CXX_COMPILER_ID STREQUAL Clang) AND (NOT CMAKE_CXX_COMPILER_ID STREQUAL IntelLLVM))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qspectre")
Expand Down Expand Up @@ -138,10 +138,10 @@ if(MSVC)

# enable creation of PDB files for Release Builds
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /Zi")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} /DEBUG /OPT:REF /OPT:ICF")
set(CMAKE_SHARED_LINKER_FLAGS_RELEASE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE} ${CMAKE_CXX_LINKER_WRAPPER_FLAG}/DEBUG ${CMAKE_CXX_LINKER_WRAPPER_FLAG}/OPT:REF ${CMAKE_CXX_LINKER_WRAPPER_FLAG}/OPT:ICF")

# enable CET shadow stack
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /CETCOMPAT")
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${CMAKE_CXX_LINKER_WRAPPER_FLAG}/CETCOMPAT")

#Use of sccache with MSVC requires workaround of replacing /Zi with /Z7
#https://github.com/mozilla/sccache
Expand Down

0 comments on commit b757f43

Please sign in to comment.