diff --git a/cmake/SDL.cmake b/cmake/SDL.cmake index 0cfa5afc2e8..cae0c82097a 100644 --- a/cmake/SDL.cmake +++ b/cmake/SDL.cmake @@ -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() @@ -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) @@ -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) @@ -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") @@ -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() diff --git a/cmake/utils.cmake b/cmake/utils.cmake index c9cb780903d..fdd6b2c95dc 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -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()