aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/dependencies
diff options
context:
space:
mode:
authorDaniel Mensinger <daniel@mensinger-ka.de>2021-09-04 10:52:03 +0200
committerDaniel Mensinger <daniel@mensinger-ka.de>2021-10-06 16:43:59 +0200
commitf1614a60715ae23b801722d5104464bc594cb281 (patch)
tree55c39fce8bdcd860a6428af4b94e4ec976edb304 /mesonbuild/dependencies
parentecaa1d19eddcd39d6b62b20cf21cfba9bff5e801 (diff)
downloadmeson-f1614a60715ae23b801722d5104464bc594cb281.zip
meson-f1614a60715ae23b801722d5104464bc594cb281.tar.gz
meson-f1614a60715ae23b801722d5104464bc594cb281.tar.bz2
cmake: Warn if we could use IMPORTED CMake targets
Diffstat (limited to 'mesonbuild/dependencies')
-rw-r--r--mesonbuild/dependencies/cmake.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/mesonbuild/dependencies/cmake.py b/mesonbuild/dependencies/cmake.py
index ed89622..3fe5b8f 100644
--- a/mesonbuild/dependencies/cmake.py
+++ b/mesonbuild/dependencies/cmake.py
@@ -15,7 +15,7 @@
from .base import ExternalDependency, DependencyException, DependencyTypeName
from ..mesonlib import is_windows, MesonException, OptionKey, PerMachine, stringlistify, extract_as_list
from ..mesondata import mesondata
-from ..cmake import CMakeExecutor, CMakeTraceParser, CMakeException, CMakeToolchain, CMakeExecScope, check_cmake_args
+from ..cmake import CMakeExecutor, CMakeTraceParser, CMakeException, CMakeToolchain, CMakeExecScope, check_cmake_args, CMakeTarget
from .. import mlog
from pathlib import Path
import functools
@@ -446,6 +446,37 @@ class CMakeDependency(ExternalDependency):
# Failed to guess a target --> try the old-style method
if len(modules) == 0:
+ # Warn when there might be matching imported targets but no automatic match was used
+ partial_modules: T.List[CMakeTarget] = []
+ for k, v in self.traceparser.targets.items():
+ tg = k.lower()
+ lname = name.lower()
+ if tg.startswith(f'{lname}::'):
+ partial_modules += [v]
+ if partial_modules:
+ mlog.warning(textwrap.dedent(f'''\
+ Could not find and exact match for the CMake dependency {name}.
+
+ However, Meson found the following partial matches:
+
+ {[x.name for x in partial_modules]}
+
+ Using imported is recommended, since this approach is less error prone
+ and better supported by Meson. Consider explicitly specifying one of
+ these in the dependency call with:
+
+ dependency('{name}', modules: ['{name}::<name>', ...])
+
+ Meson will now continue to use the old-style {name}_LIBRARIES CMake
+ variables to extract the dependency information since no explicit
+ target is currently specified.
+
+ '''))
+ mlog.debug('More info for the partial match targets:')
+ for tgt in partial_modules:
+ mlog.debug(tgt)
+
+
incDirs = [x for x in self.traceparser.get_cmake_var('PACKAGE_INCLUDE_DIRS') if x]
defs = [x for x in self.traceparser.get_cmake_var('PACKAGE_DEFINITIONS') if x]
libs = [x for x in self.traceparser.get_cmake_var('PACKAGE_LIBRARIES') if x]