diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py index 1962e062c..c0c0a4489 100644 --- a/mesonbuild/cmake/interpreter.py +++ b/mesonbuild/cmake/interpreter.py @@ -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: diff --git a/mesonbuild/interpreter.py b/mesonbuild/interpreter.py index 6df7ae174..efed755e2 100644 --- a/mesonbuild/interpreter.py +++ b/mesonbuild/interpreter.py @@ -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) diff --git a/test cases/cmake/5 cmake options/meson.build b/test cases/cmake/5 cmake options/meson.build new file mode 100644 index 000000000..3b58515a0 --- /dev/null +++ b/test cases/cmake/5 cmake options/meson.build @@ -0,0 +1,3 @@ +project('cmake_set_opt', ['c']) + +subproject('cmOpts', method: 'cmake', cmake_options: '-DSOME_CMAKE_VAR=something') diff --git a/test cases/cmake/5 cmake options/subprojects/cmOpts/CMakeLists.txt b/test cases/cmake/5 cmake options/subprojects/cmOpts/CMakeLists.txt new file mode 100644 index 000000000..62b5990e5 --- /dev/null +++ b/test cases/cmake/5 cmake options/subprojects/cmOpts/CMakeLists.txt @@ -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()