[cmake] unify clang detection

* Move Clang detection to own CMake file
* Check for Clang and AppleClang
* Use CMAKE_COMPILER_IS_CLANG to check for Clang in code
This commit is contained in:
akallabeth 2024-06-25 09:08:54 +02:00
parent 55258cd9eb
commit 26e570e9fe
No known key found for this signature in database
GPG Key ID: A49454A3FC909FD5
5 changed files with 16 additions and 8 deletions

View File

@ -73,6 +73,7 @@ include(CheckLibraryExists)
include(CheckSymbolExists)
include(CheckStructHasMember)
include(TestBigEndian)
include(CompilerDetect)
include(FindFeature)
include(ShowCMakeVars)
@ -249,7 +250,7 @@ if (CMAKE_GENERATOR MATCHES "Unix Makefile*")
endif()
endif()
if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
if(CMAKE_COMPILER_IS_CLANG)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-c11-extensions -Wno-gnu")
endif()
@ -260,7 +261,7 @@ if(NOT IOS)
endif()
# Enable address sanitizer, where supported and when required
if(${CMAKE_C_COMPILER_ID} STREQUAL "Clang" OR CMAKE_COMPILER_IS_GNUCC)
if(CMAKE_COMPILER_IS_CLANG OR CMAKE_COMPILER_IS_GNUCC)
CHECK_C_COMPILER_FLAG ("-fno-omit-frame-pointer" fno-omit-frame-pointer)
if (fno-omit-frame-pointer)

View File

@ -0,0 +1,6 @@
if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_COMPILER_IS_CLANG 1)
endif()
if(CMAKE_C_COMPILER_ID MATCHES "AppleClang" OR CMAKE_CXX_COMPILER_ID MATCHES "AppleClang")
set(CMAKE_COMPILER_IS_CLANG 1)
endif()

View File

@ -27,9 +27,7 @@ option(WITH_NEON "Enable NEON optimization." OFF)
option(WITH_JPEG "Use JPEG decoding." OFF)
if(CMAKE_C_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_COMPILER_IS_CLANG 1)
endif()
include(CompilerDetect)
if(NOT WIN32)
CMAKE_DEPENDENT_OPTION(WITH_VALGRIND_MEMCHECK "Compile with valgrind helpers." OFF

View File

@ -59,8 +59,10 @@ set(CODEC_LIBS "")
list(APPEND CODEC_SRCS ${CODEC_SSE2_SRCS})
list(APPEND CODEC_SRCS ${CODEC_NEON_SRCS})
include(CompilerDetect)
if(WITH_SSE2)
if(CMAKE_COMPILER_IS_GNUCC OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
if (CODEC_SSE2_SRCS)
set_source_files_properties(${CODEC_SSE2_SRCS} PROPERTIES COMPILE_FLAGS "-msse2" )
endif()

View File

@ -86,8 +86,9 @@ add_library(freerdp-primitives OBJECT
${PRIMITIVES_SRCS}
)
include(CompilerDetect)
if(WITH_SSE2)
if(CMAKE_COMPILER_IS_GNUCC OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
if(PRIMITIVES_SSE2_SRCS)
set_source_files_properties(${PRIMITIVES_SSE2_SRCS} PROPERTIES COMPILE_FLAGS "-msse2" )
endif()
@ -112,7 +113,7 @@ if(WITH_SSE2)
set_source_files_properties(${PRIMITIVES_OPT_SRCS} PROPERTIES COMPILE_FLAGS "/arch:SSE2")
endif()
elseif(WITH_NEON)
if(CMAKE_COMPILER_IS_GNUCC OR ${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_CLANG)
if (NOT MSVC_ARM64 AND NOT ARCH_ARM64)
set_source_files_properties(${PRIMITIVES_OPT_SRCS} PROPERTIES COMPILE_FLAGS "-mfpu=neon")
endif()