Skip to content

Commit

Permalink
revert: build: add check_cxx_compiler_flag for SDL flags
Browse files Browse the repository at this point in the history
This reverts commit e3782e8.
  • Loading branch information
spalicki committed Dec 5, 2024
1 parent 4d962e7 commit 262fb02
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 38 deletions.
37 changes: 13 additions & 24 deletions cmake/SDL.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,16 @@ include("cmake/utils.cmake")
# The flags that can be used for the main and host compilers should be moved to
# the macros to avoid code duplication and ensure consistency.
macro(sdl_unix_common_ccxx_flags var)
test_compiler_and_add_flag("-fPIC" ${var})
test_compiler_and_add_flag("-Wformat" ${var})
test_compiler_and_add_flag("-Wformat-security" ${var})
append(${var} "-fPIC -Wformat -Wformat-security")
endmacro()

macro(sdl_gnu_common_ccxx_flags var gnu_version)
if(${gnu_version} VERSION_LESS 4.9)
test_compiler_and_add_flag("-fstack-protector-all" ${var})
append(${var} "-fstack-protector-all")
else()
test_compiler_and_add_flag("-fstack-protector-strong" ${var})
append(${var} "-fstack-protector-strong")
if(NOT (${gnu_version} VERSION_LESS 8.0) AND (DNNL_TARGET_ARCH STREQUAL "X64"))
test_compiler_and_add_flag("-fcf-protection=full" ${var})
append(${var} "-fcf-protection=full")
endif()
endif()
endmacro()
Expand All @@ -50,7 +48,7 @@ endmacro()
# this warning on, let's use it too. Applicable for the library sources
# and interfaces only (tests currently rely on that fact heavily)
macro(sdl_gnu_src_ccxx_flags var)
test_compiler_and_add_flag("-Wmissing-field-initializers" ${var})
append(${var} "-Wmissing-field-initializers")
endmacro()

macro(sdl_gnu_example_ccxx_flags var)
Expand All @@ -64,7 +62,7 @@ set(ONEDNN_SDL_LINKER_FLAGS)
if(UNIX)
sdl_unix_common_ccxx_flags(ONEDNN_SDL_COMPILER_FLAGS)
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
test_compiler_and_add_flag("-D_FORTIFY_SOURCE=2" ONEDNN_SDL_COMPILER_FLAGS)
append(ONEDNN_SDL_COMPILER_FLAGS "-D_FORTIFY_SOURCE=2")
endif()
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
sdl_gnu_common_ccxx_flags(ONEDNN_SDL_COMPILER_FLAGS CMAKE_CXX_COMPILER_VERSION)
Expand All @@ -74,10 +72,10 @@ if(UNIX)
get_filename_component(CXX_CMD_NAME ${CMAKE_CXX_COMPILER} NAME)
# Fujitsu CXX compiler does not support "-fstack-protector-all".
if(NOT CXX_CMD_NAME STREQUAL "FCC")
test_compiler_and_add_flag("-fstack-protector-all" ONEDNN_SDL_COMPILER_FLAGS)
append(ONEDNN_SDL_COMPILER_FLAGS "-fstack-protector-all")
endif()
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
test_compiler_and_add_flag("-fstack-protector" ONEDNN_SDL_COMPILER_FLAGS)
append(ONEDNN_SDL_COMPILER_FLAGS "-fstack-protector")
endif()
if(APPLE)
append(ONEDNN_SDL_LINKER_FLAGS "-Wl,-bind_at_load")
Expand All @@ -88,29 +86,20 @@ if(UNIX)
endif()
elseif(WIN32)
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
test_compiler_and_add_flag("/GS" ONEDNN_SDL_COMPILER_FLAGS)
test_compiler_and_add_flag("/Gy" ONEDNN_SDL_COMPILER_FLAGS)
test_compiler_and_add_flag("/guard:cf" ONEDNN_SDL_COMPILER_FLAGS)
test_compiler_and_add_flag("/DYNAMICBASE" ONEDNN_SDL_COMPILER_FLAGS)
test_compiler_and_add_flag("/sdl" ONEDNN_SDL_COMPILER_FLAGS)
append(ONEDNN_SDL_COMPILER_FLAGS "/GS /Gy /guard:cf /DYNAMICBASE /sdl")
append(ONEDNN_SDL_LINKER_FLAGS "/NXCOMPAT /LTCG")
elseif(CMAKE_BASE_NAME STREQUAL "icx")
test_compiler_and_add_flag("/GS" ONEDNN_SDL_COMPILER_FLAGS)
test_compiler_and_add_flag("/Gy" ONEDNN_SDL_COMPILER_FLAGS)
test_compiler_and_add_flag("/guard:cf" ONEDNN_SDL_COMPILER_FLAGS)
test_compiler_and_add_flag("/Wformat" ONEDNN_SDL_COMPILER_FLAGS)
test_compiler_and_add_flag("/Wformat-security" ONEDNN_SDL_COMPILER_FLAGS)
append(ONEDNN_SDL_COMPILER_FLAGS "/GS /Gy /guard:cf /Wformat /Wformat-security")
append(ONEDNN_SDL_LINKER_FLAGS "/link /NXCOMPAT")
elseif("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
test_compiler_and_add_flag("-Wformat" ONEDNN_SDL_COMPILER_FLAGS)
test_compiler_and_add_flag("-Wformat-security" ONEDNN_SDL_COMPILER_FLAGS)
append(ONEDNN_SDL_COMPILER_FLAGS "-Wformat -Wformat-security")
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL "RELEASE")
test_compiler_and_add_flag("-D_FORTIFY_SOURCE=2" ONEDNN_SDL_COMPILER_FLAGS)
append(ONEDNN_SDL_COMPILER_FLAGS "-D_FORTIFY_SOURCE=2")
endif()
get_filename_component(CXX_CMD_NAME ${CMAKE_CXX_COMPILER} NAME)
# Fujitsu CXX compiler does not support "-fstack-protector-all".
if(NOT CXX_CMD_NAME STREQUAL "FCC")
test_compiler_and_add_flag("-fstack-protector-all" ONEDNN_SDL_COMPILER_FLAGS)
append(ONEDNN_SDL_COMPILER_FLAGS "-fstack-protector-all")
endif()
append(ONEDNN_SDL_LINKER_FLAGS "-Xlinker /NXCOMPAT -Xlinker /LTCG")
endif()
Expand Down
14 changes: 0 additions & 14 deletions cmake/utils.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,3 @@ function(find_libm var)
find_library(${var} m REQUIRED)
endif()
endfunction()

include(CheckCXXCompilerFlag)
macro(test_compiler_and_add_flag flag var)
set(CMAKE_REQUIRED_QUIET 1)
unset(COMPILER_SUPPORTS_FLAG CACHE)

if(NOT test_compiler_flag_nowarn)
append(CMAKE_REQUIRED_FLAGS "${CMAKE_CCXX_NOWARN_FLAGS}")
set(test_compiler_flag_nowarn true)
endif()

check_cxx_compiler_flag("${flag}" COMPILER_SUPPORTS_FLAG)
append_if(COMPILER_SUPPORTS_FLAG ${var} ${flag})
endmacro()

0 comments on commit 262fb02

Please sign in to comment.