[cmake-developers] Adding automatic checks for required targets in target-export files ?
Stephen Kelly
steveire at gmail.com
Mon Feb 11 13:52:13 EST 2013
Alexander Neundorf wrote:
> Another thing came to my mind.
> Let's say kguiaddons depends on kconfig, so it will do
> find_package(kconfig)
> I guess it should not search the packages kconfig depends on, but rely on
> kconfigConfig.cmake doing that.
Yes.
>
> So far, so good.
>
> Now, if we have some optional libraries used in let's say kguiaddons, this
> may give a dynamic list of targets we depend on in the Config.cmake file.
Yes.
> So I guess we have to propagate the used targets/package down to the top
> level CMakeLists.txt, which generates the Config.cmake file, and there
> configure some code into the Config.cmake file which can check (and
> find_package()) the actually used targets as necessary...
Yes. There probably doesn't have to be much propagation. Let's be concrete
and pretent that kguiaddons has a hard dependency on qtgui, and an optional
public dependency on qtsvg. The top-level CMakeLists file looks like this:
find_package(Qt5Gui REQUIRED)
find_package(Qt5Svg OPTIONAL)
add_subdirectory(src)
set(find_package_string "find_package(Qt5Gui REQUIRED)\n")
if(Qt5Svg_FOUND)
# Required by downstreams because we were (optionally) built with it
set(find_package_string "find_package(Qt5Svg REQUIRED)\n")
endif()
# Really a wrapper macro is used
configure_file(kguiaddonsConfig.cmake.in kguiaddonsConfig.cmake)
All dependencies generated in the config file should be required, because we
can determine at upstream-cmake-time whether it really is required.
>
>
> Independent from that, as a safeguard, the exported target files should in
> some way make sure that they will really work.
Sure, why not :).
> They now have already checks that the files their own libraries references
> actually exist, they have a check that the imported targets from within
> the same project exist, but they do not yet have a check that the needed
> imported targets from other projects exist too.
Correct.
> This should be there to make sure cmake report "NOT FOUND" at cmake time
> when a needed target is missing instead of failing with "could not find -
> lkcoreaddons" at link time.
Makes sense to me, and should be reasonably possible.
Thanks,
Steve.
More information about the cmake-developers
mailing list