[CMake] FindQt4.cmake to automatically include QT_USE_FILE?

Marcus D. Hanwell marcus.hanwell at kitware.com
Tue Jun 7 13:12:46 EDT 2011


2011/6/7 Michael Wild <themiwi at gmail.com>:
> On 06/07/2011 06:23 PM, Bjørn Forsman wrote:
>> 2011/6/7 Michael Wild <themiwi at gmail.com>:
>>> On 06/07/2011 03:38 PM, Bjørn Forsman wrote:
>>>> Why not put find_package(Qt4) in the sub directories where it is actually used?
>>>
>>> And if it is used in multiple subdirectories?
>>
>> What's bad about that? (Sorry, I really don't know).
>
> Then you would need to call find_package in all the subdirectories, with
> all the work that goes along with that.

Virtually everything is cached AFAIK, there is minimal cost in multiple calls.
>>
>>> FindXXX.cmake modules should only do the minimum, i.e. finding the
>>> required libraries and include-directories, setting XXX_FOUND,
>>> XXX_INCLUDE_DIRS and XXX_LIBRARIES. Anything more complex, e.g. calling
>>> add_definitions(), include_directories(), function(), macro() etc.
>>> should go into a UseXXX.cmake module.
>>
>> Ok, I didn't know about that policy.
>>
>>> If you find a FindXXX.cmake module that calls add_definitions(),
>>> include_directories(), link_libraries() or some such, it is broken and
>>> needs to be fixed.
>>
>> Broken because of the above defined policy? Or of technical reasons?
>> Sorry, but I still don't see the reason why the current find_package +
>> use_file is better than a find_package that includes the use_file
>> itself.
>
> If the FindXXX.cmake file called add_definitions(),
> include_directories() et al., that could be potentially harmful. Some
> sources might required that some define is not set, or a wrong header
> file might be #include'ed (thing of all the different X.h that exist).
> FindXXX.cmake modules should just define a few variables, *not* change
> the build system. That's the caller's responsibility, either by calling
> the functions himself or by including the UseXXX.cmake (if provided).
>
It could perhaps go one step further and populate QT_LIBRARIES with
the requested components.
>>
>> What I see is that current usage goes something like this:
>>
>> 1) find_package(Qt4 REQUIRED) at the top level
>> 2) subdirs that actually need Qt: set what modules to enable/disable
>> and then include the use_file.
>>
>> How about doing it this way:
>> 1) subdirs that actually need Qt: call find_package(Qt4 COMPONENTS
>> QtCore [...] REQUIRED) with the modules it needs.
>>
>> Is there a problem with this approach? Other than breaking the policy ;-)
>
> In principle not, except that all these redundant find_path() and
> find_library() calls will incur some slight overhead.
>
Aren't they very minimal as they see that the variable is set and return?

Marcus


More information about the CMake mailing list