From: Tyler Erickson Date: Mon, 20 Oct 2025 17:39:04 +0000 (-0600) Subject: bug: Fixing Cmake build when using clang-cl X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=461d9f90c41b90aaa01a0405aabc86c4947fc0fb;p=thirdparty%2Fjson-c.git bug: Fixing Cmake build when using clang-cl Clang-cl will fail to build and produce warnings about redefining existing symbols, mostly for float.h and math.h compatibility. To resolve this, this moves the clang-cl detection earlier in the CMakeLists.txt so that CLANG_CL can be checked properly where there is an existing MSVC workaround for these symbols. This resolves the build using the latest clang-cl from the LLVM clang repo as well as clang-cl that can be installed with MSVC 2022. Signed-off-by: Tyler Erickson --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e599244..4ebba27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -177,7 +177,17 @@ endif() check_symbol_exists(_isnan "float.h" HAVE_DECL__ISNAN) check_symbol_exists(_finite "float.h" HAVE_DECL__FINITE) -if ((MSVC AND NOT (MSVC_VERSION LESS 1800)) OR MINGW OR CYGWIN OR UNIX OR AMIGA) +if ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") + # Detect clang-cl.exe, it is Clang but with MSVC compatible command line arguments + execute_process (COMMAND ${CMAKE_C_COMPILER} -? ERROR_QUIET OUTPUT_QUIET RESULT_VARIABLE _clang_result) + if (_clang_result EQUAL 0) + set(CLANG_CL TRUE) + else() + set(CLANG_CL FALSE) + endif() +endif() + +if ((MSVC AND NOT (MSVC_VERSION LESS 1800)) OR MINGW OR CYGWIN OR UNIX OR AMIGA OR CLANG_CL) check_symbol_exists(INFINITY "math.h" HAVE_DECL_INFINITY) check_symbol_exists(isinf "math.h" HAVE_DECL_ISINF) check_symbol_exists(isnan "math.h" HAVE_DECL_ISNAN) @@ -328,9 +338,7 @@ if (NOT DEFINED CMAKE_C_COMPILER_FRONTEND_VARIANT OR "${CMAKE_C_COMPILER_FRONTEN elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "GNU") set(CMAKE_C_COMPILER_FRONTEND_VARIANT "GNU") elseif ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") - # Detect clang-cl.exe, it is Clang but with MSVC compatible command line arguments - execute_process (COMMAND ${CMAKE_C_COMPILER} -? ERROR_QUIET OUTPUT_QUIET RESULT_VARIABLE _clang_result) - if (_clang_result EQUAL 0) + if (CLANG_CL) set(CMAKE_C_COMPILER_FRONTEND_VARIANT "MSVC") else() set(CMAKE_C_COMPILER_FRONTEND_VARIANT "GNU")