[cmake-developers] CMakeFindDependencyMacro limitations

Stephen Kelly steveire at gmail.com
Thu Dec 24 07:07:08 EST 2015


Roger Leigh wrote:

> On 21/12/2015 15:07, Stephen Kelly wrote:
>> Roger Leigh wrote:
>>> I can understand why REQUIRED and related
>>> arguments are omitted--that is why find_dependency exists--but I'd quite
>>> like to be able to specify COMPONENTS where needed e.g. with FindBoost,
>>> and this is not currently possible.
>>
>> I don't remember whether this was discussed when designing
>> find_dependency. Perhaps COMPONENTS could be added to the macro now.
>
> Currently, for my own needs, COMPONENTS is the single missing piece.  If
> it would be possible to add this, it would certainly be very useful.
> 
> I'd be happy to provide a patch for COMPONENTS if you like.

I think the reason that the macro does not support COMPONENTS is that I 
don't understand how COMPONENTS is supposed to work. For example:

 find_package(Qt5 COMPONENTS Widgets)
 # Is Qt5_FOUND set to true or false?
 find_package(Qt5 COMPONENTS Quick)
 # ... what about now?

What does <Package>_FOUND ever mean if the find_package is called multiple 
times with different components? Does it mean anything?

Should CMake disallow multiple use of find_package with the same package and 
with different components?

If user code has 

 find_package(Qt5 COMPONENTS Widgets)
 find_package(FooBar REQUIRED)

and FooBarConfig.cmake has

 find_dependency(Qt5 COMPONENTS Quick)

then the if(Qt5_FOUND) in the macro will mean it will not try to find the 
Quick component.

So, there may be a need to establish a convention such as 

 <Package>_<Component>_FOUND

and check that for each component in the macro. 

You would also need to think through everything and find out whether that is 
really a full solution. I haven't thought more deeply about it than the 
above.

Note that the above example with Qt 5 can not currently happen in practice 
because the find_dependency macro does not support COMPONENTS, so config 
files must instead use 

 find_dependency(Qt5Quick)

if they want to use the macro currently. This is a good thing.

So, I would like to know if

* adding COMPONENTS support to the find_dependency macro is the right thing 
  to do
* or if the right thing to do is to move away from support for COMPONENTS 
  generally because of its messy semantics
* or if find_package should change to not support multiple calls for the 
  same package. 

I really don't know the answer - I think someone needs to do deep thinking 
about it.

I would prefer the macro not be changed before that deep thinking about 
COMPONENTS generally is done.

Thanks,

Steve.




More information about the cmake-developers mailing list