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 7fa292605..e7a693b9c 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" 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/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; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2a6a1eedf..7713dc318 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") + target_compile_options(threepp PRIVATE + "-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") + 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