From a85084e63b65452ee5a7b0f2cae67de8f2971b17 Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Mon, 1 Jul 2024 12:35:54 +0200 Subject: [PATCH 1/4] compile with warnings as errors --- CMakeLists.txt | 1 + src/CMakeLists.txt | 17 +++++++++++++- src/threepp/audio/Audio.cpp | 18 ++++++++++++++ src/threepp/loaders/ImageLoader.cpp | 12 ++++++++++ src/threepp/renderers/GLRenderer.cpp | 6 ++--- src/threepp/renderers/gl/GLMorphTargets.hpp | 4 ++-- src/threepp/renderers/gl/GLTextures.cpp | 18 +++++++------- src/threepp/utils/RegexUtil.hpp | 26 ++++++++++----------- 8 files changed, 74 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7fa292605..7a1ce0f04 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,6 +9,7 @@ option(THREEPP_BUILD_EXAMPLES "Build examples" ON) option(THREEPP_BUILD_TESTS "Build test suite" ON) option(THREEPP_WITH_SVG "Build with SVGLoader" ON) option(THREEPP_WITH_AUDIO "Build with Audio" ON) +option(THREEPP_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" ON) # Force THREEPP_WITH_GLFW ON when targeting Emscripten cmake_dependent_option(THREEPP_WITH_GLFW "Build with GLFW frontend" ON "NOT DEFINED EMSCRIPTEN" ON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a6a1eedf..1fa670c9d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -464,7 +464,7 @@ if (THREEPP_WITH_GLFW) set(GLFW_BUILD_WAYLAND OFF CACHE BOOL "" FORCE) if (THREEPP_EMBEDDED_GLFW_WITH_X11) set(GLFW_BUILD_X11 ON CACHE BOOL "" FORCE) - else() + else () set(GLFW_BUILD_X11 OFF CACHE BOOL "" FORCE) endif () set(GLFW_LIBRARY_TYPE "OBJECT" CACHE STRING "" FORCE) @@ -532,3 +532,18 @@ if (NOT DEFINED EMSCRIPTEN) endif () endif () + + +if (THREEPP_TREAT_WARNINGS_AS_ERRORS) + # Treat warnings as errors, + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") + target_compile_options(threepp PRIVATE "-Wall" "-Wextra" "-Wpedantic") + target_compile_options(threepp PRIVATE + "-Wno-parentheses" "-Wno-reorder-ctor" + "-Wno-missing-field-initializers" "-Wno-overloaded-virtual" + "-Wno-unused-parameter" "-Wno-dollar-in-identifier-extension") + target_compile_options(threepp PRIVATE "-Werror") + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + target_compile_options(threepp PRIVATE "/WX") + endif () +endif () diff --git a/src/threepp/audio/Audio.cpp b/src/threepp/audio/Audio.cpp index f9f87b255..b54c68997 100644 --- a/src/threepp/audio/Audio.cpp +++ b/src/threepp/audio/Audio.cpp @@ -1,9 +1,27 @@ #include "threepp/audio/Audio.hpp" + +#ifndef STB_IMAGE_IMPLEMENTATION + +#if defined(__GNUC__) || defined(__clang__) +// Temporarily disable specific warnings +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wall" // Disables all warnings +#pragma GCC diagnostic ignored "-Wextra" // Disables extra warnings +#pragma GCC diagnostic ignored "-Wpedantic" // Disables pedantic warnings +#endif + #define MINIAUDIO_IMPLEMENTATION #include "miniaudio.h" +#if defined(__GNUC__) || defined(__clang__) +// Re-enable the warnings +#pragma GCC diagnostic pop +#endif + +#endif + #include diff --git a/src/threepp/loaders/ImageLoader.cpp b/src/threepp/loaders/ImageLoader.cpp index db72c1a97..6be5f917e 100644 --- a/src/threepp/loaders/ImageLoader.cpp +++ b/src/threepp/loaders/ImageLoader.cpp @@ -2,10 +2,22 @@ #include "threepp/loaders/ImageLoader.hpp" #ifndef STB_IMAGE_IMPLEMENTATION +#if defined(__GNUC__) || defined(__clang__) +// Temporarily disable specific warnings +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wall" // Disables all warnings +#pragma GCC diagnostic ignored "-Wextra" // Disables extra warnings +#pragma GCC diagnostic ignored "-Wpedantic" // Disables pedantic warnings +#endif #define STB_IMAGE_IMPLEMENTATION #endif #include "stb_image.h" +#if defined(__GNUC__) || defined(__clang__) +// Re-enable the warnings +#pragma GCC diagnostic pop +#endif + using namespace threepp; namespace { diff --git a/src/threepp/renderers/GLRenderer.cpp b/src/threepp/renderers/GLRenderer.cpp index 08ec87aaa..964d7fd80 100644 --- a/src/threepp/renderers/GLRenderer.cpp +++ b/src/threepp/renderers/GLRenderer.cpp @@ -494,7 +494,7 @@ struct GLRenderer::Impl { // update skeleton only once in a frame - if (skinned->skeleton->frame != _info.render.frame) { + if (skinned->skeleton->frame != static_cast(_info.render.frame)) { skinned->skeleton->update(); skinned->skeleton->frame = _info.render.frame; @@ -788,8 +788,8 @@ struct GLRenderer::Impl { needsProgramChange = true; } else if (materialProperties->numClippingPlanes && - (materialProperties->numClippingPlanes.value() != clipping.numPlanes || - materialProperties->numIntersection != clipping.numIntersection)) { + (materialProperties->numClippingPlanes.value() != static_cast(clipping.numPlanes) || + materialProperties->numIntersection != static_cast(clipping.numIntersection))) { needsProgramChange = true; diff --git a/src/threepp/renderers/gl/GLMorphTargets.hpp b/src/threepp/renderers/gl/GLMorphTargets.hpp index 9414f88fc..b30ee1a42 100644 --- a/src/threepp/renderers/gl/GLMorphTargets.hpp +++ b/src/threepp/renderers/gl/GLMorphTargets.hpp @@ -75,7 +75,7 @@ namespace threepp::gl { // Collect influences - for (int i = 0; i < length; i++) { + for (unsigned i = 0; i < length; i++) { auto& influence = influences.at(i); @@ -83,7 +83,7 @@ namespace threepp::gl { influence.second = objectInfluences[i]; } - std::stable_sort(influences.begin(), influences.end(), absNumericalSort); + std::ranges::stable_sort(influences, absNumericalSort); for (unsigned i = 0; i < 8; i++) { diff --git a/src/threepp/renderers/gl/GLTextures.cpp b/src/threepp/renderers/gl/GLTextures.cpp index 9de033894..3f5739644 100644 --- a/src/threepp/renderers/gl/GLTextures.cpp +++ b/src/threepp/renderers/gl/GLTextures.cpp @@ -39,15 +39,15 @@ namespace { texture.minFilter != Filter::Nearest && texture.minFilter != Filter::Linear; } - GLuint filterFallback(Filter f) { - - if (f == Filter::Nearest || f == Filter::NearestMipmapNearest || f == Filter::NearestMipmapLinear) { - - return GL_NEAREST; - } - - return GL_LINEAR; - } + // GLuint filterFallback(Filter f) { + // + // if (f == Filter::Nearest || f == Filter::NearestMipmapNearest || f == Filter::NearestMipmapLinear) { + // + // return GL_NEAREST; + // } + // + // return GL_LINEAR; + // } GLint getInternalFormat(GLuint glFormat, GLuint glType) { diff --git a/src/threepp/utils/RegexUtil.hpp b/src/threepp/utils/RegexUtil.hpp index 8d404aab0..c4665683f 100644 --- a/src/threepp/utils/RegexUtil.hpp +++ b/src/threepp/utils/RegexUtil.hpp @@ -49,19 +49,19 @@ namespace { return regex_replace(s.cbegin(), s.cend(), re, f); } - std::vector regexSplit(const std::string& input, const std::regex& r) { - - std::vector result; - - std::sregex_token_iterator iter(input.begin(), input.end(), r, -1); - std::sregex_token_iterator end; - - for (; iter != end; ++iter) { - result.emplace_back(*iter); - } - - return result; - } + // std::vector regexSplit(const std::string& input, const std::regex& r) { + // + // std::vector result; + // + // std::sregex_token_iterator iter(input.begin(), input.end(), r, -1); + // std::sregex_token_iterator end; + // + // for (; iter != end; ++iter) { + // result.emplace_back(*iter); + // } + // + // return result; + // } }// namespace From 611edaee94de0ce93771a17f96587deb0701b29e Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Mon, 1 Jul 2024 12:40:19 +0200 Subject: [PATCH 2/4] fix warning --- include/threepp/materials/Material.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/threepp/materials/Material.hpp b/include/threepp/materials/Material.hpp index c05643660..f708ff266 100644 --- a/include/threepp/materials/Material.hpp +++ b/include/threepp/materials/Material.hpp @@ -115,7 +115,7 @@ namespace threepp { copyInto(*clone); return std::dynamic_pointer_cast(clone); - }; + } ~Material() override; From dd57aea84427a5d5ea47231e80c600a3d3509928 Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Mon, 1 Jul 2024 12:45:05 +0200 Subject: [PATCH 3/4] supress warning --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1fa670c9d..4a9d714b3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -539,7 +539,7 @@ if (THREEPP_TREAT_WARNINGS_AS_ERRORS) if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") target_compile_options(threepp PRIVATE "-Wall" "-Wextra" "-Wpedantic") target_compile_options(threepp PRIVATE - "-Wno-parentheses" "-Wno-reorder-ctor" + "-Wno-parentheses" "-Wno-reorder" "-Wno-reorder-ctor" "-Wno-missing-field-initializers" "-Wno-overloaded-virtual" "-Wno-unused-parameter" "-Wno-dollar-in-identifier-extension") target_compile_options(threepp PRIVATE "-Werror") From 921ebed03a049e229f28d34371aeec9d5b02a8fe Mon Sep 17 00:00:00 2001 From: Lars Ivar Hatledal Date: Mon, 1 Jul 2024 13:34:12 +0200 Subject: [PATCH 4/4] update --- .github/workflows/config.yml | 2 +- CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index ee61933b9..3e51e0a03 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -131,7 +131,7 @@ jobs: - name: Configure and build run: | - cmake . -A x64 -B build -DCMAKE_BUILD_TYPE="Release" + cmake . -A x64 -B build -DTHREEPP_TREAT_WARNINGS_AS_ERRORS=ON -DCMAKE_BUILD_TYPE="Release" cmake --build build --config Release - name: Test diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a1ce0f04..e7a693b9c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,7 @@ option(THREEPP_BUILD_EXAMPLES "Build examples" ON) option(THREEPP_BUILD_TESTS "Build test suite" ON) option(THREEPP_WITH_SVG "Build with SVGLoader" ON) option(THREEPP_WITH_AUDIO "Build with Audio" ON) -option(THREEPP_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" ON) +option(THREEPP_TREAT_WARNINGS_AS_ERRORS "Treat warnings as errors" OFF) # Force THREEPP_WITH_GLFW ON when targeting Emscripten cmake_dependent_option(THREEPP_WITH_GLFW "Build with GLFW frontend" ON "NOT DEFINED EMSCRIPTEN" ON) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4a9d714b3..7713dc318 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -537,7 +537,7 @@ endif () if (THREEPP_TREAT_WARNINGS_AS_ERRORS) # Treat warnings as errors, if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang") - target_compile_options(threepp PRIVATE "-Wall" "-Wextra" "-Wpedantic") + target_compile_options(threepp PRIVATE "-Wall" "-Wextra") target_compile_options(threepp PRIVATE "-Wno-parentheses" "-Wno-reorder" "-Wno-reorder-ctor" "-Wno-missing-field-initializers" "-Wno-overloaded-virtual"