From 46d2235289f4bfc880ca6949f887674e1ee9d3b0 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 4 Mar 2021 17:59:31 +0100 Subject: [PATCH] use WarningsAsErrors by default while build --- CMakeLists.txt | 6 +++++- GNUmakefile | 6 +++--- cmake/WarningsAsErrors.cmake | 12 ++++++++++++ documentation/CMakeLists.txt | 2 -- standalone/CMakeLists.txt | 1 - test/CMakeLists.txt | 1 - 6 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 cmake/WarningsAsErrors.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 200893d..4431f84 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,7 +26,6 @@ include(cmake/options.cmake) # see https://github.com/cpm-cmake/CPM.cmake for more info include(cmake/CPM.cmake) -CPMUsePackageLock(package-lock.cmake) # PackageProject.cmake will be used to make our target installable CPMAddPackage("gh:TheLartians/PackageProject.cmake@1.4.1") @@ -61,6 +60,11 @@ set_target_properties( CMAKE_VISIBILITY_INLINES_HIDDEN ${BUILD_SHARED_LIBS} ) +option(WarningsAsErrors "Be realy pedantic!" YES) +if(WarningsAsErrors) + include(${CMAKE_CURRENT_LIST_DIR}/cmake/WarningsAsErrors.cmake) +endif() + # being a cross-platform target, we enforce standards conformance on MSVC target_compile_options(Greeter PUBLIC $<$:/permissive>) diff --git a/GNUmakefile b/GNUmakefile index 02bdd93..e7c35e9 100755 --- a/GNUmakefile +++ b/GNUmakefile @@ -5,8 +5,7 @@ GENERATOR?=Ninja STAGE_DIR?=$(CURDIR)/stage BUILD_TYPE?=Debug -CMAKE_PRESET:=-G "$(GENERATOR)" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) --DCMAKE_PREFIX_PATH=$(STAGE_DIR) +CMAKE_PRESET:=-G "$(GENERATOR)" -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DCMAKE_BUILD_TYPE=$(BUILD_TYPE) -DCMAKE_PREFIX_PATH=$(STAGE_DIR) # Note: not needed -DCMAKE_CXX_COMPILER_LAUNCHER=ccache #XXX export CXX=clang++ @@ -22,7 +21,7 @@ BUILD_DIR?=../build-$(PROJECT_NAME)-$(CXX)-$(BUILD_TYPE) test: clean: - rm -rf $(BUILD_DIR) build-* + rm -rf $(BUILD_DIR) build build-* distclean: clean rm -rf $(STAGE_DIR) @@ -30,6 +29,7 @@ distclean: clean # update CPM.cmake update: wget -q -O cmake/CPM.cmake https://github.com/cpm-cmake/CPM.cmake/releases/latest/download/get_cpm.cmake + wget -q -O cmake/WarningsAsErrors.cmake https://raw.githubusercontent.com/approvals/ApprovalTests.cpp/master/CMake/WarningsAsErrors.cmake lock: all standalone doc cmake --build $(BUILD_DIR)/all --target cpm-update-package-lock diff --git a/cmake/WarningsAsErrors.cmake b/cmake/WarningsAsErrors.cmake new file mode 100644 index 0000000..b23660c --- /dev/null +++ b/cmake/WarningsAsErrors.cmake @@ -0,0 +1,12 @@ +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_SIMULATE_ID MATCHES "MSVC") + target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) +elseif(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang") + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Wpedantic -Werror -Wshadow) + + if(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 10.0) + target_compile_options(${PROJECT_NAME} PRIVATE -Wdeprecated-copy-dtor -Wnewline-eof) + endif() +elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + string(REGEX REPLACE " /W[0-4]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + target_compile_options(${PROJECT_NAME} PRIVATE /W4 /WX) +endif() diff --git a/documentation/CMakeLists.txt b/documentation/CMakeLists.txt index 400d1da..a8e6a01 100644 --- a/documentation/CMakeLists.txt +++ b/documentation/CMakeLists.txt @@ -5,8 +5,6 @@ project(GreeterDocs) # ---- Dependencies ---- include(../cmake/CPM.cmake) -CPMUsePackageLock(package-lock.cmake) - include(../cmake/options.cmake) CPMAddPackage(NAME Greeter SOURCE_DIR ${CMAKE_CURRENT_LIST_DIR}/..) diff --git a/standalone/CMakeLists.txt b/standalone/CMakeLists.txt index 0286a62..b0be3c0 100644 --- a/standalone/CMakeLists.txt +++ b/standalone/CMakeLists.txt @@ -9,7 +9,6 @@ include(../cmake/tools.cmake) # ---- Dependencies ---- include(../cmake/CPM.cmake) -CPMUsePackageLock(package-lock.cmake) option(CXXOPTS_BUILD_TESTS "Not needed!" OFF) CPMAddPackage("gh:jarro2783/cxxopts@2.2.0") diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index bbfa35f..2fe15b5 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -18,7 +18,6 @@ include(../cmake/tools.cmake) # ---- Dependencies ---- include(../cmake/CPM.cmake) -CPMUsePackageLock(package-lock.cmake) CPMAddPackage("gh:onqtam/doctest#2.4.5")