diff --git a/CMake/utility.cmake b/CMake/utility.cmake index cd1e835c..f7c4e33e 100644 --- a/CMake/utility.cmake +++ b/CMake/utility.cmake @@ -390,21 +390,25 @@ endfunction() # Adds warnings compiler options to the target depending on the category # target Target name #################################################################################### -function( set_compiler_warnings target) - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") - set(WARNINGS "-Werror" - "-Wall") - elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(WARNINGS "-Werror" - "-Wall") - elseif(MSVC) - set(WARNINGS "/WX" - "/W4") - endif() - target_compile_options(${target} PRIVATE ${WARNINGS}) +function(set_compiler_warnings target) + # Return if WARNINGS_AS_ERROR is OFF + if(NOT WARNINGS_AS_ERROR) + return() + endif() + + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set(WARNINGS "-Werror" "-Wall") + elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(WARNINGS "-Werror" "-Wall") + elseif(MSVC) + set(WARNINGS "/WX" "/W4") + endif() + + target_compile_options(${target} PRIVATE ${WARNINGS}) endfunction() + #################################################################################### # Adds or replace a compiler option # _OLD_OPTION The option which should be replaced diff --git a/CMakeLists.txt b/CMakeLists.txt index 1af95a8c..87c531f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,7 @@ # the build configuration options are initialized. # #################################################################################### -cmake_minimum_required (VERSION 3.0) +cmake_minimum_required (VERSION 3.5) project ("rttr" LANGUAGES CXX) @@ -60,6 +60,7 @@ option(BUILD_PACKAGE "Enable this to build the installer" ON) option(USE_PCH "Use precompiled header files for compilation" ON) option(CUSTOM_DOXYGEN_STYLE "Enable this option to use a custom doxygen style for HTML documentation; Otherwise the default will be used" ON) option(BUILD_WEBSITE_DOCU "Enable this option to create the special docu for the website" OFF) +option(WARNINGS_AS_ERROR "Enable this option to treat warnings as error" OFF) # one precompiled headers cannot be used for multiple ninja targets # thats why we have to disable this option, when BUILD_STATIC or