Posts mit dem Label CMake werden angezeigt. Alle Posts anzeigen
Posts mit dem Label CMake werden angezeigt. Alle Posts anzeigen

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.

CMake und CTest - 'make test' geht nicht

Posted by : MOnsDaR | Donnerstag, 18. Februar 2010 | Published in

Will man sein Programm mit Hilfe des in CMake eingebauten Testtools CTest testen, kann man schnell über folgenden Fehler stolpern:

Nachdem man mit den Befehlen
enable_testing()
add_test(testName testExecutable)
die Tests definiert hat, kann man wie gewohnt das Projekt generieren.
Auch ein Aufruf von make und make install läuft fehlerfrei ab.

Doch leider ergibt die Eingabe von make test nicht das gewünschte Ergebnis - Es passiert einfach garnichts.

Dies liegt wahrscheinlich daran, dass die Tests nicht in der obersten CMakeLists.txt aufgerufen werden. Der Befehl
enable_testing()
muss allerdings in der Root-CMakeLists.txt stehen, sonst wird CTest nicht ausgeführt und make test führt somit ins leere.