cmake: Added option for additional CMake args

pull/4969/head
Daniel Mensinger 6 years ago
parent d114d8446e
commit 3d7c50d109
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 11
      mesonbuild/cmake/interpreter.py
  2. 13
      mesonbuild/interpreter.py
  3. 3
      test cases/cmake/5 cmake options/meson.build
  4. 5
      test cases/cmake/5 cmake options/subprojects/cmOpts/CMakeLists.txt

@ -226,7 +226,7 @@ class CMakeInterpreter:
self.languages = []
self.targets = []
def configure(self) -> None:
def configure(self, extra_cmake_options: List[str]) -> None:
# Find CMake
cmake_exe, cmake_vers, _ = CMakeDependency.find_cmake_binary(self.env)
if cmake_exe is None or cmake_exe is False:
@ -249,7 +249,9 @@ class CMakeInterpreter:
elif len(exelist) == 2:
cmake_args += ['-DCMAKE_{}_COMPILER_LAUNCHER={}'.format(cmake_lang, exelist[0]),
'-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
mlog.log()
@ -276,10 +278,10 @@ class CMakeInterpreter:
if proc.returncode != 0:
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
# with the server doesn't work for some reason
self.configure()
self.configure(extra_cmake_options)
with self.client.connect():
generator = CMAKE_BACKEND_GENERATOR_MAP[self.backend_name]
@ -300,6 +302,7 @@ class CMakeInterpreter:
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 = [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
def analyse(self) -> None:

@ -2028,7 +2028,7 @@ permitted_kwargs = {'add_global_arguments': {'language', 'native'},
'both_libraries': known_library_kwargs,
'library': known_library_kwargs,
'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',
'suite', 'protocol'},
'vcs_tag': {'input', 'output', 'fallback', 'command', 'replace_string'},
@ -2548,8 +2548,9 @@ external dependencies (including libraries) must go to "dependencies".''')
with mlog.nested():
new_build = self.build.copy()
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.initialise()
cm_int.initialise(cmake_options)
cm_int.analyse()
# 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()
# Debug print the generated meson file
mlog.log('=== BEGIN meson.build ===')
mlog.debug('=== BEGIN meson.build ===')
from .ast import AstIndentationGenerator, AstPrinter
printer = AstPrinter()
ast.accept(AstIndentationGenerator())
ast.accept(printer)
printer.post_process()
mlog.log(printer.result)
mlog.log('=== END meson.build ===')
mlog.log()
mlog.debug(printer.result)
mlog.debug('=== END meson.build ===')
mlog.debug()
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…
Cancel
Save