Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What to use instead of `qt5_use_modules`?

Tags:

c++

cmake

qt

qt5

The Qt 5 CMake manual states that the qt5_use_modules macro is deprecated:

This macro is obsolete. Use target_link_libraries with IMPORTED targets instead.

... But qt5_use_modules does more than simply specify link libraries: it specifies include directories, necessary compile flags, and more (see the full description in the linked documentation above).

Assuming, then, that the variable QTMODULES contains some list of Qt modules that should be used for a project, what is the "recommended" way to replace the following "deprecated" CMake line?

qt5_use_modules(${myProjectName} ${QTMODULES})

The following does NOT work, primarily because it does not add any Qt include paths:

    target_link_libraries(${myProjectName} IMPORTED ${QTMODULES})

Does the QTMODULES variable need to be manually iterated over, so that include_directories can be called for each individual module name? This seems like a major step backward from qt5_use_modules, which is simple and "just works." Am I missing something?

like image 623
Kyle Strand Avatar asked Jul 01 '15 21:07

Kyle Strand


1 Answers

The message about using IMPORTED targets actually refers to the generated targets that Qt5's CMake modules provide for you, not that you should be setting the IMPORTED property on the target_link_libraries macro. For example, something like:

target_link_libraries(${myProjectName} Qt5::Core Qt5::Widgets)

will take care of adding all the necessary include paths, link paths, and libraries for using the Qt5Core and Qt5Widgets modules.

like image 171
Zrax Avatar answered Oct 16 '22 19:10

Zrax