Moving ASAN macros and calls to macros above the information output section so we can display ASAN information properly.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
diff --git a/CMakeLists.txt b/CMakeLists.txt
index b5316e5..8ba93bc 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2302,6 +2302,64 @@ Libs.private:")
"${SDL2_BINARY_DIR}/SDL2.spec" @ONLY)
endif()
+macro(check_add_debug_flag FLAG SUFFIX)
+ check_c_compiler_flag(${FLAG} HAS_C_FLAG_${SUFFIX})
+ if (HAS_C_FLAG_${SUFFIX})
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
+ endif()
+
+ check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
+ if (HAS_CXX_${SUFFIX})
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
+ endif()
+endmacro()
+
+macro(asan_check_add_debug_flag ASAN_FLAG)
+ check_add_debug_flag("-fsanitize=${ASAN_FLAG}" "${ASAN_FLAG}")
+endmacro()
+
+macro(asan_check_add_debug_flag2 ASAN_FLAG)
+ # for some sanitize flags we have to manipulate the CMAKE_REQUIRED_LIBRARIES:
+ # http://cmake.3232098.n2.nabble.com/CHECK-CXX-COMPILER-FLAG-doesn-t-give-correct-result-for-fsanitize-address-tp7600216p7600217.html
+
+ set(FLAG "-fsanitize=${ASAN_FLAG}")
+
+ set (STORED_REQLIBS ${CMAKE_REQUIRED_LIBRARIES})
+ set (CMAKE_REQUIRED_LIBRARIES "${FLAG};asan")
+ check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
+ check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
+ set (CMAKE_REQUIRED_LIBRARIES ${STORED_REQLIBS})
+
+ if (HAS_C_FLAG_${ASAN_FLAG})
+ set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
+ endif()
+
+ if (HAS_CXX_${ASAN_FLAG})
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
+ endif()
+endmacro()
+
+# enable AddressSanitizer if supported
+if (ASAN)
+ asan_check_add_debug_flag2("address")
+ asan_check_add_debug_flag("bool")
+ asan_check_add_debug_flag("bounds")
+ asan_check_add_debug_flag("enum")
+ asan_check_add_debug_flag("float-cast-overflow")
+ asan_check_add_debug_flag("float-divide-by-zero")
+ asan_check_add_debug_flag("nonnull-attribute")
+ asan_check_add_debug_flag("returns-nonnull-attribute")
+ asan_check_add_debug_flag("signed-integer-overflow")
+ asan_check_add_debug_flag("undefined")
+ asan_check_add_debug_flag("vla-bound")
+ asan_check_add_debug_flag("leak")
+ # The object size sanitizer has no effect on unoptimized builds on Clang,
+ # but causes warnings.
+ if((NOT USE_CLANG) OR (CMAKE_BUILD_TYPE STREQUAL ""))
+ asan_check_add_debug_flag("object-size")
+ endif()
+endif()
+
##### Info output #####
message(STATUS "")
message(STATUS "SDL2 was configured with the following options:")
@@ -2478,64 +2536,6 @@ if(SDL_STATIC)
endif()
endif()
-macro(check_add_debug_flag FLAG SUFFIX)
- check_c_compiler_flag(${FLAG} HAS_C_FLAG_${SUFFIX})
- if (HAS_C_FLAG_${SUFFIX})
- set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
- endif()
-
- check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX})
- if (HAS_CXX_${SUFFIX})
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
- endif()
-endmacro()
-
-macro(asan_check_add_debug_flag ASAN_FLAG)
- check_add_debug_flag("-fsanitize=${ASAN_FLAG}" "${ASAN_FLAG}")
-endmacro()
-
-macro(asan_check_add_debug_flag2 ASAN_FLAG)
- # for some sanitize flags we have to manipulate the CMAKE_REQUIRED_LIBRARIES:
- # http://cmake.3232098.n2.nabble.com/CHECK-CXX-COMPILER-FLAG-doesn-t-give-correct-result-for-fsanitize-address-tp7600216p7600217.html
-
- set(FLAG "-fsanitize=${ASAN_FLAG}")
-
- set (STORED_REQLIBS ${CMAKE_REQUIRED_LIBRARIES})
- set (CMAKE_REQUIRED_LIBRARIES "${FLAG};asan")
- check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG})
- check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG})
- set (CMAKE_REQUIRED_LIBRARIES ${STORED_REQLIBS})
-
- if (HAS_C_FLAG_${ASAN_FLAG})
- set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}")
- endif()
-
- if (HAS_CXX_${ASAN_FLAG})
- set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}")
- endif()
-endmacro()
-
-# enable AddressSanitizer if supported
-if (ASAN)
- asan_check_add_debug_flag2("address")
- asan_check_add_debug_flag("bool")
- asan_check_add_debug_flag("bounds")
- asan_check_add_debug_flag("enum")
- asan_check_add_debug_flag("float-cast-overflow")
- asan_check_add_debug_flag("float-divide-by-zero")
- asan_check_add_debug_flag("nonnull-attribute")
- asan_check_add_debug_flag("returns-nonnull-attribute")
- asan_check_add_debug_flag("signed-integer-overflow")
- asan_check_add_debug_flag("undefined")
- asan_check_add_debug_flag("vla-bound")
- asan_check_add_debug_flag("leak")
- # The object size sanitizer has no effect on unoptimized builds on Clang,
- # but causes warnings.
- if((NOT USE_CLANG) OR (CMAKE_BUILD_TYPE STREQUAL ""))
- asan_check_add_debug_flag("object-size")
- endif()
-endif()
-
##### Tests #####
if(SDL_TEST)