[CMake] FindQt4.cmake to automatically include QT_USE_FILE?

Michael Wild themiwi at gmail.com
Tue Jun 7 09:51:09 EDT 2011


On 06/07/2011 03:38 PM, Bjørn Forsman wrote:
> Thanks for a quick reply!
> 
> On 7 June 2011 14:52, Michael Wild <themiwi at gmail.com> wrote:
>> On 06/07/2011 02:20 PM, Bjørn Forsman wrote:
>>> As far as I can tell, all Qt programs built with CMake must include
>>> QT_USE_FILE after find_package(). So why doesn't FindQt4.cmake simply
>>> include QT_USE_FILE itself? Is there maybe a use case where
>>> QT_USE_FILE is *not* wanted?
>>
>> If you don't care for the macros and want to set up the
>> include-directories and defines yourself, no.
> 
> Ok, guess I haven't had any use for that so far. Examples of when it
> may be useful are welcome.
> 
> But, wait...isn't that the whole point of find_package()? To set up
> variables containing necessary includes and libs? It seems
> FindWt4.cmake is special in this case, needing one extra step.
> 
>> Also, it is common to
>> find_package(Qt4) in the top-level CMakeLists.txt file, but then include
>> QT_USE_FILE only in specific subdirectories, where Qt is actually used.
> 
> Why not put find_package(Qt4) in the sub directories where it is actually used?
> 
> Best regards,
> Bjørn Forsman

And if it is used in multiple subdirectories?

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.

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.

Michael


More information about the CMake mailing list