[CMake] What is the best way to handle Boost dependencies in a package config file

Ruslan Baratov ruslan_baratov at yahoo.com
Wed Jan 27 09:58:52 EST 2016


On 27-Jan-16 20:08, Johnson, Matt (GE Healthcare) wrote:
>> -----Original Message-----
>> From: Ruslan Baratov [mailto:ruslan_baratov at yahoo.com]
>> Sent: Wednesday, January 27, 2016 2:18 AM
>> To: Johnson, Matt (GE Healthcare)
>> Cc: cmake at cmake.org
>> Subject: Re: [CMake] What is the best way to handle Boost dependencies in
>> a package config file
>>
>> On 27-Jan-16 09:54, Johnson, Matt (GE Healthcare) wrote:
>>> I like package config files.  I want to use more of them.  However, I have a
>> dependency on boost.  While boost has a Find module, it doesn't have a
>> package config file.  I'm not going to be able to depend on the users of my
>> package building boost via cmake (also, is that still an active thing?).
>>> It seems like the best I could hope for is to generate the package config file,
>> then hack it up to deal with the boost stuff.  Has anyone already solved this
>> problem or have any tips?  I found this Hunter package manager
>> (https://urldefense.proofpoint.com/v2/url?u=https-
>> 3A__github.com_ruslo_hunter&d=CwIC-
>> g&c=IV_clAzoPDE253xZdHuilRgztyh_RiV3wUrLrDQYWSI&r=qts7iZJBjQRtedrrc
>> qcDRKGTou2a2ZKSs95InlFGa34&m=h5ntMfnYSIOG1mQp_twkUPunK5Nz0q9
>> HBqa7Ld4B_hs&s=zi9sk8NwKokHEqrLyGA5a_yrRxLdHF9P7ID23wgrWPY&e=
>> ), but it seems a bit heavyweight when all I want is boost.
>> --
>>> Also, I can't have my build system going out and downloading the packages
>> - they all have to come from an internal source.
>> Just for your information you can use "file://" links instead of regular
>> "https://urldefense.proofpoint.com/v2/url?u=http-3A__&d=CwIC-
>> g&c=IV_clAzoPDE253xZdHuilRgztyh_RiV3wUrLrDQYWSI&r=qts7iZJBjQRtedrrc
>> qcDRKGTou2a2ZKSs95InlFGa34&m=h5ntMfnYSIOG1mQp_twkUPunK5Nz0q9
>> HBqa7Ld4B_hs&s=ts63TtZeGvflnLyyJ8pKESTjxabuzNCPmS0fGn_1L7E&e= " in
>> both hunter.cmake and HunterGate so there is no need to "go out" - you can
>> be completely offline.
>>
>> Ruslo
> Ruslo - thanks for that.  I'm seriously going to look into Hunter more.  From my cursory glance at it, it's a seriously impressive bit of cmake scripting.
--

>
> Can  I ask you a few follow ups?
> 1. in the case of boost, what it is doing is using the find package module, then creating import targets based off the information.  Correct?
In general yes, but also some information passed from 
ExternalProject_Add recipe, like optional dependency. So it differs from 
approach "just add BoostConfig.cmake file" after boost installed.
Templates:
* 
https://github.com/ruslo/hunter/blob/master/cmake/templates/BoostConfig.cmake.in
* 
https://github.com/ruslo/hunter/blob/master/cmake/templates/BoostBZip2Dependency.cmake.in 
(optional boost.iostreams -> bzip2 dependency)

> 2. If I require a newer version of boost than what is listed in the gate file, I'd need to  update hunter.cmake and HunterGate,  correct?
URL/SHA1 of HunterGate command doesn't hold version of Boost to be 
precise. It holds version of archive with several versions of Boost 
(Boost/hunter.cmake: 1.55, 1.56, ...) and default version 
(configs/default.cmake: 1.58). User can choose non-default version by 
adding custom local config.cmake file: 
https://github.com/ruslo/hunter/wiki/example.custom.config.id. If you 
need version that is not listed in Boost/hunter.cmake you have to add it 
to Boost/hunter.cmake and create new archive. There is feature request 
that can allow to do it locally so it will be improved in future.

> 3. If I want to distribute my package to others, they too would need  to use Hunter, correct?  Since boost doesn't have a package config file in  its distribution, the dependency targets (e.g. Boost::regex) wouldn't exist on their system)  Any tips on this?
Well somebody have to install such extra code with Boost::* targets 
anyway, the easiest way is to delegate this job to Hunter. Also if you 
add your package to Hunter archive then users can add your package just 
by `hunter_add_package(Foo)` without even knowing about Boost and type 
of Boost targets. This is package distribution design.

> Thanks again for your hard  work on  Hunter.  I've done a bit of cmake to download and install some dependencies in the past.  Yours is WAY nicer than what I came up with.
>
> Matt

Thanks, Ruslo


More information about the CMake mailing list