From 48bfe910622d79507983fc36254ca9f3ca63acb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Krause?= Date: Tue, 27 Oct 2015 22:45:17 +0100 Subject: [PATCH 1/2] Add option JSONCPP_WITH_STRICT_ISO '-pedantic' issues all warnings demanded by strict ISO C/C++; rejecting extensions that do not follow ISO C/C++. Without this option, certain GNU extensions and traditional C/C++ features are supported as well. With this option enabled building jsoncpp fails with the musl toolchain on x86 because of an incompatible posix_memalign declaration [1]. Without '-pedantic' there is no error anymore and jsoncpp builds fine. Add an option JSONCPP_WITH_STRICT_ISO to disable compilation with '-pedantic' with GCC. If jsoncpp is build with the JSONCPP_WITH_WARNING_AS_ERROR option '-pedantic-errors' is used instead. [1] https://gcc.gnu.org/ml/gcc-patches/2015-05/msg01425.html --- CMakeLists.txt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b3ab6ee4..9c3a4e324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ ENABLE_TESTING() OPTION(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON) OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON) OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF) +OPTION(JSONCPP_WITH_STRICT_ISO "Issue all the warnings demanded by strict ISO C and ISO C++" ON) OPTION(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON) OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF) OPTION(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF) @@ -83,6 +84,10 @@ macro(UseCompilationWarningAsError) # Only enabled in debug because some old versions of VS STL generate # warnings when compiled in release configuration. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ") + elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + if (JSONCPP_WITH_STRICT_ISO) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors") + endif () endif() endmacro() @@ -100,8 +105,12 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wno-sign-conversion") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # using GCC - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -pedantic") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra") # not yet ready for -Wsign-conversion + + if (JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic") + endif () endif() find_program(CCACHE_FOUND ccache) From 7c93031c9baefd154c466a4f4efc179a942d8404 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Krause?= Date: Thu, 29 Oct 2015 09:19:41 +0100 Subject: [PATCH 2/2] Enable -Werror with JSONCPP_WITH_WARNING_AS_ERROR Commit 912d55094d2f3b777bcb48a76c2ed32447c7795e disabled '-Werror'. Enable it if jsoncpp is build with JSONCPP_WITH_WARNING_AS_ERROR=ON. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c3a4e324..028970420 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -85,6 +85,7 @@ macro(UseCompilationWarningAsError) # warnings when compiled in release configuration. set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ") elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror") if (JSONCPP_WITH_STRICT_ISO) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors") endif ()