From 26e570e9fea5e607aa76da8dc6d96bbbfae4d507 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Tue, 25 Jun 2024 09:08:54 +0200 Subject: [PATCH] [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 --- CMakeLists.txt | 5 +++-- cmake/CompilerDetect.cmake | 6 ++++++ cmake/ConfigOptions.cmake | 4 +--- libfreerdp/codec/CMakeLists.txt | 4 +++- libfreerdp/primitives/CMakeLists.txt | 5 +++-- 5 files changed, 16 insertions(+), 8 deletions(-) create mode 100644 cmake/CompilerDetect.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 2ca415cf6..b181d3236 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/CompilerDetect.cmake b/cmake/CompilerDetect.cmake new file mode 100644 index 000000000..b1390f7fb --- /dev/null +++ b/cmake/CompilerDetect.cmake @@ -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() diff --git a/cmake/ConfigOptions.cmake b/cmake/ConfigOptions.cmake index 89008c2dc..d0a1dada9 100644 --- a/cmake/ConfigOptions.cmake +++ b/cmake/ConfigOptions.cmake @@ -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 diff --git a/libfreerdp/codec/CMakeLists.txt b/libfreerdp/codec/CMakeLists.txt index 811009525..88e32c9ce 100644 --- a/libfreerdp/codec/CMakeLists.txt +++ b/libfreerdp/codec/CMakeLists.txt @@ -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() diff --git a/libfreerdp/primitives/CMakeLists.txt b/libfreerdp/primitives/CMakeLists.txt index 7526f7ace..75fc8a7a9 100644 --- a/libfreerdp/primitives/CMakeLists.txt +++ b/libfreerdp/primitives/CMakeLists.txt @@ -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()