CMake: Find Thirdparty like QT

Posted by : MOnsDaR | Donnerstag, 20. Mai 2010 | Published in

Almost every project depends on Thirdparty software like Boost or QT. For building those projects, the compiler and linker need to know where they could find includes and which libraries they should link. But how should the programmer should know where the user has installed his Thirdparty-components?

CMake provides the command find_package().

This command uses special find-scripts called findPackageName.cmake and fills standard-variables which then give information about where and if libs ands includes are installed. Find-scripts are located at /usr/share/cmake/Modules on Linux systems. CMake already brings with scripts for the most used packages. A lot of components install their own scripts.

There are additional parameters for find_package() which allow the programmer to just search for certain versions or subcomponents of the Thirdparty. There also is a flag REQUIRED which will cancel the build-process if the requested Thirdparty is not installed.

Because code says more then thousand words:

find_package(Qt4 4.4.3 COMPONENTS QtCore QtGui QtXml REQUIRED ) include(${QT_USE_FILE})
add_executable(myexe main.cpp)
target_link_libraries(myexe ${QT_LIBRARIES})

 

The source searches for the QT4-components QtCore, QtGui and QtXml in version 4.4.3 and cancels, if they are not installed. The variables QT_USE_FILE and QT_LIBRARIES will be filled and could be used for the further build-process. There are a lot of other variables besides that two. For a complete list take a look at the CMake documentation.

(0) Comments

Leave a Response