Skip to content

Commit 9234cbb

Browse files
committed
Merge pull request open-source-parsers#387 from joerg-krause/cmake-option-strict-iso
Disable -pedantic conditionally; add -pedantic-errors and -Werror conditionally
2 parents 0cce773 + 7c93031 commit 9234cbb

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ ENABLE_TESTING()
77
OPTION(JSONCPP_WITH_TESTS "Compile and (for jsoncpp_check) run JsonCpp test executables" ON)
88
OPTION(JSONCPP_WITH_POST_BUILD_UNITTEST "Automatically run unit-tests as a post build step" ON)
99
OPTION(JSONCPP_WITH_WARNING_AS_ERROR "Force compilation to fail if a warning occurs" OFF)
10+
OPTION(JSONCPP_WITH_STRICT_ISO "Issue all the warnings demanded by strict ISO C and ISO C++" ON)
1011
OPTION(JSONCPP_WITH_PKGCONFIG_SUPPORT "Generate and install .pc files" ON)
1112
OPTION(JSONCPP_WITH_CMAKE_PACKAGE "Generate and install cmake package files" OFF)
1213
OPTION(BUILD_SHARED_LIBS "Build jsoncpp_lib as a shared library." OFF)
@@ -83,6 +84,11 @@ macro(UseCompilationWarningAsError)
8384
# Only enabled in debug because some old versions of VS STL generate
8485
# warnings when compiled in release configuration.
8586
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /WX ")
87+
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
88+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
89+
if (JSONCPP_WITH_STRICT_ISO)
90+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic-errors")
91+
endif ()
8692
endif()
8793
endmacro()
8894

@@ -100,8 +106,12 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
100106
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wno-sign-conversion")
101107
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
102108
# using GCC
103-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra -pedantic")
109+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wconversion -Wshadow -Wextra")
104110
# not yet ready for -Wsign-conversion
111+
112+
if (JSONCPP_WITH_STRICT_ISO AND NOT JSONCPP_WITH_WARNING_AS_ERROR)
113+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pedantic")
114+
endif ()
105115
endif()
106116

107117
find_program(CCACHE_FOUND ccache)

0 commit comments

Comments
 (0)