@@ -27,16 +27,18 @@ include("cmake/utils.cmake")
27
27
# The flags that can be used for the main and host compilers should be moved to
28
28
# the macros to avoid code duplication and ensure consistency.
29
29
macro (sdl_unix_common_ccxx_flags var)
30
- append (${var} "-fPIC -Wformat -Wformat-security" )
30
+ test_compiler_and_add_flag("-fPIC" ${var} )
31
+ test_compiler_and_add_flag("-Wformat" ${var} )
32
+ test_compiler_and_add_flag("-Wformat-security" ${var} )
31
33
endmacro ()
32
34
33
35
macro (sdl_gnu_common_ccxx_flags var gnu_version)
34
36
if (${gnu_version} VERSION_LESS 4.9)
35
- append ( ${var} "-fstack-protector-all" )
37
+ test_compiler_and_add_flag( "-fstack-protector-all" ${var} )
36
38
else ()
37
- append ( ${var} "-fstack-protector-strong" )
39
+ test_compiler_and_add_flag( "-fstack-protector-strong" ${var} )
38
40
if (NOT (${gnu_version} VERSION_LESS 8.0) AND (DNNL_TARGET_ARCH STREQUAL "X64" ))
39
- append ( ${var} "-fcf-protection=full" )
41
+ test_compiler_and_add_flag( "-fcf-protection=full" ${var} )
40
42
endif ()
41
43
endif ()
42
44
endmacro ()
@@ -48,7 +50,7 @@ endmacro()
48
50
# this warning on, let's use it too. Applicable for the library sources
49
51
# and interfaces only (tests currently rely on that fact heavily)
50
52
macro (sdl_gnu_src_ccxx_flags var)
51
- append ( ${var} "-Wmissing-field-initializers" )
53
+ test_compiler_and_add_flag( "-Wmissing-field-initializers" ${var} )
52
54
endmacro ()
53
55
54
56
macro (sdl_gnu_example_ccxx_flags var)
@@ -62,7 +64,7 @@ set(ONEDNN_SDL_LINKER_FLAGS)
62
64
if (UNIX )
63
65
sdl_unix_common_ccxx_flags(ONEDNN_SDL_COMPILER_FLAGS)
64
66
if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
65
- append (ONEDNN_SDL_COMPILER_FLAGS "-D_FORTIFY_SOURCE=2" )
67
+ test_compiler_and_add_flag( "-D_FORTIFY_SOURCE=2" ONEDNN_SDL_COMPILER_FLAGS )
66
68
endif ()
67
69
if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "GNU" )
68
70
sdl_gnu_common_ccxx_flags(ONEDNN_SDL_COMPILER_FLAGS CMAKE_CXX_COMPILER_VERSION)
@@ -72,10 +74,10 @@ if(UNIX)
72
74
get_filename_component (CXX_CMD_NAME ${CMAKE_CXX_COMPILER} NAME )
73
75
# Fujitsu CXX compiler does not support "-fstack-protector-all".
74
76
if (NOT CXX_CMD_NAME STREQUAL "FCC" )
75
- append (ONEDNN_SDL_COMPILER_FLAGS "-fstack-protector-all" )
77
+ test_compiler_and_add_flag( "-fstack-protector-all" ONEDNN_SDL_COMPILER_FLAGS )
76
78
endif ()
77
79
elseif ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Intel" )
78
- append (ONEDNN_SDL_COMPILER_FLAGS "-fstack-protector" )
80
+ test_compiler_and_add_flag( "-fstack-protector" ONEDNN_SDL_COMPILER_FLAGS )
79
81
endif ()
80
82
if (APPLE )
81
83
append (ONEDNN_SDL_LINKER_FLAGS "-Wl,-bind_at_load" )
@@ -86,20 +88,29 @@ if(UNIX)
86
88
endif ()
87
89
elseif (WIN32 )
88
90
if ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "MSVC" )
89
- append (ONEDNN_SDL_COMPILER_FLAGS "/GS /Gy /guard:cf /DYNAMICBASE /sdl" )
91
+ test_compiler_and_add_flag("/GS" ONEDNN_SDL_COMPILER_FLAGS)
92
+ test_compiler_and_add_flag("/Gy" ONEDNN_SDL_COMPILER_FLAGS)
93
+ test_compiler_and_add_flag("/guard:cf" ONEDNN_SDL_COMPILER_FLAGS)
94
+ test_compiler_and_add_flag("/DYNAMICBASE" ONEDNN_SDL_COMPILER_FLAGS)
95
+ test_compiler_and_add_flag("/sdl" ONEDNN_SDL_COMPILER_FLAGS)
90
96
append (ONEDNN_SDL_LINKER_FLAGS "/NXCOMPAT /LTCG" )
91
97
elseif (CMAKE_BASE_NAME STREQUAL "icx" )
92
- append (ONEDNN_SDL_COMPILER_FLAGS "/GS /Gy /guard:cf /Wformat /Wformat-security" )
98
+ test_compiler_and_add_flag("/GS" ONEDNN_SDL_COMPILER_FLAGS)
99
+ test_compiler_and_add_flag("/Gy" ONEDNN_SDL_COMPILER_FLAGS)
100
+ test_compiler_and_add_flag("/guard:cf" ONEDNN_SDL_COMPILER_FLAGS)
101
+ test_compiler_and_add_flag("/Wformat" ONEDNN_SDL_COMPILER_FLAGS)
102
+ test_compiler_and_add_flag("/Wformat-security" ONEDNN_SDL_COMPILER_FLAGS)
93
103
append (ONEDNN_SDL_LINKER_FLAGS "/link /NXCOMPAT" )
94
104
elseif ("${CMAKE_CXX_COMPILER_ID} " STREQUAL "Clang" )
95
- append (ONEDNN_SDL_COMPILER_FLAGS "-Wformat -Wformat-security" )
105
+ test_compiler_and_add_flag("-Wformat" ONEDNN_SDL_COMPILER_FLAGS)
106
+ test_compiler_and_add_flag("-Wformat-security" ONEDNN_SDL_COMPILER_FLAGS)
96
107
if (UPPERCASE_CMAKE_BUILD_TYPE STREQUAL "RELEASE" )
97
- append (ONEDNN_SDL_COMPILER_FLAGS "-D_FORTIFY_SOURCE=2" )
108
+ test_compiler_and_add_flag( "-D_FORTIFY_SOURCE=2" ONEDNN_SDL_COMPILER_FLAGS )
98
109
endif ()
99
110
get_filename_component (CXX_CMD_NAME ${CMAKE_CXX_COMPILER} NAME )
100
111
# Fujitsu CXX compiler does not support "-fstack-protector-all".
101
112
if (NOT CXX_CMD_NAME STREQUAL "FCC" )
102
- append (ONEDNN_SDL_COMPILER_FLAGS "-fstack-protector-all" )
113
+ test_compiler_and_add_flag( "-fstack-protector-all" ONEDNN_SDL_COMPILER_FLAGS )
103
114
endif ()
104
115
append (ONEDNN_SDL_LINKER_FLAGS "-Xlinker /NXCOMPAT -Xlinker /LTCG" )
105
116
endif ()
0 commit comments