From 5a98c857b6c8ce8d10bde531094d1383bcc7daae Mon Sep 17 00:00:00 2001 From: Jimmy O'Rourke Date: Thu, 5 Feb 2026 15:58:10 -0800 Subject: [PATCH] Add helper macros for warning suppression --- examples/CMakeLists.txt | 7 ------- generator/parse.py | 7 +++++++ include/plotlypp/plotly_min_js.hpp | 7 +++++++ include/plotlypp/warnings.hpp | 28 ++++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 7 deletions(-) create mode 100644 include/plotlypp/warnings.hpp diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c971796..4cbecb4 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -55,10 +55,3 @@ if(PLOTLYPP_BUILD_MODULES) endif() set_target_warnings(example) -target_compile_options(example PRIVATE - $<$,$>: - # Clang complains with -Wpedantic. For external users we also have the PLOTLYPP_SYSTEM_INCLUDE CMake option - # to treat all plotlypp headers as system headers. - -Wno-overlength-strings - > -) diff --git a/generator/parse.py b/generator/parse.py index 160fe16..25e805d 100644 --- a/generator/parse.py +++ b/generator/parse.py @@ -869,8 +869,13 @@ def package_js() -> None: writer = Writer(Path(__file__).parent.parent / "include" / "plotlypp" / "plotly_min_js.hpp") emit_preamble(writer) + writer.write("#include ") + writer.write("") writer.write("namespace plotlypp {") writer.write("") + writer.write("PLOTLYPP_DISABLE_WARNING_PUSH") + writer.write("PLOTLYPP_DISABLE_WARNING_OVERLENGTH_STRINGS") + writer.write("") writer.write("// Note: constexpr string_view excessively bloats compile times due to length counts.") writer.write( "// Note: Plotly JS is chunked into multiple raw string literals to support MSVC limits, and 0x1a characters are escaped to avoid MSVC trating them as EOF." @@ -900,6 +905,8 @@ def find_safe_delimiter(chunk: str) -> str: writer.write('"\\x1a"') writer.write(";") writer.write("") + writer.write("PLOTLYPP_DISABLE_WARNING_POP") + writer.write("") writer.write("} // namespace plotlypp") writer.close() diff --git a/include/plotlypp/plotly_min_js.hpp b/include/plotlypp/plotly_min_js.hpp index df917c2..db55a83 100644 --- a/include/plotlypp/plotly_min_js.hpp +++ b/include/plotlypp/plotly_min_js.hpp @@ -8,8 +8,13 @@ #pragma once +#include + namespace plotlypp { +PLOTLYPP_DISABLE_WARNING_PUSH +PLOTLYPP_DISABLE_WARNING_OVERLENGTH_STRINGS + // Note: constexpr string_view excessively bloats compile times due to length counts. // Note: Plotly JS is chunked into multiple raw string literals to support MSVC limits, and 0x1a characters are escaped to avoid MSVC trating them as EOF. inline constexpr const char* const plotlyJS = @@ -5032,4 +5037,6 @@ return Plotly; }));)d0" ; +PLOTLYPP_DISABLE_WARNING_POP + } // namespace plotlypp diff --git a/include/plotlypp/warnings.hpp b/include/plotlypp/warnings.hpp new file mode 100644 index 0000000..809323c --- /dev/null +++ b/include/plotlypp/warnings.hpp @@ -0,0 +1,28 @@ +// Copyright (c) 2025-2026 Jimmy O'Rourke +// Licensed under and subject to the terms of the LICENSE file accompanying this distribution. +// Official repository: https://github.com/jimmyorourke/plotlypp + +#pragma once + +#if defined(_MSC_VER) +#define PLOTLYPP_DISABLE_WARNING_PUSH __pragma(warning(push)) +#define PLOTLYPP_DISABLE_WARNING_POP __pragma(warning(pop)) +#define PLOTLYPP_DISABLE_WARNING(warningNumber) __pragma(warning(disable : warningNumber)) + +// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2026 +#define PLOTLYPP_DISABLE_WARNING_OVERLENGTH_STRINGS + +#elif defined(__GNUC__) || defined(__clang__) +#define PLOTLYPP_DO_PRAGMA(X) _Pragma(#X) +#define PLOTLYPP_DISABLE_WARNING_PUSH PLOTLYPP_DO_PRAGMA(GCC diagnostic push) +#define PLOTLYPP_DISABLE_WARNING_POP PLOTLYPP_DO_PRAGMA(GCC diagnostic pop) +#define PLOTLYPP_DISABLE_WARNING(warningName) PLOTLYPP_DO_PRAGMA(GCC diagnostic ignored warningName) + +#define PLOTLYPP_DISABLE_WARNING_OVERLENGTH_STRINGS PLOTLYPP_DISABLE_WARNING("-Woverlength-strings") + +#else +#define PLOTLYPP_DISABLE_WARNING_PUSH +#define PLOTLYPP_DISABLE_WARNING_POP + +#define PLOTLYPP_DISABLE_WARNING_OVERLENGTH_STRINGS +#endif