Draft: Optional CMake target dependencies
3 unresolved threads
3 unresolved threads
Compare changes
Files
15+ 21
− 12
@@ -24,26 +24,35 @@ set_package_properties("LAPACK" PROPERTIES
Convert target dependencies to cmake generator expressions. If a downstream project does not find a dependency, the generator expression will generate an empty string. If the dependency is found, the generator expression will fill the corresponding dependencies for that target. This has the effect to make dependencies optional from the point of view of the upstream module. Notice that these generator expressions include the corresponding compiler definitions, thus, removing most of the #define
problems we have with #234 (closed).
Note: this is an experiment and is not yet fully tested!
Since
LAPACK_LIBRARIES
might be a list of libraries, this generator expression cannot be used. Try the following:Not so nice, though.
I think, it might be related to the escape of the ";" symbol, it seems that the string with multiple libraries inside the generator expression is somewhere interpreted as a list with two string:
The global property
ALL_PKG_LIBS
containsSo, it is a list of libraries, but the LAPACK library is a generator expression containing a list. The
<...>
symbols in cmake do not protect from list separation.One solution could be to store the
ALL_PKG_LIBS
not as a regular list, but our own "list" implementation with a custom element separator. This will be difficult. In the long run, I would really love to get rid of these global properties.Could be related to https://gitlab.kitware.com/cmake/cmake/-/issues/14353
But it is difficult to reproduce in a minimal example.
Yes, I realized about this problem with generators too. I think the solution might be to make an
INTERFACE
target with all of the dependencies of that library. That way one does not have to deal with lists of flags/definitions/includes. So ideally,ALL_PKG_INCS
/ALL_PKG_DEFS
/ALL_PKG_OPTS
would be empty andALL_PKG_LIBS
would be a list of targets. But I have to experiment a bit with that.Maybe something like a global accessible interface library, e.g.,
dune-all-packages
that is simply filled with all flags, options, and libraries, and then the user can simply link against this target.I tried this the other day but it does not entirely work because such library needs to be installed (because the main library may depend on it). The problem comes in downstream modules when you also want a library with the same name, and possible the same alias. Then it will conflict with whatever is defined upstream. But maybe there is a way to solve that.
how about
dune-common-all-packages
. The name does probably not solve all the problems. We need something like a forwarding target that does not show up as dependency itself. But I think this would only be possible if it would just define link libraries (via imported targets)we could maybe collect all packages in imported library that contain also the
HAVE_CXY
flags and then just collect these.Maybe !1207 (merged) can help. I want to get rid of the automatic linking of all packages. This requires the global ALL_PKG_LIBS properties and is the source of the above issue. If we make this more explicit, we don't have this problem anymore.
It would be great if we could get rid of these global states at least for the core modules. All of these experiments try to go on that direction. One concern I have is that I don't want to install targets that are only internal to a library and do not necessarily need to be exported. So there is a compromise to make there.
Now I see the problem. When I link
dunecommon
against mydune-common-all-packages
INTERFACE target I get the cmake errorexport called with target "dunecommon" which requires target "dune-common-all-packages" that is not in any export set.
Maybe we just to have to some extra quotation marks somewhere, e.g. in the
add_dune_all_flags
ordune_target_enable_all_packages
functions around the extracted global properties, e.g. link libraries.Can you push your experiment with
dune-common-all-packages
? I want to check it out. If it works when installing the target, it could be a good compromise while we get rid of global states/libraries.NVM I found it.