[CMake] Using Qt5 with CMake
Stephen Kelly
steveire at gmail.com
Wed Mar 12 04:34:24 EDT 2014
Alan W. Irwin wrote:
> (1) How should you replace
>
> find_package(Qt4 4.8.2 COMPONENTS QtCore QtGui QtSvg)
find_package(Qt5 5.2.1 COMPONENTS Svg)
or
find_package(Qt5Svg 5.2.1)
Packages and targets know their dependencies so you don't have to.
> and
>
> qt4_wrap_cpp(
> QT_MOC_OUTFILES
> ${CMAKE_SOURCE_DIR}/include/qt.h
> OPTIONS ${MOC_OPTIONS}
> )
qt5_wrap_cpp(
QT_MOC_OUTFILES
${CMAKE_SOURCE_DIR}/include/qt.h
OPTIONS ${MOC_OPTIONS}
)
Though you can port to AUTOMOC before/after porting to Qt 5 too.
> Does Qt5
> still use that directory property apprach for setting compile flags
> or is this no longer an issue?
Qt 5 provides IMPORTED targets which have the compile flags encoded in them.
The flags are consumed by target_link_libraries.
http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html
target_link_libraries(foo Qt5::Svg)
Qt4 provides IMPORTED targets too, so you can already use those before
porting to Qt 5 instead of whatever mechanism you currently use.
target_link_libraries(foo Qt4::QtSvg)
http://www.cmake.org/cmake/help/v3.0/manual/cmake-qt.7.html
> target_link_libraries(
> plplotqt${LIB_TAG}
> plplot${LIB_TAG}
> ${MATH_LIB}
> ${QT_LIBRARIES}
> )
>
> How should that command be replaced for the new Qt5 way of doing
> things?
I recommend listing the IMPORTED target 'leaf' dependencies.
target_link_libraries(
plplotqt${LIB_TAG}
plplot${LIB_TAG}
${MATH_LIB}
Qt4::QtSvg
# Qt5::Svg
)
You can use
set(QT_LIBRARIES Qt4::QtSvg)
either, but I recommend using the target names directly.
Thanks,
Steve.
More information about the CMake
mailing list