@@ -540,16 +540,44 @@ if(MSVC)
540
540
endif ()
541
541
542
542
# spectre mitigation
543
+ include (CheckCXXCompilerFlag)
543
544
if (MSVC )
544
- include (CheckCXXCompilerFlag)
545
545
check_cxx_compiler_flag(/Qspectre COMPILER_SUPPORTS_QSPECTRE)
546
546
check_cxx_compiler_flag(/d2guardspecload COMPILER_SUPPORTS_D2GUARDSPECLOAD)
547
547
if (COMPILER_SUPPORTS_QSPECTRE)
548
548
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Qspectre" )
549
549
elseif (COMPILER_SUPPORTS_D2GUARDSPECLOAD)
550
550
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /d2guardspecload" )
551
551
else ()
552
- message (STATUS "Spectre mitigation is not supported by the compiler" )
552
+ message (WARNING "Spectre mitigation is not supported by the compiler" )
553
+ endif ()
554
+ else ()
555
+ if (${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang" )
556
+ check_cxx_compiler_flag(-mretpoline COMPILER_SUPPORTS_RETPOLINE)
557
+ if (COMPILER_SUPPORTS_RETPOLINE)
558
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mretpoline" )
559
+ else ()
560
+ message (WARNING "Spectre mitigation -mretpoline flag is not supported by the compiler" )
561
+ endif ()
562
+ else ()
563
+ check_cxx_compiler_flag(-mindirect-branch=thunk COMPILER_SUPPORTS_INDIRECT_BRANCH_THUNK)
564
+ if (COMPILER_SUPPORTS_INDIRECT_BRANCH_THUNK)
565
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mindirect-branch=thunk" )
566
+ else ()
567
+ message (WARNING "Spectre mitigation -mindirect-branch=thunk flag is not supported by the compiler" )
568
+ endif ()
569
+ check_cxx_compiler_flag(-mfunction-return=thunk COMPILER_SUPPORTS_FUNCTION_RETURN_THUNK)
570
+ if (COMPILER_SUPPORTS_FUNCTION_RETURN_THUNK)
571
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mfunction-return=thunk" )
572
+ else ()
573
+ message (WARNING "Spectre mitigation -mfunction-return=thunk flag is not supported by the compiler" )
574
+ endif ()
575
+ check_cxx_compiler_flag(-mindirect-branch-register COMPILER_SUPPORTS_INDIRECT_BRANCH_REGISTER)
576
+ if (COMPILER_SUPPORTS_INDIRECT_BRANCH_REGISTER)
577
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mindirect-branch-register" )
578
+ else ()
579
+ message (WARNING "Spectre mitigation -mindirect-branch-register flag is not supported by the compiler" )
580
+ endif ()
553
581
endif ()
554
582
endif (MSVC )
555
583
0 commit comments