conan
conan copied to clipboard
[bug] CMake ends up using the Debug build of moc.exe in AUTOMOC
Summary
We consume Qt6 as a dependency in our application. We use CMake's AUTOMOC feature. When it runs, it ends up using the Debug build of moc.exe
. Which is not what it should do, as the Debug build runs slower.
Analysis
We have two different packages for Qt6, one for Release and one for Debug.
We run conan install
twice, first for Release, then for Debug.
When find_package(Qt6 CONFIG REQUIRED COMPONENTS Core Widgets)
runs, it prints
Conan: Including build module from '....conan2/p/qt8b9eda40d4b6a/p/lib/cmake/Qt6Core/conan_qt_executables_variables.cmake'
and this is what sets the path to the moc executable. But this is the Qt Debug package. So what ends up happening is that CMake uses this moc.exe
for its AUTOMOC feature.
This is because in Qt6Config.cmake
, it says either
foreach(_BUILD_MODULE ${qt_BUILD_MODULES_PATHS_RELEASE} )
message(${Qt6_MESSAGE_MODE} "Conan: Including build module from '${_BUILD_MODULE}'")
include(${_BUILD_MODULE})
endforeach()
or
foreach(_BUILD_MODULE ${qt_BUILD_MODULES_PATHS_DEBUG} )
message(${Qt6_MESSAGE_MODE} "Conan: Including build module from '${_BUILD_MODULE}'")
include(${_BUILD_MODULE})
endforeach()
So when we run conan install -s build_type=Debug ...
followed by conan install -s build_type=Release ...
it ends up with the Debug moc.exe. But when we run it the other way round (Release first, Debug second), it uses the Release moc.exe.
So in my opinion, Qt6Config.cmake should not depend on the configuration. My understanding is that if a file depends on the configuration, it should also have that configuration in its name. Which is why the order of conan install
matter. I would consider this a bug.
conan install
doesn't seem to overwrite the Qt6Config.cmake
file. When I modify this file manually, it's not reset by conan install
. So to fix this issue for all devs, I would need to tell them to delete the conan
folder in the build directory. I would consider this another bug.
Environment
Windows 10, conan 2.2, Qt 6.6.2.