cmake with qt - qt developer days
TRANSCRIPT
![Page 2: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/2.jpg)
Qt Buildsystems
![Page 3: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/3.jpg)
Why CMake?
● Finding dependencies
● Providing shared libraries
● Platform independence● Configure checks
● Code generators
● Extendible
● Scalable
![Page 4: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/4.jpg)
Related tools
CPack CTest CDash
![Page 5: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/5.jpg)
Stages of building
Configure Generate moc Compile Link
![Page 6: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/6.jpg)
Finding Dependencies
![Page 7: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/7.jpg)
CMake today
find_package(Qt4 REQUIRED QtCore QtGui)
include_directories(${QT_INCLUDES})
add_definitions(${QT_DEFINITIONS})
add_executable(myexe WIN32 main.cpp)
target_link_libraries(myexe
${QT_QTCORE_LIBRARIES}
${QT_QTGUI_LIBRARIES}
)
![Page 8: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/8.jpg)
CMake today
find_package(Qt5Widgets)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_executable(myexe WIN32 main.cpp)
target_link_libraries(myexe
${Qt5Widgets_LIBRARIES}
)
![Page 9: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/9.jpg)
QMake (Qt 5)
TARGET = myexe
SOURCES = main.cpp
QT += widgets
![Page 10: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/10.jpg)
CMake today
find_package(Qt5Widgets)
include_directories(${Qt5Widgets_INCLUDE_DIRS})
add_definitions(${Qt5Widgets_DEFINITIONS})
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
add_executable(myexe WIN32 main.cpp)
target_link_libraries(myexe
${Qt5Widgets_LIBRARIES}
)
![Page 11: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/11.jpg)
CMake tomorrow (2013)
find_package(Qt5Widgets)
add_executable(myexe WIN32 main.cpp)
target_link_libraries(myexe
Qt5::Widgets
)
![Page 12: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/12.jpg)
CMake tomorrow (2013)
find_package(Qt4)
add_executable(myexe WIN32 main.cpp)
target_link_libraries(myexe
Qt4::Gui
)
![Page 13: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/13.jpg)
Finding dependencies
find_package(Qt5Widgets)
find_package(boost …)
add_executable(dependent …)
target_link_libraries(dependent
Qt5::Widgets
boost::spirit
boost::mpl)
![Page 14: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/14.jpg)
The QTestLib problem
![Page 15: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/15.jpg)
Finding dependencies
find_package(LibXml2)● Libraries
● Header files
● Defines
● Version variables
find_package(Squish)● Executables
● Test macros
![Page 16: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/16.jpg)
Finding dependencies
● Treasure maps● FindLibXml2.cmake
● FindSquish.cmake● FindQt4.cmake● Not part of upstream
● Local Guide● Qt5WidgetsConfig.cmake
● PulseAudioConfig.cmake● Part of upstream package
![Page 17: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/17.jpg)
Generating Code
![Page 18: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/18.jpg)
Generated code
CMakeqt4_wrap_cpp(moc_files mywidget.h)
qt4_wrap_ui(ui_files mywidget.ui)
add_library(mylib ${sources}
${moc_files}
${ui_files})
![Page 19: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/19.jpg)
Generated code
CMakeqt4_wrap_cpp(moc_files mywidget.h)
qt4_wrap_ui(ui_files mywidget.ui)
add_library(mylib ${sources}
${moc_files}
${ui_files})
QMake
SOURCES += mywidget.cpp
HEADERS += mywidget.h mycontrol.h
![Page 20: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/20.jpg)
Automoc
CMake (2.8.8)
● No need for qt[4|5]_wrap_cpp
● #include “moc_mywidget.cpp”
● Or don't!● Finds Q_OBJECT in .h and .cpp files
![Page 21: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/21.jpg)
Automoc
CMake (2.8.8)
qt4_wrap_ui(ui_files mywidget.ui)
add_library(mylib ${sources}
${ui_files})
set_target_property(mylib AUTOMOC ON)
![Page 22: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/22.jpg)
Automoc
CMake (2.8.8)
set(CMAKE_AUTOMOC ON)
qt4_wrap_ui(ui_files mywidget.ui)
add_library(mylib ${sources}
${ui_files})
![Page 23: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/23.jpg)
Extended code generation
qt4_create_translation(qm_files
${mylib_SRCS} mylib_de.ts
)
![Page 24: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/24.jpg)
Extended code generation
qt4_generate_dbus_interface(mywidget.h
com.kdab.mywidget.xml
)
qt4_add_dbus_interfaces(dbus_files
com.kdab.mywidget.xml)
![Page 25: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/25.jpg)
Platform independence
![Page 26: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/26.jpg)
Platform checks
check_include_file(“limits.h” HAVE_LIMITS)
check_source_compiles(
“#include <qglobal.h>
#ifndef __PIC__
#error \"Compile your code with -fPIC or -fPIE.\"
#endif
“
HAVE_PIC
)
![Page 27: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/27.jpg)
Creating Dependencies
![Page 28: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/28.jpg)
Providing dependencies
install(TARGETS mylib
EXPORT myexports …)
install(TARGETS otherlib
EXPORT myexports …)
install(EXPORT myexport …)
![Page 29: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/29.jpg)
Providing dependencies
install(EXPORT myexport
FILENAME mytargets.cmake)
…
# mylibConfig.cmake
include(mytargets.cmake)
mylib_helpful_macro(...)
![Page 30: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/30.jpg)
Providing dependencies
# No Findmylib.cmake needed!
find_package(mylib)
add_executable(dependent …)
target_link_libraries(dependent
mylib
otherlib)
![Page 31: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/31.jpg)
Imported targets
# Qt5GuiConfig.cmake
add_library(Qt5::Gui IMPORTED)
set_target_property(Qt5::Gui
LOCATION
“/opt/qt5/lib/Qt5Gui.so”
)
![Page 32: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/32.jpg)
Imported targets
# Qt5GuiConfig.cmake
add_library(Qt5::Gui IMPORTED)
set_target_property(Qt5::Gui
INTERFACE_INCLUDE_DIRECTORIES
“/opt/qt5/include/Qt5Gui”
“$<TARGET_INCLUDES:Qt5::Core>”
)
![Page 33: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/33.jpg)
Imported targets
# Qt5GuiConfig.cmake
add_library(Qt5::Gui IMPORTED)
set_target_property(Qt5::Gui
INTERFACE_INCLUDE_DIRECTORIES
“/opt/qt5/include/Qt5Gui”
“$<TARGET_PROPERTY:Qt5::Core,INTERFACE_INCLUDE_DIRECTRIES>”
)
![Page 34: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/34.jpg)
Imported targets
# Qt5GuiConfig.cmake
add_library(Qt5::Gui IMPORTED)
set_target_property(Qt5::Gui
INTERFACE_INCLUDE_DIRECTORIES
“/opt/qt5/include/Qt5Gui”
“$<TARGET_INCLUDES:Qt5::Core>”
)
![Page 35: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/35.jpg)
qtmain.lib
QMake
CONFIG -= console
CMake (Qt 4)
add_executable(exec WIN32 …)
target_link_libraries(${QT_QTMAIN_LIBS})
![Page 36: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/36.jpg)
qtmain.lib
CMake (Qt 5)
add_executable(exec WIN32 …)
target_link_libraries(${QT_QTMAIN_LIBS})
![Page 37: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/37.jpg)
Imported targets
# Qt5GuiConfig.cmake
add_library(Qt5::Gui IMPORTED)
set_target_property(Qt5::Gui
INTERFACE_LINK_LIBRARIES
“$<TARGET_LIBRARIES:Qt5::Core>”
“$<$<WIN32_EXECUTABLE>:Qt5::WinMain>”
)
![Page 38: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/38.jpg)
Declarative expressions
add_executable(CoolApp …)
target_link_libraries(CoolApp
Qt5::Widgets
$<$<CONFIG:Debug>:Qt5::Test>
)
![Page 39: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/39.jpg)
Declarative expressions
add_executable(CoolApp …)
set_target_property(CoolApp
INCLUDE_DIRECTORIES $<$<CONFIG:Debug>:/usr/include/valgrind>
)
![Page 40: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/40.jpg)
● Object orientated
● Declarative
![Page 41: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/41.jpg)
Qt Buildsystems
QBS
![Page 42: CMake with Qt - Qt Developer Days](https://reader030.vdocuments.net/reader030/viewer/2022021208/62062fec8c2f7b1730053e29/html5/thumbnails/42.jpg)
Configure Generate moc Compile Link
QBS