Skip to content

Commit 78af438

Browse files
committed
Check if compiler supports -fcf-protection=full
Cross-compilation toolchains may not support `-fcf-protection=full` which can cause build failures. This patch fixes the issue by checking if the compiler emits an error when the option is uses instead of using compiler version ranges.
1 parent 2851acd commit 78af438

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

cmake/helpers.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ macro(add_sanitizer_flag flag)
5858
set(CMAKE_REQUIRED_LIBRARIES ${SAVED_CMAKE_REQUIRED_LIBRARIES})
5959
endmacro()
6060

61+
check_cxx_compiler_flag("-fcf-protection=full" CXX_HAS_FCF_PROTECTION_FULL)
62+
6163
function(add_ur_target_compile_options name)
6264
if(NOT MSVC)
6365
target_compile_definitions(${name} PRIVATE -D_FORTIFY_SOURCE=2)
@@ -78,8 +80,7 @@ function(add_ur_target_compile_options name)
7880
# See: https://github.com/oneapi-src/unified-runtime/issues/2120
7981
# -flto
8082
# $<$<CXX_COMPILER_ID:Clang,AppleClang>:-fsanitize=cfi>
81-
# -fcf-protection not supported in GCC < 8
82-
$<$<OR:$<NOT:$<CXX_COMPILER_ID:GNU>>,$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,8>>:-fcf-protection=full>
83+
$<$<BOOL:${CXX_HAS_FCF_PROTECTION_FULL}>:-fcf-protection=full>
8384
# -fstack-clash-protection is not supported in apple clang or GCC < 8
8485
$<$<AND:$<CXX_COMPILER_ID:GNU>,$<VERSION_GREATER_EQUAL:$<CXX_COMPILER_VERSION>,8>>:-fstack-clash-protection>
8586
$<$<CXX_COMPILER_ID:Clang>:-fstack-clash-protection>

0 commit comments

Comments
 (0)