From 108d5061d4f64de0a2988cf338b1c23596f609cd Mon Sep 17 00:00:00 2001 From: Malkierian Date: Mon, 28 Oct 2024 17:30:11 -0700 Subject: [PATCH] Small Warnings Refactor (#4477) * Disable all warnings, even in release, on the `src` directory. Resolve math macro duplication warnings. * Suppress LUS warnings. * Modify it to utilize a variable that defaults on but can be specified in command line to disable it. Prevet total compile option overwrite for LUS. * Remove unnecessary unset and cache parameters. * Document warnings flag in BUILDING.md --- CMakeLists.txt | 13 +++++++++++++ docs/BUILDING.md | 3 +++ soh/CMakeLists.txt | 1 + soh/include/libc/math.h | 6 ++++++ soh/include/macros.h | 4 ++++ 5 files changed, 27 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 606abeba7..2bdaf1de9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,18 @@ project(Ship VERSION 8.0.6 LANGUAGES C CXX) include(CMake/soh-cvars.cmake) include(CMake/lus-cvars.cmake) +option(SUPPRESS_WARNINGS "Suppress warnings in LUS and src (decomp)" ON) +if(SUPPRESS_WARNINGS) + MESSAGE("Suppressing warnings in LUS and src") + if(MSVC) + set(WARNING_OVERRIDE /w) + else() + set(WARNING_OVERRIDE -w) + endif() +else() + MESSAGE("Skipping warning suppression") +endif() + set(NATO_PHONETIC_ALPHABET "Alfa" "Bravo" "Charlie" "Delta" "Echo" "Foxtrot" "Golf" "Hotel" "India" "Juliett" "Kilo" "Lima" "Mike" "November" "Oscar" "Papa" @@ -148,6 +160,7 @@ add_compile_definitions(CONTROLLERBUTTONS_T=uint32_t) # Sub-projects ################################################################################ add_subdirectory(libultraship ${CMAKE_BINARY_DIR}/libultraship) +target_compile_options(libultraship PRIVATE "${WARNING_OVERRIDE}") add_subdirectory(ZAPDTR/ZAPD ${CMAKE_BINARY_DIR}/ZAPD) add_subdirectory(OTRExporter) add_subdirectory(soh) diff --git a/docs/BUILDING.md b/docs/BUILDING.md index a95dbc31e..74ab53378 100644 --- a/docs/BUILDING.md +++ b/docs/BUILDING.md @@ -31,6 +31,7 @@ cd Shipwright # Setup cmake project # Add `-DCMAKE_BUILD_TYPE:STRING=Release` if you're packaging +# Add `-DSUPPRESS_WARNINGS=0` to prevent suppression of warnings from LUS and decomp (src) files. set to 1 to re-enable suppression & 'C:\Program Files\CMake\bin\cmake' -S . -B "build/x64" -G "Visual Studio 17 2022" -T v143 -A x64 # Generate soh.otr @@ -133,6 +134,7 @@ git submodule update --init # Generate Ninja project # Add `-DCMAKE_BUILD_TYPE:STRING=Release` if you're packaging +# Add `-DSUPPRESS_WARNINGS=0` to prevent suppression of warnings from LUS and decomp (src) files. set to 1 to re-enable suppression # Add `-DPython3_EXECUTABLE=$(which python3)` if you are using non-standard Python installations such as PyEnv cmake -H. -Bbuild-cmake -GNinja @@ -187,6 +189,7 @@ git submodule update --init # Generate Ninja project # Add `-DCMAKE_BUILD_TYPE:STRING=Release` if you're packaging +# Add `-DSUPPRESS_WARNINGS=0` to prevent suppression of warnings from LUS and decomp (src) files. set to 1 to re-enable suppression cmake -H. -Bbuild-cmake -GNinja # Generate soh.otr diff --git a/soh/CMakeLists.txt b/soh/CMakeLists.txt index 784f3cc81..935f32ea1 100644 --- a/soh/CMakeLists.txt +++ b/soh/CMakeLists.txt @@ -173,6 +173,7 @@ endif() # src (decomp) {{{ file(GLOB_RECURSE src__ RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "src/*.c" "src/*.h") +set_source_files_properties(${src__} PROPERTIES COMPILE_OPTIONS "${WARNING_OVERRIDE}") list(APPEND src__ ${CMAKE_CURRENT_SOURCE_DIR}/Resource.rc) list(FILTER src__ EXCLUDE REGEX "src/dmadata/*") diff --git a/soh/include/libc/math.h b/soh/include/libc/math.h index cad323823..473ef112b 100644 --- a/soh/include/libc/math.h +++ b/soh/include/libc/math.h @@ -3,9 +3,15 @@ #include +#ifndef M_PI #define M_PI 3.14159265358979323846f +#endif +#ifndef M_SQRT2 #define M_SQRT2 1.41421356237309504880f +#endif +#ifndef FLT_MAX #define FLT_MAX 340282346638528859811704183484516925440.0f +#endif #define SHT_MAX 32767.0f #define SHT_MINV (1.0f / SHT_MAX) #define DEGTORAD(x) (x * M_PI / 180.0f) diff --git a/soh/include/macros.h b/soh/include/macros.h index e5c03ceca..9c7c43d80 100644 --- a/soh/include/macros.h +++ b/soh/include/macros.h @@ -32,8 +32,12 @@ //#define SEGMENTED_TO_VIRTUAL(addr) PHYSICAL_TO_VIRTUAL(gSegments[SEGMENT_NUMBER(addr)] + SEGMENT_OFFSET(addr)) #define SEGMENTED_TO_VIRTUAL(addr) addr +#ifndef SQ #define SQ(x) ((x)*(x)) +#endif +#ifndef ABS #define ABS(x) ((x) >= 0 ? (x) : -(x)) +#endif #define DECR(x) ((x) == 0 ? 0 : --(x)) #define CLAMP(x, min, max) ((x) < (min) ? (min) : (x) > (max) ? (max) : (x)) #define CLAMP_MAX(x, max) ((x) > (max) ? (max) : (x))