Files
CMake/Modules/CMakeCompilerIdDetection.cmake
T
Lee Cantey e739170f15 EMBTClang: Add support for the Embarcadero bcc64x compiler
Add a new compiler id, EMBTClang, for the Embarcadero clang-based Win64
compiler (bcc64x), as a Clang variant detected by its __CODEGEARC__ marker
on the MinGW-w64 target, and exclude that target from the Embarcadero
compiler id.

Provide Compiler/ and Platform/ modules for C, CXX, and ASM, including
feature tests, binutils discovery with the linker, resource compiler, and
LLVM binutils pinned to the toolchain, and the derived RTL and include
directories forwarded into try_compile.

Drive the WIN32_EXECUTABLE property through the toolchain's console and GUI
subsystem switches, and add an EMBT_RUNTIME_LIBRARY target property
(Static or Dynamic) implemented like WATCOM_RUNTIME_LIBRARY and
MSVC_RUNTIME_LIBRARY.

Build shared and module libraries as plain DLLs.  Search for libraries as
name.lib before the MinGW names, and do not add the GNU -Bstatic and
-Bdynamic switches.  Do not provide a C++ module dependency scanning rule:
the toolchain's clang-scan-deps does not apply the bcc64x driver's target,
standard, and include paths.

Document the new id and property, and add RunCMake and build tests covering
detection, the runtime-library property, binutils pinning, the console/GUI
subsystem macros, precompiled header reuse across target kinds, and C++20
builds without module scanning.

Closes: #26769
2026-10-28 14:58:31 -04:00

172 lines
4.9 KiB
CMake

# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
# file LICENSE.rst or https://cmake.org/licensing for details.
function(_readFile file)
include(${file})
get_filename_component(name ${file} NAME_WE)
string(REGEX REPLACE "-.*" "" CompilerId ${name})
set(_compiler_id_version_compute_${CompilerId} ${_compiler_id_version_compute} PARENT_SCOPE)
set(_compiler_id_simulate_${CompilerId} ${_compiler_id_simulate} PARENT_SCOPE)
set(_compiler_id_pp_test_${CompilerId} ${_compiler_id_pp_test} PARENT_SCOPE)
endfunction()
function(compiler_id_detection outvar lang)
if (NOT "x${lang}" STREQUAL "xFortran" AND NOT "x${lang}" STREQUAL "xCSharp"
AND NOT "x${lang}" STREQUAL "xISPC")
file(GLOB lang_files
"${CMAKE_ROOT}/Modules/Compiler/*-DetermineCompiler.cmake")
set(nonlang CXX)
if ("x${lang}" STREQUAL "xCXX")
set(nonlang C)
endif()
file(GLOB nonlang_files
"${CMAKE_ROOT}/Modules/Compiler/*-${nonlang}-DetermineCompiler.cmake")
list(REMOVE_ITEM lang_files ${nonlang_files})
endif()
set(files ${lang_files})
if (files)
foreach(file ${files})
_readFile(${file})
endforeach()
set(options ID_STRING VERSION_STRINGS ID_DEFINE PLATFORM_DEFAULT_COMPILER)
set(oneValueArgs PREFIX)
cmake_parse_arguments(CID "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (CID_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "Unrecognized arguments: \"${CID_UNPARSED_ARGUMENTS}\"")
endif()
# Order is relevant here. For example, compilers which pretend to be
# GCC must appear before the actual GCC.
list(APPEND ordered_compilers
Intel
IntelLLVM
DPClang
PathScale
EMBTClang
Embarcadero
Borland
Watcom
OpenWatcom
SunPro
HP
Compaq
zOS
IBMClang
XLClang
XL
VisualAge
NVHPC
PGI
CrayClang
Cray
TI
FujitsuClang
Fujitsu
GHS
Tasking
OrangeC
Renesas
)
if ("x${lang}" STREQUAL "xC")
list(APPEND ordered_compilers
TinyCC
Bruce
PellesC
)
endif()
list(APPEND ordered_compilers
SCO
ARMCC
AppleClang
ARMClang
TIClang
)
list(APPEND ordered_compilers
Clang
LCC
GNU
MSVC
ADSP
IAR
Diab
)
if ("x${lang}" STREQUAL "xC")
list(APPEND ordered_compilers
SDCC
)
endif()
if("x${lang}" STREQUAL "xCUDA")
set(ordered_compilers NVIDIA Clang)
endif()
if("x${lang}" STREQUAL "xHIP")
set(ordered_compilers NVIDIA Clang)
endif()
if("x${lang}" STREQUAL "xSYCL")
list(PREPEND ordered_compilers AdaptiveCpp)
endif()
if(CID_ID_DEFINE)
foreach(Id ${ordered_compilers})
string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "# define ${CID_PREFIX}COMPILER_IS_${Id} 0\n")
endforeach()
# Hard-code definitions for compilers that are no longer supported.
string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "# define ${CID_PREFIX}COMPILER_IS_MIPSpro 0\n")
endif()
set(pp_if "#if")
if (CID_VERSION_STRINGS)
string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "\n/* Version number components: V=Version, R=Revision, P=Patch
Version date components: YYYY=Year, MM=Month, DD=Day */\n")
endif()
foreach(Id ${ordered_compilers})
if (NOT _compiler_id_pp_test_${Id})
message(FATAL_ERROR "No preprocessor test for \"${Id}\"")
endif()
set(id_content "${pp_if} ${_compiler_id_pp_test_${Id}}\n")
if (CID_ID_STRING)
set(PREFIX ${CID_PREFIX})
string(CONFIGURE "${_compiler_id_simulate_${Id}}" SIMULATE_BLOCK @ONLY)
string(APPEND id_content "# define ${CID_PREFIX}COMPILER_ID \"${Id}\"${SIMULATE_BLOCK}")
endif()
if (CID_ID_DEFINE)
string(APPEND id_content "# undef ${CID_PREFIX}COMPILER_IS_${Id}\n")
string(APPEND id_content "# define ${CID_PREFIX}COMPILER_IS_${Id} 1\n")
endif()
if (CID_VERSION_STRINGS)
set(PREFIX ${CID_PREFIX})
set(MACRO_DEC DEC)
set(MACRO_HEX HEX)
string(CONFIGURE "${_compiler_id_version_compute_${Id}}" VERSION_BLOCK @ONLY)
string(APPEND id_content "${VERSION_BLOCK}\n")
endif()
string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "\n${id_content}")
set(pp_if "#elif")
endforeach()
if (CID_PLATFORM_DEFAULT_COMPILER)
set(platform_compiler_detection "
/* These compilers are either not known or too old to define an
identification macro. Try to identify the platform and guess that
it is the native compiler. */
#elif defined(__hpux) || defined(__hpua)
# define ${CID_PREFIX}COMPILER_ID \"HP\"
#else /* unknown compiler */
# define ${CID_PREFIX}COMPILER_ID \"\"")
endif()
string(APPEND CMAKE_${lang}_COMPILER_ID_CONTENT "\n${platform_compiler_detection}\n#endif")
endif()
set(${outvar} ${CMAKE_${lang}_COMPILER_ID_CONTENT} PARENT_SCOPE)
endfunction()