Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to build with warnings as errors #271

Merged
merged 4 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion include/threepp/materials/Material.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace threepp {
copyInto(*clone);

return std::dynamic_pointer_cast<T>(clone);
};
}

~Material() override;

Expand Down
17 changes: 16 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 ()
18 changes: 18 additions & 0 deletions src/threepp/audio/Audio.cpp
Original file line number Diff line number Diff line change
@@ -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 <stdexcept>


Expand Down
12 changes: 12 additions & 0 deletions src/threepp/loaders/ImageLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/threepp/renderers/GLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(_info.render.frame)) {

skinned->skeleton->update();
skinned->skeleton->frame = _info.render.frame;
Expand Down Expand Up @@ -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<int>(clipping.numPlanes) ||
materialProperties->numIntersection != static_cast<int>(clipping.numIntersection))) {

needsProgramChange = true;

Expand Down
4 changes: 2 additions & 2 deletions src/threepp/renderers/gl/GLMorphTargets.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ namespace threepp::gl {

// Collect influences

for (int i = 0; i < length; i++) {
for (unsigned i = 0; i < length; i++) {

auto& influence = influences.at(i);

influence.first = i;
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++) {

Expand Down
18 changes: 9 additions & 9 deletions src/threepp/renderers/gl/GLTextures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
26 changes: 13 additions & 13 deletions src/threepp/utils/RegexUtil.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ namespace {
return regex_replace(s.cbegin(), s.cend(), re, f);
}

std::vector<std::string> regexSplit(const std::string& input, const std::regex& r) {

std::vector<std::string> 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<std::string> regexSplit(const std::string& input, const std::regex& r) {
//
// std::vector<std::string> 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

Expand Down
Loading