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
This commit is contained in:
Daniel Gibson 2024-03-19 01:53:53 +01:00
parent 34db181b40
commit 94b4289527

View file

@ -154,8 +154,25 @@ endif()
include(CheckCXXCompilerFlag) include(CheckCXXCompilerFlag)
include(TestBigEndian) 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 # 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(-pipe)
add_compile_options(-Wall) add_compile_options(-Wall)
@ -168,7 +185,7 @@ if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID STREQUAL "Clang")
if(FORCE_COLORED_OUTPUT) if(FORCE_COLORED_OUTPUT)
if(CMAKE_COMPILER_IS_GNUCC) if(CMAKE_COMPILER_IS_GNUCC)
add_compile_options (-fdiagnostics-color=always) add_compile_options (-fdiagnostics-color=always)
elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") elseif (D3_COMPILER_IS_CLANG)
add_compile_options (-fcolor-diagnostics) add_compile_options (-fcolor-diagnostics)
endif () endif ()
endif () endif ()
@ -567,7 +584,7 @@ if (AROS)
set(AROS_ARCH ${CMAKE_SYSTEM_PROCESSOR}) set(AROS_ARCH ${CMAKE_SYSTEM_PROCESSOR})
endif() endif()
else() 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") set_target_properties(idlib PROPERTIES COMPILE_FLAGS "-fPIC")
endif() endif()
endif() endif()