Add CMake option to not add warning flags (#267)

Allow extra compiler warnings to be disabled.
This commit is contained in:
Dan Ibanez 2020-12-14 14:47:52 -07:00 committed by GitHub
parent 66b52e6cc9
commit 2d8e17c4f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -37,6 +37,7 @@ enable_testing()
option(CXXOPTS_BUILD_EXAMPLES "Set to ON to build examples" ON)
option(CXXOPTS_BUILD_TESTS "Set to ON to build tests" ON)
option(CXXOPTS_ENABLE_INSTALL "Generate the install target" ON)
option(CXXOPTS_ENABLE_WARNINGS "Add warnings to CMAKE_CXX_FLAGS" ON)
# request c++11 without gnu extension for the whole project and enable more warnings
if (CXXOPTS_CXX_STANDARD)
@ -47,11 +48,13 @@ endif()
set(CMAKE_CXX_EXTENSIONS OFF)
if (CXXOPTS_ENABLE_WARNINGS)
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 -Weffc++ -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wno-sign-conversion -Wsuggest-override")
endif()
endif()
add_library(cxxopts INTERFACE)
add_library(cxxopts::cxxopts ALIAS cxxopts)