define compiler warning flags globally instead of locally for every binary

This commit is contained in:
Mario Werner 2017-06-19 15:46:14 +02:00
parent 34c574802e
commit 38708cb91d
3 changed files with 9 additions and 12 deletions

View File

@ -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(

View File

@ -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()

View File

@ -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()