cmake: Added option for additional CMake args
This commit is contained in:
parent
d114d8446e
commit
3d7c50d109
|
@ -226,7 +226,7 @@ class CMakeInterpreter:
|
||||||
self.languages = []
|
self.languages = []
|
||||||
self.targets = []
|
self.targets = []
|
||||||
|
|
||||||
def configure(self) -> None:
|
def configure(self, extra_cmake_options: List[str]) -> None:
|
||||||
# Find CMake
|
# Find CMake
|
||||||
cmake_exe, cmake_vers, _ = CMakeDependency.find_cmake_binary(self.env)
|
cmake_exe, cmake_vers, _ = CMakeDependency.find_cmake_binary(self.env)
|
||||||
if cmake_exe is None or cmake_exe is False:
|
if cmake_exe is None or cmake_exe is False:
|
||||||
|
@ -249,7 +249,9 @@ class CMakeInterpreter:
|
||||||
elif len(exelist) == 2:
|
elif len(exelist) == 2:
|
||||||
cmake_args += ['-DCMAKE_{}_COMPILER_LAUNCHER={}'.format(cmake_lang, exelist[0]),
|
cmake_args += ['-DCMAKE_{}_COMPILER_LAUNCHER={}'.format(cmake_lang, exelist[0]),
|
||||||
'-DCMAKE_{}_COMPILER={}'.format(cmake_lang, exelist[1])]
|
'-DCMAKE_{}_COMPILER={}'.format(cmake_lang, exelist[1])]
|
||||||
cmake_args += ['-G', generator, '-DCMAKE_INSTALL_PREFIX={}'.format(self.install_prefix)]
|
cmake_args += ['-G', generator]
|
||||||
|
cmake_args += ['-DCMAKE_INSTALL_PREFIX={}'.format(self.install_prefix)]
|
||||||
|
cmake_args += extra_cmake_options
|
||||||
|
|
||||||
# Run CMake
|
# Run CMake
|
||||||
mlog.log()
|
mlog.log()
|
||||||
|
@ -276,10 +278,10 @@ class CMakeInterpreter:
|
||||||
if proc.returncode != 0:
|
if proc.returncode != 0:
|
||||||
raise CMakeException('Failed to configure the CMake subproject')
|
raise CMakeException('Failed to configure the CMake subproject')
|
||||||
|
|
||||||
def initialise(self) -> None:
|
def initialise(self, extra_cmake_options: List[str]) -> None:
|
||||||
# Run configure the old way becuse doing it
|
# Run configure the old way becuse doing it
|
||||||
# with the server doesn't work for some reason
|
# with the server doesn't work for some reason
|
||||||
self.configure()
|
self.configure(extra_cmake_options)
|
||||||
|
|
||||||
with self.client.connect():
|
with self.client.connect():
|
||||||
generator = CMAKE_BACKEND_GENERATOR_MAP[self.backend_name]
|
generator = CMAKE_BACKEND_GENERATOR_MAP[self.backend_name]
|
||||||
|
@ -300,6 +302,7 @@ class CMakeInterpreter:
|
||||||
src_dir = bs_reply.src_dir
|
src_dir = bs_reply.src_dir
|
||||||
self.bs_files = [x.file for x in bs_reply.build_files if not x.is_cmake and not x.is_temp]
|
self.bs_files = [x.file for x in bs_reply.build_files if not x.is_cmake and not x.is_temp]
|
||||||
self.bs_files = [os.path.relpath(os.path.join(src_dir, x), self.env.get_source_dir()) for x in self.bs_files]
|
self.bs_files = [os.path.relpath(os.path.join(src_dir, x), self.env.get_source_dir()) for x in self.bs_files]
|
||||||
|
self.bs_files = list(set(self.bs_files))
|
||||||
self.codemodel = cm_reply
|
self.codemodel = cm_reply
|
||||||
|
|
||||||
def analyse(self) -> None:
|
def analyse(self) -> None:
|
||||||
|
|
|
@ -2028,7 +2028,7 @@ permitted_kwargs = {'add_global_arguments': {'language', 'native'},
|
||||||
'both_libraries': known_library_kwargs,
|
'both_libraries': known_library_kwargs,
|
||||||
'library': known_library_kwargs,
|
'library': known_library_kwargs,
|
||||||
'subdir': {'if_found'},
|
'subdir': {'if_found'},
|
||||||
'subproject': {'version', 'default_options', 'required', 'method'},
|
'subproject': {'version', 'default_options', 'required', 'method', 'cmake_options'},
|
||||||
'test': {'args', 'depends', 'env', 'is_parallel', 'should_fail', 'timeout', 'workdir',
|
'test': {'args', 'depends', 'env', 'is_parallel', 'should_fail', 'timeout', 'workdir',
|
||||||
'suite', 'protocol'},
|
'suite', 'protocol'},
|
||||||
'vcs_tag': {'input', 'output', 'fallback', 'command', 'replace_string'},
|
'vcs_tag': {'input', 'output', 'fallback', 'command', 'replace_string'},
|
||||||
|
@ -2548,8 +2548,9 @@ external dependencies (including libraries) must go to "dependencies".''')
|
||||||
with mlog.nested():
|
with mlog.nested():
|
||||||
new_build = self.build.copy()
|
new_build = self.build.copy()
|
||||||
prefix = self.coredata.builtins['prefix'].value
|
prefix = self.coredata.builtins['prefix'].value
|
||||||
|
cmake_options = mesonlib.stringlistify(kwargs.get('cmake_options', []))
|
||||||
cm_int = CMakeInterpreter(new_build, subdir, subdir_abs, prefix, new_build.environment, self.backend)
|
cm_int = CMakeInterpreter(new_build, subdir, subdir_abs, prefix, new_build.environment, self.backend)
|
||||||
cm_int.initialise()
|
cm_int.initialise(cmake_options)
|
||||||
cm_int.analyse()
|
cm_int.analyse()
|
||||||
|
|
||||||
# Generate a meson ast and execute it with the normal do_subproject_meson
|
# Generate a meson ast and execute it with the normal do_subproject_meson
|
||||||
|
@ -2561,15 +2562,15 @@ external dependencies (including libraries) must go to "dependencies".''')
|
||||||
mlog.log()
|
mlog.log()
|
||||||
|
|
||||||
# Debug print the generated meson file
|
# Debug print the generated meson file
|
||||||
mlog.log('=== BEGIN meson.build ===')
|
mlog.debug('=== BEGIN meson.build ===')
|
||||||
from .ast import AstIndentationGenerator, AstPrinter
|
from .ast import AstIndentationGenerator, AstPrinter
|
||||||
printer = AstPrinter()
|
printer = AstPrinter()
|
||||||
ast.accept(AstIndentationGenerator())
|
ast.accept(AstIndentationGenerator())
|
||||||
ast.accept(printer)
|
ast.accept(printer)
|
||||||
printer.post_process()
|
printer.post_process()
|
||||||
mlog.log(printer.result)
|
mlog.debug(printer.result)
|
||||||
mlog.log('=== END meson.build ===')
|
mlog.debug('=== END meson.build ===')
|
||||||
mlog.log()
|
mlog.debug()
|
||||||
|
|
||||||
result = self.do_subproject_meson(dirname, subdir, default_options, required, kwargs, ast, cm_int.bs_files)
|
result = self.do_subproject_meson(dirname, subdir, default_options, required, kwargs, ast, cm_int.bs_files)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
project('cmake_set_opt', ['c'])
|
||||||
|
|
||||||
|
subproject('cmOpts', method: 'cmake', cmake_options: '-DSOME_CMAKE_VAR=something')
|
|
@ -0,0 +1,5 @@
|
||||||
|
cmake_minimum_required(VERSION 3.7)
|
||||||
|
|
||||||
|
if(NOT "${SOME_CMAKE_VAR}" STREQUAL "something")
|
||||||
|
message(FATAL_ERROR "Setting the CMake var failed")
|
||||||
|
endif()
|
Loading…
Reference in New Issue