Use cmake instead of pkg-config to find packages in dunecontrol
The library pkg-config
is used to distinguish if a module is already installed or not. With this information, it gives precedence for the modules to include in case of double definitions.
The issue with pkg-config
-
De-facto dependency: The website hints that
pkg-config
is an optional dependency. However, the reality is that using DUNE withoutdunecontrol
requires you to know how several internal things about DUNE. So, most of our users (specially newcomers), requiredunecontrol
to use DUNE at all Now, the problem is thatdunecontrol
depends inpkg-config
even though all of our documentations say its optional. I have fallen into this trap several times when creating minimal setups. -
Finds packages the
pkg-config
way: It tries to find information extracting information from the.pc
files. But this is not how the build system in dune works. Our build system is built with cmake, that is to say that if cmake cannot find a package, it doesn't matter how does the.pc
file looks like. In other words, that's just a proxy for the real way to find dune modules.
Proposal
Make dune control find packages using cmake and use this to distinguish if a module is installed or not.
Merge request reports
Activity
added buildsystem label
assigned to @santiago.ospina
requested review from @simon.praetorius
- Resolved by Santiago Ospina De Los Ríos
I like this proposal very much. Did you notice any difference in the time for dunecontrol to run? I guess, cmake scripts sre more expensive than pkg-config calls? Maybe not, because only a minimal script is run and not the full cmake configuration.
Another improvement could be to also remove
pkg-config
fromduneproject
, but it needs a bit more complicated logic to get the dependencies right. I think we can at least pass this as it is now.Just for the record, the function should look something like this:
cmake_package_dependencies(){ depends="$CMAKE -DMODULE=$1 -P << EOF 2>/dev/null find_package(${MODULE} REQUIRED QUIET) foreach(_DUNE_DEPEND ${DUNE_DEPENDS}) string(REGEX REPLACE \"\\(\" \"\" REQF1 ${_DUNE_DEPEND}) string(REGEX REPLACE \"\\)\" \"\" LR ${REQF1}) list(APPEND deps ${LR}) endforeach() message(NOTICE ${deps}) EOF" for pkg in $depends; do depends="$depends `cmake_package_dependencies $pkg`" done echo $depends }
but I don't have time to test it thoroughly now.
It seems to work in my simple tests. But since this is a tool used everywhere, maybe we need a larger test group. In particular, @markus.blatt could you tests this in your applications?
Also @christi. I think you have a better overview of the
dunecontrol
script.
To me pkg-config is outdated and CMake took over with its config files. In future, Common Package Specification (CPS) will become part of the C++ standard and we might move again.
@santiago.ospina I saw that there is also some pck-config calls in the Python bindings: https://gitlab.dune-project.org/core/dune-common/-/blob/master/python/dune/common/module.py I can't see directly how necessary the usage there is but it doesn't seem to be guarded against pck-config not being present, too.
ah you don't remove all usage yet with this MR. So then just for the record.
Edited by Timo Koch