|
| 1 | +#[[ |
| 2 | +ProjectOptions.cmake - Defines project-specific options for CMake. |
| 3 | +]] |
| 4 | + |
| 5 | +set(CMAKE_CXX_STANDARD |
| 6 | + 20 |
| 7 | + CACHE STRING "C++ standard") |
| 8 | +set(CMAKE_CXX_STANDARD_REQUIRED |
| 9 | + ON |
| 10 | + CACHE BOOL "C++ standard required") |
| 11 | +set(CMAKE_CXX_EXTENSIONS |
| 12 | + OFF |
| 13 | + CACHE BOOL "C++ extensions") |
| 14 | + |
| 15 | +# ############################################################################## |
| 16 | +# Sanitizer - cmake-modules/build/Sanitizer.cmake |
| 17 | +# ############################################################################## |
| 18 | + |
| 19 | +set(USE_SANITIZER |
| 20 | + OFF |
| 21 | + CACHE BOOL "Enable sanitizer") |
| 22 | + |
| 23 | +# ############################################################################## |
| 24 | +# Valgrind - cmake-modules/test/Valgrind.cmake |
| 25 | +# ############################################################################## |
| 26 | + |
| 27 | +set(USE_VALGRIND |
| 28 | + OFF |
| 29 | + CACHE BOOL "Enable Valgrind") |
| 30 | +set(USE_VALGRIND_OPTIONS |
| 31 | + --leak-check=full # Each individual leak will be shown in detail. |
| 32 | + --show-leak-kinds=all # Show all of "definite, indirect, possible, |
| 33 | + # reachable" leak kinds in the "full" report. |
| 34 | + --gen-suppressions=all # gen suppress info automatically. |
| 35 | + --track-origins=yes # Favor useful output over speed. This tracks the |
| 36 | + # origins of uninitialized values, which could be very |
| 37 | + # useful for memory errors. Consider turning off if |
| 38 | + # Valgrind is unacceptably slow. |
| 39 | + CACHE STRING "valgrind options.") |
| 40 | + |
| 41 | +# ############################################################################## |
| 42 | +# Clang-Tidy - cmake-modules/build/ClangTidy.cmake |
| 43 | +# ############################################################################## |
| 44 | + |
| 45 | +set(USE_CLANGTIDY |
| 46 | + OFF |
| 47 | + CACHE BOOL "Enable Clang-Tidy") |
| 48 | + |
| 49 | +# ############################################################################## |
| 50 | +# Cppcheck - cmake-modules/build/Cppcheck.cmake |
| 51 | +# ############################################################################## |
| 52 | + |
| 53 | +set(USE_CPPCHECK |
| 54 | + OFF |
| 55 | + CACHE BOOL "Enable Cppcheck") |
| 56 | +set(USE_CPPCHECK_SUPPRESSION_FILE |
| 57 | + ${CMAKE_SOURCE_DIR}/.cppcheck-suppressions.txt |
| 58 | + CACHE STRING |
| 59 | + "Customize the path to the Cppcheck suppressions file of the project") |
| 60 | + |
| 61 | +# ############################################################################## |
| 62 | +# Hardening - cmake-modules/build/Hardening.cmake |
| 63 | +# ############################################################################## |
| 64 | + |
| 65 | +# Comment `-Wl,-z,nodlopen` for dlopen call |
| 66 | +if(NOT MSVC) |
| 67 | + set(USE_HARDENING_FLAGS |
| 68 | + -D_GLIBCXX_ASSERTIONS # Enable assertions |
| 69 | + -U_FORTIFY_SOURCE # Disable stack protector |
| 70 | + -D_FORTIFY_SOURCE=3 # Enable stack protector |
| 71 | + -fstack-protector-strong # Enable stack protector |
| 72 | + -fcf-protection # Control Flow Guard |
| 73 | + -fstack-clash-protection # Control Flow Guard |
| 74 | + -Wimplicit-fallthrough # Enabled in compiler flags by default |
| 75 | + -fstrict-flex-arrays=3 # Enable strict array bounds |
| 76 | + -Wformat # Enabled in compiler flags by default |
| 77 | + -Wformat=2 # Enabled in compiler flags by default |
| 78 | + # -Wl,-z,nodlopen # Restrict dlopen(3) calls to shared objects |
| 79 | + -Wl,-z,noexecstack # Enable data execution prevention by marking stack |
| 80 | + # memory as non-executable |
| 81 | + -Wl,-z,relro # Mark relocation table entries resolved at load-time as |
| 82 | + # read-only |
| 83 | + -Wl,-z,now # Mark relocation table entries resolved at load-time as |
| 84 | + # read-only. It impacts startup performance |
| 85 | + "-fsanitize=undefined -fsanitize-minimal-runtime" # Enable minimal runtime |
| 86 | + # undefined behavior sanitizer |
| 87 | + -fno-delete-null-pointer-checks |
| 88 | + -fno-strict-overflow |
| 89 | + -fno-strict-aliasing |
| 90 | + -ftrivial-auto-var-init=zero |
| 91 | + -Wtrampolines # Enable trampolines(gcc only) |
| 92 | + -mbranch-protection=standard # Enable indirect branches(aarch64 only) |
| 93 | + CACHE STRING "Additional hardening compilation flags for GCC/Clang") |
| 94 | + |
| 95 | + set(USE_HARDENING_LINKS |
| 96 | + -fstack-protector-strong # Enable stack protector |
| 97 | + "-fsanitize=undefined -fsanitize-minimal-runtime" |
| 98 | + # -Wl,-z,nodlopen # Restrict dlopen(3) calls to shared objects |
| 99 | + -Wl,-z,noexecstack # Enable data execution prevention by marking stack |
| 100 | + # memory as non-executable |
| 101 | + -Wl,-z,relro # Mark relocation table entries resolved at load-time as |
| 102 | + # read-only |
| 103 | + -Wl,-z,now # Mark relocation table entries resolved at load-time as |
| 104 | + # read-only. It impacts startup performance |
| 105 | + CACHE STRING "Additional hardening linking flags for GCC/Clang") |
| 106 | +endif() |
0 commit comments