aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2020-08-03 17:48:12 +0200
committerDaniel Mensinger <daniel@mensinger-ka.de>2020-08-03 17:48:12 +0200
commit1c1ec9ff11a0f49c000b728781aab447a0776e2f (patch)
treecbbc920d4e55b16d0716b537552e3f40ea2b6e73
parent70edf82c6c77902cd64f44848302bbac92d611d8 (diff)
downloadmeson-1c1ec9ff11a0f49c000b728781aab447a0776e2f.zip
meson-1c1ec9ff11a0f49c000b728781aab447a0776e2f.tar.gz
meson-1c1ec9ff11a0f49c000b728781aab447a0776e2f.tar.bz2
cmake: resolve IMPORTED executables in custom commands (fixes #7509)
-rw-r--r--mesonbuild/cmake/interpreter.py17
-rw-r--r--mesonbuild/cmake/traceparser.py3
-rw-r--r--test cases/cmake/11 cmake_module_path/meson.build10
-rw-r--r--test cases/cmake/11 cmake_module_path/subprojects/cmMod/CMakeLists.txt15
-rw-r--r--test cases/cmake/11 cmake_module_path/subprojects/cmMod/gen.py9
5 files changed, 49 insertions, 5 deletions
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py
index f404109..9749c4c 100644
--- a/mesonbuild/cmake/interpreter.py
+++ b/mesonbuild/cmake/interpreter.py
@@ -651,7 +651,7 @@ class ConverterCustomTarget:
def __repr__(self) -> str:
return '<{}: {} {}>'.format(self.__class__.__name__, self.name, self.outputs)
- def postprocess(self, output_target_map: OutputTargetMap, root_src_dir: str, subdir: str, all_outputs: T.List[str]) -> None:
+ def postprocess(self, output_target_map: OutputTargetMap, root_src_dir: str, subdir: str, all_outputs: T.List[str], trace: CMakeTraceParser) -> None:
# Default the working directory to ${CMAKE_CURRENT_BINARY_DIR}
if not self.working_dir:
self.working_dir = self.current_bin_dir.as_posix()
@@ -694,7 +694,18 @@ class ConverterCustomTarget:
if not j:
continue
target = output_target_map.executable(j)
- cmd += [target] if target else [j]
+ if target:
+ cmd += [target]
+ continue
+ elif j in trace.targets:
+ trace_tgt = trace.targets[j]
+ if trace_tgt.type == 'EXECUTABLE' and 'IMPORTED_LOCATION' in trace_tgt.properties:
+ cmd += trace_tgt.properties['IMPORTED_LOCATION']
+ continue
+ mlog.debug('CMake: Found invalid CMake target "{}" --> ignoring \n{}'.format(j, trace_tgt))
+
+ # Fallthrough on error
+ cmd += [j]
commands += [cmd]
self.command = commands
@@ -969,7 +980,7 @@ class CMakeInterpreter:
object_libs = []
custom_target_outputs = [] # type: T.List[str]
for i in self.custom_targets:
- i.postprocess(self.output_target_map, self.src_dir, self.subdir, custom_target_outputs)
+ i.postprocess(self.output_target_map, self.src_dir, self.subdir, custom_target_outputs, self.trace)
for i in self.targets:
i.postprocess(self.output_target_map, self.src_dir, self.subdir, self.install_prefix, self.trace)
if i.type == 'OBJECT_LIBRARY':
diff --git a/mesonbuild/cmake/traceparser.py b/mesonbuild/cmake/traceparser.py
index a241360..fd16c75 100644
--- a/mesonbuild/cmake/traceparser.py
+++ b/mesonbuild/cmake/traceparser.py
@@ -269,6 +269,7 @@ class CMakeTraceParser:
args = list(tline.args) # Make a working copy
# Make sure the exe is imported
+ is_imported = True
if 'IMPORTED' not in args:
return self._gen_exception('add_executable', 'non imported executables are not supported', tline)
@@ -277,7 +278,7 @@ class CMakeTraceParser:
if len(args) < 1:
return self._gen_exception('add_executable', 'requires at least 1 argument', tline)
- self.targets[args[0]] = CMakeTarget(args[0], 'EXECUTABLE', {})
+ self.targets[args[0]] = CMakeTarget(args[0], 'EXECUTABLE', {}, tline=tline, imported=is_imported)
def _cmake_add_library(self, tline: CMakeTraceLine):
# DOC: https://cmake.org/cmake/help/latest/command/add_library.html
diff --git a/test cases/cmake/11 cmake_module_path/meson.build b/test cases/cmake/11 cmake_module_path/meson.build
index 2259268..75467e3 100644
--- a/test cases/cmake/11 cmake_module_path/meson.build
+++ b/test cases/cmake/11 cmake_module_path/meson.build
@@ -1,7 +1,7 @@
# We use Python3 as it's the only thing guaranteed to be available on any platform Meson can run on (unlike Zlib in linuxlike/13 cmake dependency).
project('user CMake find_package module using cmake_module_path',
- meson_version: '>= 0.50.0')
+ meson_version: '>= 0.55.0')
if not find_program('cmake', required: false).found()
error('MESON_SKIP_TEST cmake binary not available.')
@@ -15,3 +15,11 @@ endif
dependency('SomethingLikePython', required : true, method : 'cmake', cmake_module_path : 'cmake', modules: 'Python::Interpreter')
dependency('SomethingLikePython', method : 'cmake', cmake_module_path : ['doesNotExist', 'cmake'], modules: 'Python::Interpreter')
+
+# Test a custom target with Python::Interpreter in COMMAND
+cm = import('cmake')
+op = cm.subproject_options()
+op.add_cmake_defines({'CMAKE_MODULE_PATH': meson.source_root() / 'cmake'})
+sp = cm.subproject('cmMod', options: op)
+main = sp.target('main')
+test('main', main)
diff --git a/test cases/cmake/11 cmake_module_path/subprojects/cmMod/CMakeLists.txt b/test cases/cmake/11 cmake_module_path/subprojects/cmMod/CMakeLists.txt
new file mode 100644
index 0000000..88ba9bc
--- /dev/null
+++ b/test cases/cmake/11 cmake_module_path/subprojects/cmMod/CMakeLists.txt
@@ -0,0 +1,15 @@
+cmake_minimum_required(VERSION 3.5)
+
+project(cmMod)
+
+message(STATUS "CMAKE_MODULE_PATH: '${CMAKE_MODULE_PATH}'")
+
+find_package(SomethingLikePython REQUIRED)
+
+add_custom_command(
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/main.c"
+ COMMAND Python::Interpreter "${CMAKE_CURRENT_SOURCE_DIR}/gen.py"
+ WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}"
+)
+
+add_executable(main "${CMAKE_CURRENT_BINARY_DIR}/main.c")
diff --git a/test cases/cmake/11 cmake_module_path/subprojects/cmMod/gen.py b/test cases/cmake/11 cmake_module_path/subprojects/cmMod/gen.py
new file mode 100644
index 0000000..5c71646
--- /dev/null
+++ b/test cases/cmake/11 cmake_module_path/subprojects/cmMod/gen.py
@@ -0,0 +1,9 @@
+with open('main.c', 'w') as fp:
+ print('''
+#include <stdio.h>
+
+int main(void) {
+ printf(\"Hello World\");
+ return 0;
+}
+''', file=fp)