From 0b8644c452d864dc88d801ce55b47207051857d7 Mon Sep 17 00:00:00 2001 From: Thomas Braun Date: Tue, 1 Sep 2020 13:36:55 +0200 Subject: [PATCH] test/CMakeLists.txt: Use more fine grained compiler detection Clang on Windows comes in two flavours, one which pretens to be like GCC and one which pretends to be like MSVC. We need to distinguish these two so that we can pass the correct compiler flags. Co-authored-by: James Moore --- test/CMakeLists.txt | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 3d8bceb70..403bd0402 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -142,6 +142,18 @@ set(files src/unit-user_defined_input.cpp src/unit-wstring.cpp) +set(CLANG_AS_MSVC 0) +set(MSVC_LIKE 0) + +if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") + set(MSVC_LIKE 1) +elseif(CMAKE_CXX_SIMULATE_ID STREQUAL "MSVC" + AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" + AND CMAKE_GENERATOR MATCHES "Visual Studio") + set(MSVC_LIKE 1) + set(CLANG_AS_MSVC 1) +endif() + foreach(file ${files}) get_filename_component(file_basename ${file} NAME_WE) string(REGEX REPLACE "unit-([^$]+)" "test-\\1" testcase ${file_basename}) @@ -149,10 +161,12 @@ foreach(file ${files}) add_executable(${testcase} $ ${file}) target_compile_definitions(${testcase} PRIVATE DOCTEST_CONFIG_SUPER_FAST_ASSERTS) target_compile_options(${testcase} PRIVATE - $<$:/EHsc;$<$:/Od>> - $<$>:-Wno-deprecated;-Wno-float-equal> + $<${MSVC_LIKE}:/EHsc;/W4;/WX;$<$:/Od>> + $<$:-Wno-deprecated;-Wno-float-equal;-Wall;-Wextra;-pedantic;-Werror> $<$:-Wno-deprecated-declarations> + $<${CLANG_AS_MSVC}:/clang:-Wno-deprecated;/clang:-pedantic;/clang:-Wno-deprecated-declarations;-Wno-float-equal> ) + target_include_directories(${testcase} PRIVATE ${CMAKE_BINARY_DIR}/include thirdparty/doctest thirdparty/fifo_map) target_link_libraries(${testcase} PRIVATE ${NLOHMANN_JSON_TARGET_NAME}) @@ -179,9 +193,10 @@ endforeach() add_executable(json_unit EXCLUDE_FROM_ALL $ ${files}) target_compile_definitions(json_unit PRIVATE DOCTEST_CONFIG_SUPER_FAST_ASSERTS) target_compile_options(json_unit PRIVATE - $<$:/EHsc;$<$:/Od>> - $<$>:-Wno-deprecated;-Wno-float-equal> + $<${MSVC_LIKE}:/EHsc;$<$:/Od>> + $<$:-Wno-deprecated;-Wno-float-equal> $<$:-Wno-deprecated-declarations> + $<${CLANG_AS_MSVC}:/clang:-Wno-deprecated-declarations> ) target_include_directories(json_unit PRIVATE ${CMAKE_BINARY_DIR}/include thirdparty/doctest thirdparty/fifo_map) target_link_libraries(json_unit ${NLOHMANN_JSON_TARGET_NAME})