From 2a7fc9e30edc03488c689811d1ef239d3ea567e5 Mon Sep 17 00:00:00 2001 From: Trond H Emaus Date: Fri, 27 Mar 2020 19:59:22 +0100 Subject: [PATCH 1/3] add /WX mscv compiler option for only mscv compiler clang on windows support both gcc and mscv style options. Clang.exe on windows defaults to gcc style, which will result in /WX unknown compiler command. This will set /WX if and only if the compiler is MSVC and greater than version 1900 --- cmake/utils.cmake | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 997bc2d1..6b6bfa5f 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -28,13 +28,15 @@ endfunction() # Turn on warnings on the given target function(spdlog_enable_warnings target_name) + set(MSVC_OPTIONS "/W3") + if(MSVC_VERSION GREATER 1900) #Allow non fatal security wanrnings for msvc 2015 + set(MSVC_OPTIONS "${MSVC_OPTIONS} /WX") + endif() target_compile_options(${target_name} PRIVATE $<$,$,$>: -Wall -Wextra -Wconversion -pedantic -Wfatal-errors> - $<$:/W3>) - if(MSVC_VERSION GREATER 1900) #Allow non fatal security wanrnings for msvc 2015 - target_compile_options(${target_name} PRIVATE /WX) - endif() + $<$:${MSVC_OPTIONS}>) + endfunction() From 7054cf7a35c1816679d5fa20f3c9f063261ee422 Mon Sep 17 00:00:00 2001 From: Trond H Emaus Date: Sat, 28 Mar 2020 00:03:59 +0100 Subject: [PATCH 2/3] replace MSVC_OPTIONS variable as list --- cmake/utils.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index 6b6bfa5f..bd6d3777 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -28,9 +28,9 @@ endfunction() # Turn on warnings on the given target function(spdlog_enable_warnings target_name) - set(MSVC_OPTIONS "/W3") + list(APPEND MSVC_OPTIONS "/W3") if(MSVC_VERSION GREATER 1900) #Allow non fatal security wanrnings for msvc 2015 - set(MSVC_OPTIONS "${MSVC_OPTIONS} /WX") + list(APPEND MSVC_OPTIONS "/WX") endif() target_compile_options(${target_name} PRIVATE $<$,$,$>: From 3e4df86ac02b21f206e64c17beea69285bc332a5 Mon Sep 17 00:00:00 2001 From: Trond H Emaus Date: Sat, 28 Mar 2020 10:26:32 +0100 Subject: [PATCH 3/3] create MSVC_OPTIONS list only if compiler is msvc --- cmake/utils.cmake | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/cmake/utils.cmake b/cmake/utils.cmake index bd6d3777..5581ef95 100644 --- a/cmake/utils.cmake +++ b/cmake/utils.cmake @@ -28,10 +28,13 @@ endfunction() # Turn on warnings on the given target function(spdlog_enable_warnings target_name) - list(APPEND MSVC_OPTIONS "/W3") - if(MSVC_VERSION GREATER 1900) #Allow non fatal security wanrnings for msvc 2015 - list(APPEND MSVC_OPTIONS "/WX") + 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>