cmake: select correct generator in toolchain.py
This commit is contained in:
parent
f0812baf8d
commit
9b5463681e
|
@ -30,11 +30,13 @@ __all__ = [
|
||||||
'TargetOptions',
|
'TargetOptions',
|
||||||
'parse_generator_expressions',
|
'parse_generator_expressions',
|
||||||
'language_map',
|
'language_map',
|
||||||
|
'backend_generator_map',
|
||||||
|
'cmake_get_generator_args',
|
||||||
'cmake_defines_to_args',
|
'cmake_defines_to_args',
|
||||||
'check_cmake_args',
|
'check_cmake_args',
|
||||||
]
|
]
|
||||||
|
|
||||||
from .common import CMakeException, SingleTargetOptions, TargetOptions, cmake_defines_to_args, language_map, check_cmake_args
|
from .common import CMakeException, SingleTargetOptions, TargetOptions, cmake_defines_to_args, language_map, backend_generator_map, cmake_get_generator_args, check_cmake_args
|
||||||
from .client import CMakeClient
|
from .client import CMakeClient
|
||||||
from .executor import CMakeExecutor
|
from .executor import CMakeExecutor
|
||||||
from .fileapi import CMakeFileAPI
|
from .fileapi import CMakeFileAPI
|
||||||
|
|
|
@ -15,11 +15,14 @@
|
||||||
# This class contains the basic functionality needed to run any interpreter
|
# This class contains the basic functionality needed to run any interpreter
|
||||||
# or an interpreter-based tool.
|
# or an interpreter-based tool.
|
||||||
|
|
||||||
from ..mesonlib import MesonException
|
from ..mesonlib import MesonException, OptionKey
|
||||||
from .. import mlog
|
from .. import mlog
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import typing as T
|
import typing as T
|
||||||
|
|
||||||
|
if T.TYPE_CHECKING:
|
||||||
|
from ..environment import Environment
|
||||||
|
|
||||||
language_map = {
|
language_map = {
|
||||||
'c': 'C',
|
'c': 'C',
|
||||||
'cpp': 'CXX',
|
'cpp': 'CXX',
|
||||||
|
@ -32,6 +35,15 @@ language_map = {
|
||||||
'swift': 'Swift',
|
'swift': 'Swift',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
backend_generator_map = {
|
||||||
|
'ninja': 'Ninja',
|
||||||
|
'xcode': 'Xcode',
|
||||||
|
'vs2010': 'Visual Studio 10 2010',
|
||||||
|
'vs2015': 'Visual Studio 15 2017',
|
||||||
|
'vs2017': 'Visual Studio 15 2017',
|
||||||
|
'vs2019': 'Visual Studio 16 2019',
|
||||||
|
}
|
||||||
|
|
||||||
blacklist_cmake_defs = [
|
blacklist_cmake_defs = [
|
||||||
'CMAKE_TOOLCHAIN_FILE',
|
'CMAKE_TOOLCHAIN_FILE',
|
||||||
'CMAKE_PROJECT_INCLUDE',
|
'CMAKE_PROJECT_INCLUDE',
|
||||||
|
@ -87,6 +99,12 @@ def _flags_to_list(raw: str) -> T.List[str]:
|
||||||
res = list(filter(lambda x: len(x) > 0, res))
|
res = list(filter(lambda x: len(x) > 0, res))
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
def cmake_get_generator_args(env: 'Environment') -> T.List[str]:
|
||||||
|
backend_name = env.coredata.get_option(OptionKey('backend'))
|
||||||
|
assert isinstance(backend_name, str)
|
||||||
|
assert backend_name in backend_generator_map
|
||||||
|
return ['-G', backend_generator_map[backend_name]]
|
||||||
|
|
||||||
def cmake_defines_to_args(raw: T.Any, permissive: bool = False) -> T.List[str]:
|
def cmake_defines_to_args(raw: T.Any, permissive: bool = False) -> T.List[str]:
|
||||||
res = [] # type: T.List[str]
|
res = [] # type: T.List[str]
|
||||||
if not isinstance(raw, list):
|
if not isinstance(raw, list):
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
# This class contains the basic functionality needed to run any interpreter
|
# This class contains the basic functionality needed to run any interpreter
|
||||||
# or an interpreter-based tool.
|
# or an interpreter-based tool.
|
||||||
|
|
||||||
from .common import CMakeException, CMakeTarget, TargetOptions, CMakeConfiguration, language_map, check_cmake_args
|
from .common import CMakeException, CMakeTarget, TargetOptions, CMakeConfiguration, language_map, backend_generator_map, cmake_get_generator_args, check_cmake_args
|
||||||
from .client import CMakeClient, RequestCMakeInputs, RequestConfigure, RequestCompute, RequestCodeModel, ReplyCMakeInputs, ReplyCodeModel
|
from .client import CMakeClient, RequestCMakeInputs, RequestConfigure, RequestCompute, RequestCodeModel, ReplyCMakeInputs, ReplyCodeModel
|
||||||
from .fileapi import CMakeFileAPI
|
from .fileapi import CMakeFileAPI
|
||||||
from .executor import CMakeExecutor
|
from .executor import CMakeExecutor
|
||||||
|
@ -74,15 +74,6 @@ disable_policy_warnings = [
|
||||||
'CMP0102',
|
'CMP0102',
|
||||||
]
|
]
|
||||||
|
|
||||||
backend_generator_map = {
|
|
||||||
'ninja': 'Ninja',
|
|
||||||
'xcode': 'Xcode',
|
|
||||||
'vs2010': 'Visual Studio 10 2010',
|
|
||||||
'vs2015': 'Visual Studio 15 2017',
|
|
||||||
'vs2017': 'Visual Studio 15 2017',
|
|
||||||
'vs2019': 'Visual Studio 16 2019',
|
|
||||||
}
|
|
||||||
|
|
||||||
target_type_map = {
|
target_type_map = {
|
||||||
'STATIC_LIBRARY': 'static_library',
|
'STATIC_LIBRARY': 'static_library',
|
||||||
'MODULE_LIBRARY': 'shared_module',
|
'MODULE_LIBRARY': 'shared_module',
|
||||||
|
@ -898,9 +889,8 @@ class CMakeInterpreter:
|
||||||
# TODO: drop this check once the deprecated `cmake_args` kwarg is removed
|
# TODO: drop this check once the deprecated `cmake_args` kwarg is removed
|
||||||
extra_cmake_options = check_cmake_args(extra_cmake_options)
|
extra_cmake_options = check_cmake_args(extra_cmake_options)
|
||||||
|
|
||||||
generator = backend_generator_map[self.backend_name]
|
|
||||||
cmake_args = []
|
cmake_args = []
|
||||||
cmake_args += ['-G', generator]
|
cmake_args += cmake_get_generator_args(self.env)
|
||||||
cmake_args += [f'-DCMAKE_INSTALL_PREFIX={self.install_prefix}']
|
cmake_args += [f'-DCMAKE_INSTALL_PREFIX={self.install_prefix}']
|
||||||
cmake_args += extra_cmake_options
|
cmake_args += extra_cmake_options
|
||||||
trace_args = self.trace.trace_args()
|
trace_args = self.trace.trace_args()
|
||||||
|
|
|
@ -16,7 +16,7 @@ from pathlib import Path
|
||||||
from .traceparser import CMakeTraceParser
|
from .traceparser import CMakeTraceParser
|
||||||
from ..envconfig import CMakeSkipCompilerTest
|
from ..envconfig import CMakeSkipCompilerTest
|
||||||
from ..mesonlib import MachineChoice
|
from ..mesonlib import MachineChoice
|
||||||
from .common import language_map
|
from .common import language_map, cmake_get_generator_args
|
||||||
from .. import mlog
|
from .. import mlog
|
||||||
|
|
||||||
import shutil
|
import shutil
|
||||||
|
@ -224,7 +224,10 @@ class CMakeToolchain:
|
||||||
# Configure
|
# Configure
|
||||||
trace = CMakeTraceParser(self.cmakebin.version(), build_dir)
|
trace = CMakeTraceParser(self.cmakebin.version(), build_dir)
|
||||||
self.cmakebin.set_exec_mode(print_cmout=False, always_capture_stderr=trace.requires_stderr())
|
self.cmakebin.set_exec_mode(print_cmout=False, always_capture_stderr=trace.requires_stderr())
|
||||||
cmake_args = [*trace.trace_args(), '-DCMAKE_TOOLCHAIN_FILE=' + temp_toolchain_file.as_posix(), '.']
|
cmake_args = []
|
||||||
|
cmake_args += trace.trace_args()
|
||||||
|
cmake_args += cmake_get_generator_args(self.env)
|
||||||
|
cmake_args += [f'-DCMAKE_TOOLCHAIN_FILE={temp_toolchain_file.as_posix()}', '.']
|
||||||
rc, _, raw_trace = self.cmakebin.call(cmake_args, build_dir=build_dir, disable_cache=True)
|
rc, _, raw_trace = self.cmakebin.call(cmake_args, build_dir=build_dir, disable_cache=True)
|
||||||
|
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
|
|
Loading…
Reference in New Issue