mirror of
https://github.com/json-c/json-c.git
synced 2026-03-22 22:49:06 +08:00
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 <tyler.erickson@seagate.com>
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user