From cb2872e0b2a2f71f54da101cca0ef791389e3a71 Mon Sep 17 00:00:00 2001 From: ibireme Date: Sun, 8 Dec 2024 22:10:10 +0800 Subject: [PATCH] Fix MSVC compiler flags by using list instead of string concatenation: #189 --- CMakeLists.txt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d47d8e5..9b482b2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") include(XcodeProperty) if(XCODE) + # Flag string for Xcode property set(YYJSON_FLAGS "-Wall -Wextra -Werror -pedantic -pedantic-errors") if(YYJSON_ENABLE_FASTMATH) set(YYJSON_FLAGS "${YYJSON_FLAGS} -ffast-math") @@ -98,18 +99,20 @@ if(XCODE) set_xcode_property(yyjson OTHER_CFLAGS[variant=Release] ${YYJSON_FLAGS}) elseif(MSVC) + # Flag list for MSVC set(YYJSON_FLAGS "/utf-8") if(YYJSON_ENABLE_FASTMATH) - set(YYJSON_FLAGS "${YYJSON_FLAGS} /fp:fast") + list(APPEND YYJSON_FLAGS "/fp:fast") endif() target_compile_options(yyjson PRIVATE $<$:${YYJSON_FLAGS}>) target_compile_options(yyjson PRIVATE $<$:${YYJSON_FLAGS}>) elseif(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|Intel") - set(YYJSON_FLAGS "") + # Flag list for GCC like compilers + set(YYJSON_FLAGS) if(YYJSON_ENABLE_FASTMATH) - set(YYJSON_FLAGS "-ffast-math") + list(APPEND YYJSON_FLAGS "-ffast-math") endif() target_compile_options(yyjson PRIVATE $<$:${YYJSON_FLAGS}>)