From 132ec0a5fca4503ba08d98dce54bfb489318c2b5 Mon Sep 17 00:00:00 2001 From: FIlip Demski Date: Fri, 3 Apr 2020 10:09:29 +0200 Subject: [PATCH] Added an option to disable compiler warnings --- CMakeLists.txt | 3 +++ cmake/utils.cmake | 22 ++++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 802c8228..bb2daf5a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,9 @@ option(SPDLOG_BUILD_BENCH "Build benchmarks (Requires https://github.com/google/ # sanitizer options option(SPDLOG_SANITIZE_ADDRESS "Enable address sanitizer in tests" OFF) +# warning options +option(SPDLOG_ENABLE_WARNINGS "Enable compiler warnings" ON) + # install options option(SPDLOG_INSTALL "Generate the install target" ${SPDLOG_MASTER_PROJECT}) option(SPDLOG_FMT_EXTERNAL "Use external fmt library instead of bundled" OFF) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 5581ef95..f6f9bd78 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -28,17 +28,19 @@ endfunction() # Turn on warnings on the given target function(spdlog_enable_warnings target_name) - if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") - list(APPEND MSVC_OPTIONS "/W3") - if(MSVC_VERSION GREATER 1900) #Allow non fatal security wanrnings for msvc 2015 - list(APPEND MSVC_OPTIONS "/WX") - endif() - endif() + if(SPDLOG_ENABLE_WARNINGS) + if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + list(APPEND MSVC_OPTIONS "/W3") + if(MSVC_VERSION GREATER 1900) #Allow non fatal security wanrnings for msvc 2015 + list(APPEND MSVC_OPTIONS "/WX") + endif() + endif() - target_compile_options(${target_name} PRIVATE - $<$,$,$>: - -Wall -Wextra -Wconversion -pedantic -Wfatal-errors> - $<$:${MSVC_OPTIONS}>) + target_compile_options(${target_name} PRIVATE + $<$,$,$>: + -Wall -Wextra -Wconversion -pedantic -Wfatal-errors> + $<$:${MSVC_OPTIONS}>) + endif() endfunction()