[CMake] dependencies between external projects (not DEPENDS)

Nicholas Braden nicholas11braden at gmail.com
Wed Aug 17 07:09:26 EDT 2016


Usually there would be variables like A_ROOT which allow the
FindA.cmake module being used by B to correctly find everything. If
there isn't, you'd have to write your own FindA.cmake module in either
case. If you can't modify B, you could use the patch step of the
external project to replace the broken FindA.cmake with your modern
FindA.cmake with minimal effort while you wait for B to accept your
pull request. The takeaway is, if B doesn't have a way for you to say
"Look for A here first/only", that's a bug in B's FindA module.

As for recursive dependencies, there is the CMakeFindDependencyMacro
module, but you have to be careful about the can of worms you are
opening - you'd want to only find versions which are binary compatible
and also deal with cases of the wrong version of the package having
already been found. Sometimes it's easier to just tell the client to
find the dependencies for you, rather than trying to do it for them
and potentially getting it wrong. I honestly don't know what the best
approach is here.

On Mon, Aug 15, 2016 at 10:56 AM, Neil Carlson <neil.n.carlson at gmail.com> wrote:
> I'm struggling with how to handle dependencies between external projects in
> a
> superbuild.  The issue is different than simply ensuring that one gets built
> before
> another using the DEPENDS keyword -- that's trivial.
>
> Suppose I have two external libraries A and B, where B depends on A.  It is
> not
> always possible to correctly define variables like A_LIBRARIES that feed
> into the
> externalproject_add for B that anticipate what will come out of the A
> configure/build.
> There are sometimes additional link libraries that only come to light after
> A is
> actually configured.
>
> How do people handle these situations?  I'm thinking of a multi-pass
> approach
> where one runs cmake/make twice.  The first installs A skipping the
> dependent B.
> The second builds B (skipping a found A) using correctly set variables from
> a
> FindA module.
>
> Incidentally, is it kosher to have a Find module invoke a find_package?
> There are
> examples in of this in standard Find modules.  This creates problems in the
> superbuild context, where say A is found, but rejected by the superbuild
> because
> of missing features, for example, but FindB finds A and uses it.
>
> Thanks for your advice.
>
> -Neil
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list