@@ -577,7 +577,9 @@ macro(macro_setup_compilers_data
577577 endif ()
578578
579579 # Iterate over known compilers to identify the compiler type
580- foreach (_entry "clang-cl;llvm;clang-cl" "clang++;llvm;clang" "clang;llvm;clang" "appleclang++;llvm;appleclang" "g++;gnu;gcc" "gcc;gnu;gcc" "c++;gnu;cc" "cc;gnu;cc" "cl;msvc;cl" )
580+ # Note: "c++" and "cc" use "wrapper" family - they need runtime detection since they
581+ # can be symlinks/wrappers for either GCC or Clang depending on the system
582+ foreach (_entry "clang-cl;llvm;clang-cl" "clang++;llvm;clang" "clang;llvm;clang" "appleclang++;llvm;appleclang" "g++;gnu;gcc" "gcc;gnu;gcc" "c++;wrapper;cc" "cc;wrapper;cc" "cl;msvc;cl" )
581583 list (GET _entry 0 _cxx_comp)
582584
583585 # Check if the provided compiler matches the known C++ compiler
@@ -586,6 +588,27 @@ macro(macro_setup_compilers_data
586588 if (_found_pos GREATER -1)
587589 list (GET _entry 1 _family)
588590 list (GET _entry 2 _cc_comp)
591+
592+ # Handle cc/c++ wrapper compilers - detect actual compiler by running --version
593+ if (${_family} STREQUAL wrapper)
594+ execute_process (
595+ COMMAND "${compiler_path} " --version
596+ OUTPUT_VARIABLE _version_output
597+ ERROR_QUIET
598+ OUTPUT_STRIP_TRAILING_WHITESPACE
599+ RESULT_VARIABLE _version_result
600+ )
601+ string (TOLOWER "${_version_output} " _version_lower)
602+
603+ if ("${_version_lower} " MATCHES "clang" )
604+ # cc/c++ is actually Clang (common on macOS and some Linux distros)
605+ set (_family "llvm" )
606+ else ()
607+ # Assume GNU/GCC
608+ set (_family "gnu" )
609+ endif ()
610+ endif ()
611+
589612 # Handle special case for CYGWIN and GNU family compilers
590613 if (${_family} STREQUAL gnu)
591614 if (CYGWIN )
@@ -639,6 +662,9 @@ macro(macro_setup_compilers_data
639662 unset (_family)
640663 unset (_cc_comp)
641664 unset (_found_pos)
665+ unset (_version_output)
666+ unset (_version_lower)
667+ unset (_version_result)
642668
643669endmacro (macro_setup_compilers_data)
644670
0 commit comments