From 7aa2a67d8381c9a88d69a3f53d74a7f079214263 Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Mon, 9 Mar 2026 21:49:43 +0800 Subject: Establish a well-structured modern C++ project architecture Focus on code quality: Treat strict warnings as errors, memory checks with Sanitizers, Clang formatting and static analysis Performance optimization: LTO, ccache --- etc/cflags.cmake | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 etc/cflags.cmake (limited to 'etc/cflags.cmake') diff --git a/etc/cflags.cmake b/etc/cflags.cmake new file mode 100644 index 0000000..ac08601 --- /dev/null +++ b/etc/cflags.cmake @@ -0,0 +1,16 @@ +set (CMAKE_CXX_STANDARD 23) +set (CMAKE_EXPORT_COMPILE_COMMANDS ON) + +set(SANITIZING_FLAGS -fno-sanitize-recover=all -fsanitize=undefined -fsanitize=address) + +# ask for more warnings from the compiler +set (CMAKE_BASE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") +set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wpedantic -Wextra -Weffc++ -Werror -Wshadow -Wpointer-arith -Wcast-qual -Wformat=2 -Wno-unqualified-std-cast-call -Wno-non-virtual-dtor") + +# Sanitizers +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + message(STATUS "Enabling Address and Undefined Behavior Sanitizers") + set(SANITIZING_FLAGS "-fno-sanitize-recover=all -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer") + set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${SANITIZING_FLAGS} -g -O0") + set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} ${SANITIZING_FLAGS}") +endif() \ No newline at end of file -- cgit v1.2.3