Qt Compilation
← Installation von Qt | ● | Spezialisierung einer Qt Klasse →
To compile our Qt examples with CMake we create a meta project description named “CMakeLists.txt”. This project description is transformed into Makefiles, XCode projects or Windows solutions similar to QMake.
It is assumed that the main module is named main.cpp. Then the following CMakeLists.txt file will compile and link it with the Qt4 libraries installed somewhere in /usr/local/, for example in /usr/local/Trolltech/Qt-4.7.4. Please substitute your particular installation directory for the latter.
PROJECT(MyQtApp)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.3)
# non-standard path to Qt4
SET(CMAKE_PREFIX_PATH ${CMAKE_PREFIX_PATH};
/usr/local/Trolltech/Qt-4.7.4;
)
# Qt4 dependency
FIND_PACKAGE(Qt4 COMPONENTS QtCore QtGui REQUIRED)
INCLUDE(${QT_USE_FILE})
ADD_DEFINITIONS(${QT_DEFINITIONS})
# executable
ADD_EXECUTABLE(main main.cpp)
TARGET_LINK_LIBRARIES(main
${QT_LIBRARIES}
)
On Unix and Mac we type the following command to compile:
cmake . && make
To change the configuration (e.g. paths, compiler settings etc.) we type
ccmake .
to open the interactive cmake configuration tool.
← Installation von Qt | ● | Spezialisierung einer Qt Klasse →