[CMake] Is there a way to delay "find_package" until link-time when the package is actually needed?

Timothy Wrona tjwrona1992 at gmail.com
Thu Feb 14 12:21:43 EST 2019


I have a collection of interdependent CMake projects (lots of legacy code)
that I want to convert to using CMake targets for linking. The code is
built in such a way that all projects run cmake generation, then all
projects build, then all projects link.

I would like to export a CMake target from one of the projects and link to
it in another, but the issue is the project I am exporting from runs its
cmake generation AFTER the project I am linking the target in. This causes
"find_package" to fail because the target has not been exported yet, but
realistically the exported target is not needed until link-time.

Is there a way to delay "find_package" to not look for the package until
link-time? At link-time the package will have been exported already and if
"find_package" was not called until then, it would be found successfully
and the target could be pulled in and linked to.

Thanks,
Tim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190214/a361b7c6/attachment.html>


More information about the CMake mailing list