-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CMake find_package dependency backend #4444
Conversation
mesonbuild/dependencies/base.py
Outdated
if not self.silent: | ||
if cmakebin and invalid_version: | ||
mlog.log('Found CMake:', mlog.red('NO'), '(version of', mlog.bold(cmakebin.get_path()), | ||
'is', mlog.bold(cmvers) ,'but version', mlog.bold(CMakeDependency.class_cmake_version), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Flake8]
[E231] missing whitespace after ','
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I missed that. Should be fixed now.
mesonbuild/dependencies/base.py
Outdated
if not self.silent: | ||
if cmakebin and invalid_version: | ||
mlog.log('Found CMake:', mlog.red('NO'), '(version of', mlog.bold(cmakebin.get_path()), | ||
'is', mlog.bold(cmvers) ,'but version', mlog.bold(CMakeDependency.class_cmake_version), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[Flake8]
[E203] whitespace before ','
The last time this was discussed someone found out that CMake's facility for giving out dependency information for third parties was deprecated. Because of that we chose not to support it. Is this still the case or is the mechanism this PR is using guaranteed to remain supported for the foreseeable future? |
Yes, it is deprecated but this is not a problem since the changes do not rely on one line pkg-config like output. Instead, the traced output CMake generates is parsed. Also, the
Should the The only real problem would be the removal of the |
Should This option would, of course, be a lot slower than the |
@jpakkane @mensinda, here is the discussion. Then I tried to look if I could generate a custom CMakeLists printing out find_package() results, I didn't find an easy solution and didn't like the fact that this would depend on CMake internal stuff. Looking your PR, it seems it support the version arg which is nice. |
I did some further testing with the It is definitively possible to use the standard The dependency detection process would then be:
I have tested this on Linux with CMake 3.12.3 and 3.4.0. It technically also works for CMake versions below 3.4.0, but the variables are not expanded in the trace output (even with The @jeandet yes, extracting the version from the CMake scripts is supported. It is generally possible to extract the content of (almost) any variable and any target property. |
I managed to test the Some benchmarks with and without tricking CMake:
Should I keep the
Also, are there other variables and/or target properties that should be extracted? |
ci/appveyor-install.bat
Outdated
@@ -17,6 +17,7 @@ libgtk3-devel,^ | |||
ninja,^ | |||
python3-pip,^ | |||
vala,^ | |||
cmake,^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are alphabetically sorted. Please add cmake in the appropriate place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be fixed with the last commit
Any opinions regarding the points from above? |
I have replaced the One CMake "build directory" is created for each dependency. All build directories have a |
What is the purpose of installing the CMake file? |
The CMake file is used as a "CMake project" to determine the dependency. This file is copied into each CMake "build" directory (in |
LGTM. Is this ready to merge or are there still open questions? |
Yes, it is ready to merge and there are no open questions on my part. |
The clause 'with pkg-config if possible, as a framework (OSX only), and with library-specific fallback detection logic otherwise' in the description of |
Updated the documentation. Are there any other issues? |
This seems to ⚔️ conflict now... |
Fixed the conflicts by rebasing. |
All CI checks are passing again. Should be ready to merge. |
I think the failure here was because |
Right, but having the dependency detection fail just because CMake is unable to automatically use a different generator is still bad, so I think the change should stay. But I agree that this commit fixes a very niche issue. |
Thanks. |
This seems to have a path where an unbound variable exception occurs, see: https://travis-ci.org/jon-turney/meson-corpus-test/jobs/458904519#L643 |
I agree. My point was merely that the comment alludes to mysterious "reasons" without details. |
Oh. I missed that. Should be fixed with #4549 |
After fixing the above, there is now a different failure https://travis-ci.org/jon-turney/meson-corpus-test/jobs/460388821#L552 The problematic line is:
I'm guessing the type of the returned object has changed, from a not-found pkgconfig dependency to a not-found cmake dependency. per http://mesonbuild.com/Reference-manual.html#dependency-object, it's an error to call |
What would be the desired behavior in this case? The main problem here is that with Maybe enforcing |
If CMake does not provide a way to get equivalent data, then there's nothing else you can realistically do. |
I do have access to every variable CMake has ever set, but this would be completely different from My idea would be to restrict the use of |
Waitaminute: udevdir = dependency('udev', required : false).get_pkgconfig_variable('udevdir') How has this passed earlier? It should fail because you are trying to get a variable of a dependency that does not exist. The documentation says:
That should be an error because a not-found dependency is not really a pkg-config dependency. I checked the code and in I guess the obvious follow up question is whether we can change this or do we need to preserve the current behaviour to keep backwards compatibility. |
I think that's what I wrote...
Without a line number or commit I have no idea what you are blaming me for. Regardless... it doesn't matter what Maybe it should return a
Yeah. This looks dangerous, but I haven't looked at what casync does with this value. There's possibly another bug here in that calling |
Something else which could do with a bit of polish: https://travis-ci.org/jon-turney/meson-corpus-test/jobs/461405180#L522
The actual error here is due to a package dependency change, but the way it's reported is very confusing. This is a consquence of some logic in I'm not sure what the correct thing to do here is. meson/mesonbuild/dependencies/base.py Lines 2071 to 2080 in 0c23e65
|
Added a CMake dependency method based on
the CMakea--find-package
option
CMakeLists.txt
and the CMake trace output (--trace --trace-expand
).To extract the necessary information from the CMake trace a few CMake
functions were implemented to detect all variables and targets:
set()
unset()
string()
-- only partiallyadd_executable()
-- only forIMPORTED
targetsadd_library()
-- only forIMPORTED
targetsadd_custom_target()
-- only looks at the target nameset_property()
set_target_properties()
With these functions both the old-style
<NAME>_LIBRARIES
variables, as well as imported targets, and version detection are supported.
Also, the CMake method will be used if the for the
auto
method when pkg-config fails.Example:
CMake is automatically used after
pkg-config
fails whenno
method
was provided in the dependency options.The minimum CMake version is 3.4 because the variables are not expanded in older
versions in the trace output.
Extracted CMake trace information
Variables
PACKAGE_FOUND
PACKAGE_VERSION
<NAME>_VERSION
<NAME>_VERSION_STRING
PACKAGE_INCLUDE_DIRS
PACKAGE_LIBRARIES
Target properties
INTERFACE_INCLUDE_DIRECTORIES
INTERFACE_COMPILE_DEFINITIONS
-D
)INTERFACE_COMPILE_OPTIONS
IMPORTED_CONFIGURATIONS
INTERFACE_LINK_LIBRARIES
IMPORTED_LINK_DEPENDENT_LIBRARIES
IMPORTED_LOCATION