[CMake] How do you handle recursive dependencies in CMake

Raymond Wan rwan.work at gmail.com
Thu Jun 30 06:10:21 EDT 2016


Hi Sven,


On Thu, Jun 30, 2016 at 4:59 PM, Sven Baars <s.baars at rug.nl> wrote:
> This is a reply to the options that Ray gave. Here I will use the
> package dependencies C -> B -> A{1,2}:


Well, I presented some options to you.  Perhaps there are others, but
if none of them are right for you then there's nothing more I can add,
I think.


> On supercomputers it is very common that every library on the system is
> installed in a different directory. This is so every user can load their
> own version of the library without breaking the system for others.


Sure.  So, during the CMake run, you can set CMAKE_INSTALL_PREFIX to
be something like ~/lib/ or ~/mylib/ or whatever.


> Therefore, you will never find libraries that are installed in the
> standard system directories where CMake looks for the libraries. By


Well, I wasn't suggesting that you use Find_Package as-is.  I mean the
phrase "CMake looks for the libraries" isn't quite correct here since
its behaviour is affected by the Find_Package's implementation.

Presumably, you will need to write your own for the modules you're
working with.  One person would write it and this file would be
shared.

How it would work is "something like" (i.e., you need to look at how
it works yourself) the Boost library.  With that, you can set
BOOST_ROOT to override the system-installed version.  (Take a look at:
 https://cmake.org/cmake/help/v3.3/module/FindBoost.html)

I think I said this early on, but perhaps I didn't explain it very well.

Thus, each user would set an environment variable that would affect
the search path of this Find_Package that you wrote.  If this is
troublesome, then you can add some favourite paths like ~/lib/ and
~/mylib/ as default paths to the search first.

I think it is a bit unreasonable for CMake to "automatically" know
where libraries are stored for each user other than performing a
recursive search down ~/ .  (I suppose that's possible.)  To reduce
the search space for binary programs that we've installed in ~/, we
would set the PATH variable.  I don't think it's that much different
from setting something like BOOST_ROOT and then getting a Find_Package
that you've written to use this as the starting point for a search.

I mean, it seems strange to expect CMake to be able to find archive
files by itself but, by default, we do not expect the same for
executable files...

Ray


More information about the CMake mailing list