cmake: Use a mapping when writing compiler ID

Meson and CMake compiler ids are different. This commit adds a mapping
from the meson list:

https://mesonbuild.com/Reference-tables.html#compiler-ids

to the CMake list:

https://cmake.org/cmake/help/latest/variable/CMAKE_LANG_COMPILER_ID.html

The mapping is not 1-1, and not all entries are mapped, so this is
a best-effort attempt. Fallback to GNU as before to try to limp along
and hope that the build files don't rely on an accurate compiler ID.
This commit is contained in:
Nirbheek Chauhan 2020-08-12 15:39:18 +05:30 committed by Nirbheek Chauhan
parent bc64e1d6b0
commit 4b0e1850a0
1 changed files with 26 additions and 1 deletions

View File

@ -35,6 +35,31 @@ if T.TYPE_CHECKING:
TYPE_result = T.Tuple[int, T.Optional[str], T.Optional[str]]
MESON_TO_CMAKE_MAPPING = {
'arm': 'ARMCC',
'armclang': 'ARMClang',
'clang': 'Clang',
'clang-cl': 'MSVC',
'flang': 'Flang',
'g95': 'G95',
'gcc': 'GNU',
'intel': 'Intel',
'intel-cl': 'MSVC',
'msvc': 'MSVC',
'pathscale': 'PathScale',
'pgi': 'PGI',
'sun': 'SunPro',
}
def meson_compiler_to_cmake_id(cobj):
# cland and apple clang both map to 'clang' in meson, so we need to look at
# the linker that's being used
if cobj.linker.get_id() == 'ld64':
return 'AppleClang'
# If no mapping, try GNU and hope that the build files don't care
return MESON_TO_CMAKE_MAPPING.get(cobj.get_id(), 'GNU')
class CMakeExecutor:
# The class's copy of the CMake path. Avoids having to search for it
# multiple times in the same Meson invocation.
@ -280,7 +305,7 @@ class CMakeExecutor:
if comp_obj is not None:
exe_list = comp_obj.get_exelist()
comp_id = comp_obj.get_id().upper()
comp_id = meson_compiler_to_cmake_id(comp_obj)
comp_version = comp_obj.version.upper()
if len(exe_list) == 1: