Skip to content

Commit b786c47

Browse files
authored
Add helper macros for warning suppression (#11)
1 parent 9f46d20 commit b786c47

4 files changed

Lines changed: 42 additions & 7 deletions

File tree

examples/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,3 @@ if(PLOTLYPP_BUILD_MODULES)
5555
endif()
5656

5757
set_target_warnings(example)
58-
target_compile_options(example PRIVATE
59-
$<$<OR:$<CXX_COMPILER_ID:Clang>,$<CXX_COMPILER_ID:AppleClang>>:
60-
# Clang complains with -Wpedantic. For external users we also have the PLOTLYPP_SYSTEM_INCLUDE CMake option
61-
# to treat all plotlypp headers as system headers.
62-
-Wno-overlength-strings
63-
>
64-
)

generator/parse.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,13 @@ def package_js() -> None:
869869

870870
writer = Writer(Path(__file__).parent.parent / "include" / "plotlypp" / "plotly_min_js.hpp")
871871
emit_preamble(writer)
872+
writer.write("#include <plotlypp/warnings.hpp>")
873+
writer.write("")
872874
writer.write("namespace plotlypp {")
873875
writer.write("")
876+
writer.write("PLOTLYPP_DISABLE_WARNING_PUSH")
877+
writer.write("PLOTLYPP_DISABLE_WARNING_OVERLENGTH_STRINGS")
878+
writer.write("")
874879
writer.write("// Note: constexpr string_view excessively bloats compile times due to length counts.")
875880
writer.write(
876881
"// 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:
900905
writer.write('"\\x1a"')
901906
writer.write(";")
902907
writer.write("")
908+
writer.write("PLOTLYPP_DISABLE_WARNING_POP")
909+
writer.write("")
903910
writer.write("} // namespace plotlypp")
904911
writer.close()
905912

include/plotlypp/plotly_min_js.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,13 @@
88

99
#pragma once
1010

11+
#include <plotlypp/warnings.hpp>
12+
1113
namespace plotlypp {
1214

15+
PLOTLYPP_DISABLE_WARNING_PUSH
16+
PLOTLYPP_DISABLE_WARNING_OVERLENGTH_STRINGS
17+
1318
// Note: constexpr string_view excessively bloats compile times due to length counts.
1419
// 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.
1520
inline constexpr const char* const plotlyJS =
@@ -5032,4 +5037,6 @@ return Plotly;
50325037
}));)d0"
50335038
;
50345039

5040+
PLOTLYPP_DISABLE_WARNING_POP
5041+
50355042
} // namespace plotlypp

include/plotlypp/warnings.hpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2025-2026 Jimmy O'Rourke
2+
// Licensed under and subject to the terms of the LICENSE file accompanying this distribution.
3+
// Official repository: https://github.com/jimmyorourke/plotlypp
4+
5+
#pragma once
6+
7+
#if defined(_MSC_VER)
8+
#define PLOTLYPP_DISABLE_WARNING_PUSH __pragma(warning(push))
9+
#define PLOTLYPP_DISABLE_WARNING_POP __pragma(warning(pop))
10+
#define PLOTLYPP_DISABLE_WARNING(warningNumber) __pragma(warning(disable : warningNumber))
11+
12+
// https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2026
13+
#define PLOTLYPP_DISABLE_WARNING_OVERLENGTH_STRINGS
14+
15+
#elif defined(__GNUC__) || defined(__clang__)
16+
#define PLOTLYPP_DO_PRAGMA(X) _Pragma(#X)
17+
#define PLOTLYPP_DISABLE_WARNING_PUSH PLOTLYPP_DO_PRAGMA(GCC diagnostic push)
18+
#define PLOTLYPP_DISABLE_WARNING_POP PLOTLYPP_DO_PRAGMA(GCC diagnostic pop)
19+
#define PLOTLYPP_DISABLE_WARNING(warningName) PLOTLYPP_DO_PRAGMA(GCC diagnostic ignored warningName)
20+
21+
#define PLOTLYPP_DISABLE_WARNING_OVERLENGTH_STRINGS PLOTLYPP_DISABLE_WARNING("-Woverlength-strings")
22+
23+
#else
24+
#define PLOTLYPP_DISABLE_WARNING_PUSH
25+
#define PLOTLYPP_DISABLE_WARNING_POP
26+
27+
#define PLOTLYPP_DISABLE_WARNING_OVERLENGTH_STRINGS
28+
#endif

0 commit comments

Comments
 (0)