From 8c0a2daa1320a5a5bdc470a6c3a551822f67748c Mon Sep 17 00:00:00 2001 From: pac Date: Fri, 20 Dec 2019 04:48:14 +0100 Subject: [PATCH] Fixes to cmake for MSVC build --- CMakeLists.txt | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 64116d6..83c1b4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,12 +24,26 @@ endif() add_library(json11 json11.cpp) target_include_directories(json11 PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) -target_compile_options(json11 - PRIVATE -fPIC -fno-rtti -fno-exceptions -Wall) +if (NOT MSVC) + target_compile_options(json11 + PRIVATE -fPIC -fno-rtti -fno-exceptions -Wall) +endif() # Set warning flags, which may vary per platform include(CheckCXXCompilerFlag) -set(_possible_warnings_flags /W4 /WX -Wextra -Werror) +set(_possible_warnings_flags /W4 /WX) +# +# Add Wextra & Werror compiler flags only if not building with Microsoft compiler +# +# NOTE: +# check_cxx_compiler_flag() for these flags evaluates to positive result +# but during build, cl.exe fails with following error +# cl : Command line error D8021: invalid numeric argument '/Wextra' +# +if (NOT MSVC) + set(_possible_warnings_flags ${_possible_warnings_flags} -Wextra -Werror) +endif() + foreach(_warning_flag ${_possible_warnings_flags}) unset(_flag_supported) CHECK_CXX_COMPILER_FLAG(${_warning_flag} _flag_supported)