From 38708cb91dc1f4dab2d0bb83edec7acea8be05f3 Mon Sep 17 00:00:00 2001 From: Mario Werner Date: Mon, 19 Jun 2017 15:46:14 +0200 Subject: [PATCH] define compiler warning flags globally instead of locally for every binary --- CMakeLists.txt | 10 +++++++++- src/CMakeLists.txt | 6 ------ test/CMakeLists.txt | 5 ----- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 93af87d..0d807f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -27,6 +27,15 @@ set(VERSION "1.2.0") option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON) option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" OFF) +# request c++11 without gnu extension for the whole project and enable more warnings +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_EXTENSIONS OFF) +if(MSVC) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W2") +elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow") +endif() + set(CXXOPTS_LINKER_LIBRARIES "") set(CXXOPTS_USE_UNICODE_HELP FALSE CACHE BOOL "Use ICU Unicode library") if(CXXOPTS_USE_UNICODE_HELP) @@ -39,7 +48,6 @@ if(CXXOPTS_USE_UNICODE_HELP) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${ICU_CFLAGS} -DCXXOPTS_USE_UNICODE") endif() -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -Wshadow") add_library(cxxopts INTERFACE) target_sources( diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9a79b08..eec97b7 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -21,10 +21,4 @@ if(CXXOPTS_BUILD_EXAMPLES) add_executable(example example.cpp) target_link_libraries(example cxxopts) - - if (MSVC) - target_compile_options(example PUBLIC /W2) - elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") - target_compile_options(example PUBLIC -std=c++11 -Wall) - endif() endif() diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 734e902..13b9012 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,11 +2,6 @@ if (CXXOPTS_BUILD_TESTS) add_executable(options_test main.cpp options.cpp) target_link_libraries(options_test cxxopts) - if (MSVC) - target_compile_options(options_test PUBLIC /W2) - elseif(CMAKE_CXX_COMPILER_ID MATCHES "[Cc]lang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU") - target_compile_options(options_test PUBLIC -std=c++11 -Wall) - endif() add_test(options options_test) endif()