Skip to content

Commit

Permalink
fix: enable customizable options (#91)
Browse files Browse the repository at this point in the history
Signed-off-by: msclock <msclock@qq.com>
  • Loading branch information
msclock committed Apr 5, 2024
1 parent 75cab72 commit 4ca35ec
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
6 changes: 3 additions & 3 deletions cmake/build/CompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ set(COMPILER_FLAGS_WARNINGS_MSVC
/w14928 # illegal copy-initialization; more than one user-defined conversion
# has been implicitly applied
/permissive- # standards conformance mode for MSVC compiler.
)
CACHE STRING "Compiler warnings flags for MSVC")

set(COMPILER_FLAGS_WARNINGS_GNU
-Wall # all warnings on
Expand Down Expand Up @@ -74,7 +74,7 @@ set(COMPILER_FLAGS_WARNINGS_GNU
-Wuseless-cast # warn if you perform a cast to the same type
-Wsuggest-override # warn if an overridden member function is not marked
# 'override' or 'final'
)
CACHE STRING "Compiler warnings flags for GNU")

set(COMPILER_FLAGS_WARNINGS_CUDA
-Wall # Wall all warnings
Expand All @@ -83,7 +83,7 @@ set(COMPILER_FLAGS_WARNINGS_CUDA
-Wconversion # Warn on type conversions that may lose data"
-Wshadow # Warn the user if a variable declaration shadows one from a parent
# context
)
CACHE STRING "Compiler warnings flags for CUDA")

if(CMAKE_VERSION VERSION_LESS 3.24)
option(CMAKE_COMPILE_WARNING_AS_ERROR "Treat Warnings As Errors" OFF)
Expand Down
3 changes: 2 additions & 1 deletion cmake/build/Cppcheck.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ set(USE_CPPCHECK_OPTIONS
# ignores code that cppcheck thinks is invalid C++
--suppress=syntaxError
--suppress=preprocessorErrorDirective
--inconclusive)
--inconclusive
CACHE STRING "cppcheck run options")

set(USE_CPPCHECK_SUPPRESS_DIR
"*:${CMAKE_CURRENT_BINARY_DIR}/_deps/*.h"
Expand Down
8 changes: 4 additions & 4 deletions cmake/build/Hardening.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ if(MSVC)
/NXCOMPAT # Data Execution Prevention
/DYNAMICBASE # Image Randomization
/CETCOMPAT # Enhanced Mitigation Experience Toolkit (EMET)
)
CACHE STRING "Additional hardening compilation flags for MSVC")

set(USE_HARDENING_LINKS
/NXCOMPAT # Data Execution Prevention
/CETCOMPAT # Enhanced Mitigation Experience Toolkit (EMET)
)
CACHE STRING "Additional hardening linking flags for MSVC")
else()
set(USE_HARDENING_FLAGS
-D_GLIBCXX_ASSERTIONS # Enable assertions
Expand Down Expand Up @@ -63,7 +63,7 @@ else()
-ftrivial-auto-var-init=zero
-Wtrampolines # Enable trampolines(gcc only)
-mbranch-protection=standard # Enable indirect branches(aarch64 only)
)
CACHE STRING "Additional hardening compilation flags for GCC/Clang")

set(USE_HARDENING_LINKS
-fstack-protector-strong # Enable stack protector
Expand All @@ -77,7 +77,7 @@ else()
# read-only
-Wl,-z,now # Mark relocation table entries resolved at load-time as
# read-only. It impacts startup performance
)
CACHE STRING "Additional hardening linking flags for GCC/Clang")
endif()

message(
Expand Down
18 changes: 12 additions & 6 deletions cmake/build/Sanitizer.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ set(USE_SANITIZER_ASAN_FLAGS
# MSVC
"/fsanitize=address /Zi"
# Clang 3.2+ use this version. The no-omit-frame-pointer option is optional.
"-g -fsanitize=address -fno-omit-frame-pointer" "-g -fsanitize=address")
"-g -fsanitize=address -fno-omit-frame-pointer" "-g -fsanitize=address"
CACHE STRING "Compile with Address sanitizer flags.")

set(USE_SANITIZER_MSAN_FLAGS
# MSVC
Expand All @@ -35,19 +36,24 @@ set(USE_SANITIZER_MSAN_FLAGS
"-g -fsanitize=memory -fno-omit-frame-pointer -fsanitize-memory-track-origins"
# Optional: -fno-optimize-sibling-calls -fsanitize-memory-track-origins=2
"-g -fsanitize=memory -fno-omit-frame-pointer"
"-g -fsanitize=memory")
"-g -fsanitize=memory"
CACHE STRING "Compile with Memory sanitizer flags.")

set(USE_SANITIZER_USAN_FLAGS # GNU/Clang
"-g -fsanitize=undefined")
"-g -fsanitize=undefined"
CACHE STRING "Compile with Undefined Behaviour sanitizer flags.")

set(USE_SANITIZER_TSAN_FLAGS # GNU/Clang
"-g -fsanitize=thread")
"-g -fsanitize=thread"
CACHE STRING "Compile with Thread sanitizer flags.")

set(USE_SANITIZER_LSAN_FLAGS # GNU/Clang
"-g -fsanitize=leak")
"-g -fsanitize=leak"
CACHE STRING "Compile with Leak sanitizer flags.")

set(USE_SANITIZER_CFI_FLAGS # GNU/Clang
"-g -fsanitize=cfi")
"-g -fsanitize=cfi"
CACHE STRING "Compile with Control Flow Integrity(CFI) sanitizer flags.")

set(USE_SANITIZER
"Address,Undefined"
Expand Down
8 changes: 6 additions & 2 deletions cmake/test/Coverage.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,17 @@ message(
- lcov: preferred for gcc compilers.
- opencppcoverage: preferred for msvc compilers.
- gcovr: preferred for non-msvc compilers.
OFF - Disables code coverage.")
OFF - Disables code coverage.
CODE_COVERAGE_GCOVR_REPORT_FORMAT: Sets the gcovr report format. Default is lcov."
)

if(NOT CODE_COVERAGE)
message(STATUS "Code coverage disabled by CODE_COVERAGE evaluates to false.")
endif()

set(CODE_COVERAGE_GCOVR_REPORT_FORMAT "lcov")
set(CODE_COVERAGE_GCOVR_REPORT_FORMAT
"lcov"
CACHE STRING "Sets the gcovr report format.")

# Programs to generate coverage tools
find_program(LLVM_COV_PATH llvm-cov)
Expand Down

0 comments on commit 4ca35ec

Please sign in to comment.