From 35cc4595bf88a4dfb53efc850eeaa32cebd21809 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Wed, 12 Aug 2020 15:39:18 +0530 Subject: [PATCH] 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. --- mesonbuild/cmake/executor.py | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/mesonbuild/cmake/executor.py b/mesonbuild/cmake/executor.py index 793862f1b..e29e67a04 100644 --- a/mesonbuild/cmake/executor.py +++ b/mesonbuild/cmake/executor.py @@ -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: