From bf8e8c843d524c3a3371c2ea59d92d567cf85e90 Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Tue, 19 Mar 2024 01:53:53 +0100 Subject: [PATCH] CMake: Detect all variations of the clang compiler (hopefully) According to https://cmake.org/cmake/help/v3.26/variable/CMAKE_LANG_COMPILER_ID.html there's at least "Clang" (plain LLVM clang), "AppleClang", "ARMClang", "FujitsuClang", "XLClang" and "IBMClang" (both of which are variations of the clang/llvm-based IBM XL compiler). This should detect all of them (I hope they all behave close enough to normal clang to work..) There's also "IntelLLVM", but I have no idea if that's based on Clang or does its own thing based on LLVM.. I also doubt dhewm3 will ever be built with any other clang-derivate than "Clang" and "AppleClang" :-p fixes #510 --- CMakeLists.txt | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b31399..6505a39 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,8 +156,25 @@ endif() include(CheckCXXCompilerFlag) include(TestBigEndian) +set(D3_COMPILER_IS_CLANG FALSE) +set(D3_COMPILER_IS_GCC_OR_CLANG FALSE) + +if(NOT MSVC) + # check if this is some kind of clang (Clang, AppleClang, whatever) + # (convert compiler ID to lowercase so we match Clang, clang, AppleClang etc, regardless of case) + string(TOLOWER ${CMAKE_CXX_COMPILER_ID} compiler_id_lower) + if(compiler_id_lower MATCHES ".*clang.*") + message(STATUS "Compiler \"${CMAKE_CXX_COMPILER_ID}\" detected as some kind of clang") + set(D3_COMPILER_IS_CLANG TRUE) + set(D3_COMPILER_IS_GCC_OR_CLANG TRUE) + elseif(CMAKE_COMPILER_IS_GNUCC) + set(D3_COMPILER_IS_GCC_OR_CLANG TRUE) + endif() + unset(compiler_id_lower) +endif() # NOT MSVC + # compiler specific flags -if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") +if(D3_COMPILER_IS_GCC_OR_CLANG) add_compile_options(-pipe) add_compile_options(-Wall) @@ -170,7 +187,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang") if(FORCE_COLORED_OUTPUT) if(CMAKE_COMPILER_IS_GNUCC) add_compile_options (-fdiagnostics-color=always) - elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + elseif (D3_COMPILER_IS_CLANG) add_compile_options (-fcolor-diagnostics) endif () endif () @@ -569,7 +586,7 @@ if (AROS) set(AROS_ARCH ${CMAKE_SYSTEM_PROCESSOR}) endif() else() - if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang" AND NOT MINGW) + if(D3_COMPILER_IS_GCC_OR_CLANG AND NOT MINGW) set_target_properties(idlib PROPERTIES COMPILE_FLAGS "-fPIC") endif() endif()