QtCreator + Conan + CMake
-
Hey guys,
What is the envisioned workflow for working with QtCreator and Qt consumed via conan? I cannot find information online.
I am able to build and execute via command line an application using Qt 6.3.1.
Initially, I stumbled upon this same issue but followed the suggestions there to get everything working.I don't understand, however, what is the envisioned workflow to integrate all of this into QtCreator. I managed to import my test project from the existing build folder created via the command line. All the configurations seems to be properly imported, and the auto-detected kit also works. I am not able however to run the conan install step within the IDE (I get the error "Conan install: invalid command"). Also, I don't understand how could I enable the virtual env (source activate.sh) within QtCreator.
Does someone have experience on this? Thanks a lot in advance!
-
Have a look at Qt Creator: CMake package-manager auto-setup.
Qt Creator will inject a piece of CMake code that will use cmake-conan to run the
conan install
step before configuring the CMake project. -
Thanks for the hint @cristian-adam !
I followed your suggestion and now the conan install step runs successfully and the conan dependencies of my project build correctly. In my conan recipe I have the following requirements:def requirements(self): self.requires("qtbase/6.3.1@qt/everywhere") self.requires("qtdeclarative/6.3.1@qt/everywhere") self.requires("qtshadertools/6.3.1@qt/everywhere")
I get however some errors while building my test application. In particular, the compiler complains that it does not find some headers like QQmlApplicationEngine and QQuickTextDocument.
I checked and those files are available in my conan cache but from the compile command I see that QtQml.framework/Headers and QtQuick.framework/Headers are not passed as -isystem directories (only QtCore.framework/Headers and QtGui.framework/Headers are passed).
Am I missing something in my cmake files? I would not know for which package / target to look for to be honest.
-
Documentation for QQmlApplicationEngine is stating that you need to have:
find_package(Qt6 REQUIRED COMPONENTS Qml) target_link_libraries(mytarget PRIVATE Qt6::Qml)
And for QQuickTextDocument you need:
find_package(Qt6 REQUIRED COMPONENTS Quick) target_link_libraries(mytarget PRIVATE Qt6::Quick)
Make sure you have the components mentioned in your
find_package
call. -
That was indeed the initial version of my cmake files. With that configuration I was able to build and run the application via command line.
The problem arises when I integrate everything into Qt Creator. Somehow the IDE cannot find those components so that call to find_package fails.
This is the error I get:
-- Could NOT find Qt6Qml (missing: Qt6Qml_DIR) CMake Error at ui-qml/CMakeLists.txt:9 (find_package): Found package configuration file: /Users/matt/.conan/data/qtbase/6.3.1/qt/everywhere/package/e82d3b03afbaff61d74c55b72301091c49f823e1/lib/cmake/Qt6/Qt6Config.cmake but it set Qt6_FOUND to FALSE so package "Qt6" is considered to be NOT FOUND. Reason given by package: Failed to find Qt component "Qml". Expected Config file at "/Users/matt/.conan/data/qtbase/6.3.1/qt/everywhere/package/e82d3b03afbaff61d74c55b72301091c49f823e1/lib/cmake/Qt6Qml/Qt6QmlConfig.cmake" does NOT exist
The Qt6QmlConfig.cmake file is expected in the qtbase package but in my conan cache is avaialble at
/Users/matt/.conan/data/qtdeclarative/6.3.1/qt/everywhere/package/2dde3e9608192b6b5be2c3f127c052e58418d664/lib/cmake/Qt6Qml
-
I think this is a Qt conan recipe bug. You should have in your
<build-dir>/conan-dependencies/conan_paths.cmake
something like:set(CMAKE_PREFIX_PATH "/Users/matt/.conan/data/qtbase/6.3.1/qt/everywhere/package/e82d3b03afbaff61d74c55b72301091c49f823e1/" "/Users/matt/.conan/data/qtdeclarative/6.3.1/qt/everywhere/build/2dde3e9608192b6b5be2c3f127c052e58418d664" ${CMAKE_PREFIX_PATH} ${CMAKE_CURRENT_LIST_DIR})
so that CMake, when doing a
find_package
, will search in all directories.Make sure you delete your
<build-dir>
and start from scratch, and if it doesn't help, then rung CMake wiht--debug-find
so that it prints more details about thefind_package
calls. -
My bad, the location in my conan cache of Qt6QmlConfig.cmake file was:
"/Users/matt/.conan/data/qtdeclarative/6.3.1/qt/everywhere/**package**/2dde3e9608192b6b5be2c3f127c052e58418d664/lib/cmake/Qt6Qml"
and not:
"/Users/matt/.conan/data/qtdeclarative/6.3.1/qt/everywhere/**build**/2dde3e9608192b6b5be2c3f127c052e58418d664/lib/cmake/Qt6Qml"
I checked in my conan_paths.cmake and all the paths seem to be there.
By running CMake with additional debug info I get:CMake Debug Log at ui-qml/CMakeLists.txt:9 (find_package): find_package considered the following paths for FindQt6.cmake: /Users/matt/.conan/data/ninja/1.11.0/_/_/package/dcee4cca2e436edf288d615e9a3f84542aab8e03/FindQt6.cmake /Users/matt/.conan/data/qtdeclarative/6.3.1/qt/everywhere/package/2dde3e9608192b6b5be2c3f127c052e58418d664/FindQt6.cmake /Users/matt/.conan/data/qtimageformats/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtlanguageserver/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtshadertools/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtsvg/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtbase/6.3.1/qt/everywhere/package/e82d3b03afbaff61d74c55b72301091c49f823e1/FindQt6.cmake /Users/matt/.conan/data/ninja/1.11.0/_/_/package/dcee4cca2e436edf288d615e9a3f84542aab8e03/FindQt6.cmake /Users/matt/.conan/data/qtdeclarative/6.3.1/qt/everywhere/package/2dde3e9608192b6b5be2c3f127c052e58418d664/FindQt6.cmake /Users/matt/.conan/data/qtimageformats/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtlanguageserver/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtshadertools/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtsvg/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtbase/6.3.1/qt/everywhere/package/e82d3b03afbaff61d74c55b72301091c49f823e1/FindQt6.cmake /Users/matt/.conan/data/ninja/1.11.0/_/_/package/dcee4cca2e436edf288d615e9a3f84542aab8e03/FindQt6.cmake /Users/matt/.conan/data/qtdeclarative/6.3.1/qt/everywhere/package/2dde3e9608192b6b5be2c3f127c052e58418d664/FindQt6.cmake /Users/matt/.conan/data/qtimageformats/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtlanguageserver/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtshadertools/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtsvg/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtbase/6.3.1/qt/everywhere/package/e82d3b03afbaff61d74c55b72301091c49f823e1/FindQt6.cmake /Users/matt/.conan/data/ninja/1.11.0/_/_/package/dcee4cca2e436edf288d615e9a3f84542aab8e03/FindQt6.cmake /Users/matt/.conan/data/qtdeclarative/6.3.1/qt/everywhere/package/2dde3e9608192b6b5be2c3f127c052e58418d664/FindQt6.cmake /Users/matt/.conan/data/qtimageformats/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtlanguageserver/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtshadertools/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtsvg/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtbase/6.3.1/qt/everywhere/package/e82d3b03afbaff61d74c55b72301091c49f823e1/FindQt6.cmake /Users/matt/.conan/data/ninja/1.11.0/_/_/package/dcee4cca2e436edf288d615e9a3f84542aab8e03/FindQt6.cmake /Users/matt/.conan/data/qtdeclarative/6.3.1/qt/everywhere/package/2dde3e9608192b6b5be2c3f127c052e58418d664/FindQt6.cmake /Users/matt/.conan/data/qtimageformats/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtlanguageserver/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtshadertools/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtsvg/6.3.1/qt/everywhere/package/66b09352dfc791c1f370be1e3bc4d82923afb37c/FindQt6.cmake /Users/matt/.conan/data/qtbase/6.3.1/qt/everywhere/package/e82d3b03afbaff61d74c55b72301091c49f823e1/FindQt6.cmake /Users/matt/Desktop/Workspaces/qt6-qml-example/build_release_with_debug_info/conan-dependencies/FindQt6.cmake /Users/matt/Desktop/Workspaces/qt6-qml-example/build_release_with_debug_info/conan-dependencies/FindQt6.cmake /Applications/CMake.app/Contents/share/cmake-3.24/Modules/FindQt6.cmake The file was not found. /Users/matt/.conan/data/qtbase/6.3.1/qt/everywhere/package/e82d3b03afbaff61d74c55b72301091c49f823e1/lib/cmake/Qt6/Qt6Config.cmake
-
The next CMake debugging level would be:
--trace-expand --trace-redirect=cmake-trace.log
Do this for:
- command line build
- Qt Creator build
Qt Creator should work in the same way as from command line.
Also worth pointing out this blog article https://www.qt.io/blog/conan-package-manager-pilot-to-end-in-december
-
Oh, that's sad news! I was so excited when I read Qt was adopting conan, I think it has great potential. Thanks @cristian-adam for the hints, I'll keep playing around.