From 566076e3d80e4e6b4f99db926d4453247f428a28 Mon Sep 17 00:00:00 2001 From: Ben Morse Date: Thu, 10 May 2018 17:46:11 -0700 Subject: [PATCH] add WARNINGS_AS_ERRORS cmake option (#176) --- README.md | 1 + build.py | 2 ++ src/CMakeLists.txt | 9 ++++++++- 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c025927..011c961 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ There are some CMake options you might care about: | `ENABLE_IO_THREAD` | `ON` | When enabled, we start up a thread to do io processing, if disabled you should call `Discord_UpdateConnection` yourself. | `USE_STATIC_CRT` | `OFF` | (Windows) Enable to statically link the CRT, avoiding requiring users install the redistributable package. (The prebuilt binaries enable this option) | [`BUILD_SHARED_LIBS`](https://cmake.org/cmake/help/v3.7/variable/BUILD_SHARED_LIBS.html) | `OFF` | Build library as a DLL +| `WARNINGS_AS_ERRORS` | `OFF` | When enabled, compiles with `-Werror` (on *nix platforms). | ## Continuous Builds diff --git a/build.py b/build.py index f8a2d32..25f3654 100755 --- a/build.py +++ b/build.py @@ -286,6 +286,8 @@ def libs(clean, static, shared, skip_formatter, just_release): if IS_BUILD_MACHINE: just_release = True + static_options['WARNINGS_AS_ERRORS'] = True + dynamic_options['WARNINGS_AS_ERRORS'] = True if PLATFORM == 'win': generator32 = 'Visual Studio 14 2015' diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 51e321d..f9ec250 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -2,6 +2,7 @@ include_directories(${PROJECT_SOURCE_DIR}/include) option(ENABLE_IO_THREAD "Start up a separate I/O thread, otherwise I'd need to call an update function" ON) option(USE_STATIC_CRT "Use /MT[d] for dynamic library" OFF) +option(WARNINGS_AS_ERRORS "When enabled, compiles with `-Werror` (on *nix platforms)." OFF) set(CMAKE_CXX_STANDARD 14) @@ -76,7 +77,13 @@ if(UNIX) -Wall -Wextra -Wpedantic - -Werror + ) + + if (${WARNINGS_AS_ERRORS}) + target_compile_options(discord-rpc PRIVATE -Werror) + endif (${WARNINGS_AS_ERRORS}) + + target_compile_options(discord-rpc PRIVATE -Wno-unknown-pragmas # pragma push thing doesn't work on clang -Wno-old-style-cast # it's fine -Wno-c++98-compat # that was almost 2 decades ago