[CMake] Using find_package() portably?

Konstantin Tokarev annulen at yandex.ru
Tue Nov 21 06:36:57 EST 2017



21.11.2017, 13:45, "Johannes Zarl-Zierl" <johannes.zarl-zierl at jku.at>:
> Hi,
>
> I thought you might want some context for the suggestions:
>
> On Dienstag, 21. November 2017 11:45:43 CET Konstantin Tokarev wrote:
>>  1) add instruction how to install dependencies
>
> This is what many/most projects do, and it works reasonably well.
> Advantages:
>  - You don't clutter your project with dependencies
>  - People on each platform already know how to install dependencies
>  - You don't complicate things for package maintainers
> Disadvantages:
>  - No automatic dependency resolution
>
>>  2) use hand-made script or more complex solution to automate dependency
>>  installation, or
>
> Hand-made scripts are often a maintenance nightmare and hard to get right for
> all platforms. The One True Way(TM) would be a so-called "super-build", i.e. a
> CMake project that uses external_project() to build your project along with
> its dependencies.

FWIW I've seen many projects that provide scripts or one-liners how to install all
dependencies on popular systems, and if things are readily available or otherwise pre-built
and downloadable from central place, it's not hard to maintain, at least when number of
dependencies is small

Examples:

1. (Not related to cmake, just to show idea):
https://wiki.qt.io/Building_Qt_5_from_Git#Linux.2FX11
- lists packages which you need to install on different distros on wiki page

2. https://trac.webkit.org/browser/webkit/trunk/Tools/gtk/install-dependencies
- similar thing but automated

3. https://trac.webkit.org/browser/webkit/trunk/Tools/Scripts/update-webkit-wincairo-libs.py
- downloads and unpacks zip file with all dependencies into fixed location

>
>>  3) avoid using find_package() st all
>
> That's the first time I've heard that suggestion. I'm not sure if this will
> ease your pain ;-)

I've meant by using things like ExternalProject, or from your point 4, or when
using other metabuilders. When all dependencies are in known locations,
you don't really need to use find_package anymore.

Though It may be handy though if you allow building with both external and
internal dependencies, e.g. if you develop open source project distributors
will be reluctant to include it if it can use bundled dependencies only.

>
> 4) Shipping the dependency with your project (not using external_project)
> This can sometimes be useful, but you should carefully consider the
> implications beforehand to see if it's worth it for your project. As a rule of
> thumb: don't do this if the dependency is readily available and/or big.
>
> Cheers,
>   Johannes
>
> --
>
> 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

-- 
Regards,
Konstantin


More information about the CMake mailing list