[CMake] using external library

Kai Wolf kai.wolf at gmail.com
Mon Mar 5 06:26:16 EST 2018


Steph,

what you want to achieve is better known as a *Superbuild* in the CMake
world. You have several options here, but the most basic one is probably
the following:

You setup another repository which only builds all the external
dependencies (such as Qt) and put them in a predefined place. In your
actual project you could refer to those prebuilt libraries using the
CMAKE_PREFIX_PATH variable, which should point to the install directory
from your external build. This way all the external stuff will only be
build once (probably via CI) and all your developers don't need to build
all the dependencies themselves.

Regarding the external package introspection. You could use find_package()
to check, if the correct version of your external library has been found on
the system and just use it. In any other case you check for the _NOTFOUND
variable and set it up locally, with the installation target pointing to
the CMAKE_PREFIX_PATH as mentioned above.

On a personal note, I would not use such a build system layout myself, as
it quickly becomes unclear from where a dependency is coming from and if
the dependency has all the required flags and settings as needed for the
software project. So you might want to reconsider a more cleaner layout.
For inspiration you may have a look at the CMake configuration of the
OpenChemistry project [1].

Greetings

[1] https://github.com/OpenChemistry/openchemistry

Kai Wolf

http://kai-wolf.me/
kai.wolf at gmail.com

2018-03-05 11:59 GMT+01:00 Stéphane Ancelot <sancelot at numalliance.com>:

> Hi,
>
> I need some external libraries in my project (eg a particular version of
> qt..)
>
> These external projects have been cloned locally , I could use
> ExternalProject_Add to clone it in my project.
>
> My major problem is that I will compile it each time and this is time and
> disk usage  consuming, for each users .
>
> I sounds to me better to have the compiled version available in my
> development system and use only header+binaries of this particular release.
>
> So, the scenario I would like to obtain :
>
> check if My Qt5 binaries are setted up in my system in a predefined
> directory (to not overlap with possible system one), if not setted up, then
>
> clone qt needed release and install it in my predefined system directory
> once (like /usr/local or a directory shared between users) .
>
> I hope you understood and it is enough clear ....
>
> Thanks
>
> Steph
>
>
>
>
>
>
> --
>
> 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/opensou
> rce/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> https://cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20180305/62be6afb/attachment.html>


More information about the CMake mailing list