diff --git a/CMakeLists.txt b/CMakeLists.txt index aac038881..22205ae73 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -84,6 +84,7 @@ option(SRB2_CONFIG_ZDEBUG "Compile with ZDEBUG defined." OFF) option(SRB2_CONFIG_PROFILEMODE "Compile for profiling (GCC only)." OFF) option(SRB2_CONFIG_TRACY "Compile with Tracy profiling enabled" OFF) option(SRB2_CONFIG_ASAN "Compile with AddressSanitizer (libasan)." OFF) +option(SRB2_CONFIG_UBSAN "Compile with UndefinedBehaviorSanitizer (libubsan)." OFF) set(SRB2_CONFIG_ASSET_DIRECTORY "" CACHE PATH "Path to directory that contains all asset files for the installer. If set, assets will be part of installation and cpack.") option(SRB2_CONFIG_LTO "Enable link time optimizations, improves performance at the cost of longer link times." ON) option(SRB2_CONFIG_TIDY "Enable clang tiny, checks compiled code for issues at the cost of longer compile times." OFF) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 03cc0cb96..fb297a369 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -64,6 +64,11 @@ if(SRB2_CONFIG_ASAN) target_link_options(SRB2SDL2 PRIVATE -fsanitize=address) endif() +if(SRB2_CONFIG_UBSAN) + target_compile_options(SRB2SDL2 PRIVATE -fsanitize=undefined) + target_link_options(SRB2SDL2 PRIVATE -fsanitize=undefined) +endif() + if(SRB2_CONFIG_TIDY) set(CMAKE_CXX_CLANG_TIDY "clang-tidy;-checks=*") endif() @@ -220,7 +225,7 @@ endif() target_compile_options(SRB2SDL2 PRIVATE -fwrapv) if (${CMAKE_BUILD_TYPE} MATCHES Debug) - + target_compile_options(SRB2SDL2 PRIVATE -O0) else() target_compile_options(SRB2SDL2 PRIVATE -O3) endif() @@ -233,6 +238,7 @@ target_compile_options(SRB2SDL2 PRIVATE # This is a direct translation from versions.mk $<$,$>: -Wall + -Wextra -Wno-trigraphs -W # Was controlled by RELAXWARNINGS -Wfloat-equal @@ -314,6 +320,7 @@ target_compile_options(SRB2SDL2 PRIVATE # C, Clang and Apple Clang $<$,$,$>>: -Wall + -Wextra -Wno-absolute-value -Wno-trigraphs -Wno-error=non-literal-null-conversion @@ -322,13 +329,6 @@ target_compile_options(SRB2SDL2 PRIVATE -Wno-error=unused-but-set-variable > - # C, MSVC - $<$,$>: - # All warnings at and before Visual Studio 2019 RTM - # https://learn.microsoft.com/en-us/cpp/error-messages/compiler-warnings/compiler-warnings-by-compiler-version?view=msvc-170 - /Wv:19.20.27004.0 - > - # C++, GNU, Clang and Apple Clang $<$,$,$,$>>: -Wall @@ -337,11 +337,6 @@ target_compile_options(SRB2SDL2 PRIVATE -Wno-unused-private-field > - # C++, MSVC - $<$,$>: - /Wv:19.20.27004.0 - > - # GNU $<$: -fmax-errors=5 @@ -352,10 +347,6 @@ if(SRB2_CONFIG_ERRORMODE) $<$,$,$>: -Werror > - - $<$: - /WX - > ) endif() @@ -373,7 +364,7 @@ target_compile_definitions(SRB2SDL2 PRIVATE -DCMAKECONFIG) # Misc. build options from Makefiles if(SRB2_CONFIG_DEBUGMODE) - target_compile_definitions(SRB2SDL2 PRIVATE -DZDEBUG -DPARANOIA -DRANGECHECK -DPACKETDROP) + target_compile_definitions(SRB2SDL2 PRIVATE -D_DEBUG -DZDEBUG -DPARANOIA -DRANGECHECK -DPACKETDROP) endif() if(SRB2_CONFIG_MOBJCONSISTANCY) target_compile_definitions(SRB2SDL2 PRIVATE -DMOBJCONSISTANCY)