diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2021-09-04 10:52:03 +0200 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2021-10-06 16:43:59 +0200 |
commit | f1614a60715ae23b801722d5104464bc594cb281 (patch) | |
tree | 55c39fce8bdcd860a6428af4b94e4ec976edb304 | |
parent | ecaa1d19eddcd39d6b62b20cf21cfba9bff5e801 (diff) | |
download | meson-f1614a60715ae23b801722d5104464bc594cb281.zip meson-f1614a60715ae23b801722d5104464bc594cb281.tar.gz meson-f1614a60715ae23b801722d5104464bc594cb281.tar.bz2 |
cmake: Warn if we could use IMPORTED CMake targets
-rw-r--r-- | mesonbuild/dependencies/cmake.py | 33 | ||||
-rw-r--r-- | test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake | 2 | ||||
-rw-r--r-- | test cases/linuxlike/13 cmake dependency/test.json | 10 |
3 files changed, 43 insertions, 2 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] diff --git a/test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake b/test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake index e12aeb9..938c706 100644 --- a/test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake +++ b/test cases/linuxlike/13 cmake dependency/cmake_fake1/cmMesonTestF1Config.cmake @@ -4,6 +4,8 @@ if(ZLIB_FOUND OR ZLIB_Found) set(cmMesonTestF1_FOUND ON) set(cmMesonTestF1_LIBRARIES ${ZLIB_LIBRARY}) set(cmMesonTestF1_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR}) + + add_library(CMMesonTESTf1::evil_non_standard_trget UNKNOWN IMPORTED) else() set(cmMesonTestF1_FOUND OFF) endif() diff --git a/test cases/linuxlike/13 cmake dependency/test.json b/test cases/linuxlike/13 cmake dependency/test.json index a125536..1505986 100644 --- a/test cases/linuxlike/13 cmake dependency/test.json +++ b/test cases/linuxlike/13 cmake dependency/test.json @@ -2,5 +2,13 @@ "env": { "CMAKE_PREFIX_PATH": "@ROOT@/cmake_fake1;@ROOT@/cmake_fake2:@ROOT@/cmake_pref_env", "PATH": "@ROOT@/cmake_fake3/bin:@PATH@" - } + }, + "stdout": [ + { + "line": "WARNING: Could not find and exact match for the CMake dependency cmMesonTestF1." + }, + { + "line": " ['CMMesonTESTf1::evil_non_standard_trget']" + } + ] } |