From 8e1c599c10679bdb1bdc050f110d53257e4d641c Mon Sep 17 00:00:00 2001 From: Daniel Mensinger Date: Sun, 4 Jul 2021 22:16:46 +0200 Subject: [PATCH] cmake: Improved error message for using dependency for executables fixes #8893 --- mesonbuild/modules/cmake.py | 2 ++ .../failing/116 cmake executable dependency/meson.build | 9 +++++++++ .../subprojects/cmlib/CMakeLists.txt | 5 +++++ .../subprojects/cmlib/main.c | 3 +++ .../failing/116 cmake executable dependency/test.json | 7 +++++++ 5 files changed, 26 insertions(+) create mode 100644 test cases/failing/116 cmake executable dependency/meson.build create mode 100644 test cases/failing/116 cmake executable dependency/subprojects/cmlib/CMakeLists.txt create mode 100644 test cases/failing/116 cmake executable dependency/subprojects/cmlib/main.c create mode 100644 test cases/failing/116 cmake executable dependency/test.json diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py index c390b01c3..cc259dcdc 100644 --- a/mesonbuild/modules/cmake.py +++ b/mesonbuild/modules/cmake.py @@ -109,6 +109,8 @@ class CMakeSubproject(ModuleObject): @stringArgs def dependency(self, state, args, kwargs): info = self._args_to_info(args) + if info['func'] == 'executable': + raise InvalidArguments(f'{args[0]} is an executable and does not support the dependency() method. Use target() instead.') orig = self.get_variable(state, [info['dep']], {}) assert isinstance(orig, dependencies.Dependency) actual = orig.include_type diff --git a/test cases/failing/116 cmake executable dependency/meson.build b/test cases/failing/116 cmake executable dependency/meson.build new file mode 100644 index 000000000..bfb03ef20 --- /dev/null +++ b/test cases/failing/116 cmake executable dependency/meson.build @@ -0,0 +1,9 @@ +project('cmake-executable-dependency', ['c', 'cpp']) + +if not find_program('cmake', required: false).found() + error('MESON_SKIP_TEST CMake is not installed') +endif + +cmake = import('cmake') +cmlib = cmake.subproject('cmlib') +maind = cmlib.dependency('main') diff --git a/test cases/failing/116 cmake executable dependency/subprojects/cmlib/CMakeLists.txt b/test cases/failing/116 cmake executable dependency/subprojects/cmlib/CMakeLists.txt new file mode 100644 index 000000000..006787986 --- /dev/null +++ b/test cases/failing/116 cmake executable dependency/subprojects/cmlib/CMakeLists.txt @@ -0,0 +1,5 @@ +cmake_minimum_required(VERSION 3.5) + +project(cmlib) + +add_executable(main main.c) diff --git a/test cases/failing/116 cmake executable dependency/subprojects/cmlib/main.c b/test cases/failing/116 cmake executable dependency/subprojects/cmlib/main.c new file mode 100644 index 000000000..9b6bdc2ec --- /dev/null +++ b/test cases/failing/116 cmake executable dependency/subprojects/cmlib/main.c @@ -0,0 +1,3 @@ +int main(void) { + return 0; +} diff --git a/test cases/failing/116 cmake executable dependency/test.json b/test cases/failing/116 cmake executable dependency/test.json new file mode 100644 index 000000000..d11cfa76b --- /dev/null +++ b/test cases/failing/116 cmake executable dependency/test.json @@ -0,0 +1,7 @@ +{ + "stdout": [ + { + "line": "test cases/failing/116 cmake executable dependency/meson.build:9:0: ERROR: main is an executable and does not support the dependency() method. Use target() instead." + } + ] +}