I work on build systems a fair bit, and this is something I thought others might benefit from. I went through quite a bit of code in our projects that did not do things the “right way”, and it wasn’t clear what that was to me at first. Qt 5 improved its integration with CMake quite significantly – moving from using the qmake command to find Qt 4 components in a traditional CMake find module to providing its own CMake config files. This meant that instead of having to guess where Qt and its libraries/headers were installed we could use the information generated by Qt’s own build system. This led to many of us, myself included, finding Qt 5 modules individually:
1 2 |
find_package(Qt5Core REQUIRED) find_package(Qt5Widgets REQUIRED) |
This didn’t feel right to me, but I hadn’t yet seen what I think is the preferred way (and the way I would recommend) to find Qt 5. It also led to either using ‘CMAKE_PREFIX_PATH’ to specify the prefix Qt 5 was installed in, or passing in ‘Qt5Core_DIR’, ‘Qt5Widgets_DIR’, etc for the directory containing each and every Qt 5 config module – normally all within a common prefix. There is a better way, and it makes many of these things simpler again:
1 |
find_package(Qt5 COMPONENTS Core Widgets REQUIRED) |
This is not only more compact, which is always nice, but it means that you can simply pass in ‘Qt5_DIR’ to your project, and it will use that when searching for the components. There are many other great features in CMake that improve Qt integration, but I want to keep this post short…
Pingback: Alexis Girault
Pingback: Sankhesh Jhaveri
Pingback: TManhente
Pingback: Marcus D. Hanwell
Pingback: Marcus D. Hanwell
Pingback: Andre Fitch
Pingback: Marcus D. Hanwell
Pingback: Keith Kyzivat (Keithel)
Pingback: Tien Do (@tienonsoftware)
Pingback: alcroito