Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
6.8.0
-
None
-
OS: Windows 10
CMake: 3.29.6
Generator: Ninja
Description
Original title: using qt_add_library with the CMake generator "Ninja" on windows gives ninja: error: '::cmake_automoc_parser', [...] missing and no known rule to make it
Using the Ninja generator and qt_add_library to create a library target configures find, but fails to compile because of:
ninja: error: '::cmake_automoc_parser', needed by <some_json_file>, missing and no known rule to make it
It seems that the variable QT_CMAKE_EXPORT_NAMESPACE is not defined when qt6_extract_metatypes is called.
Adding set(QT_CMAKE_EXPORT_NAMESPACE Qt6) at the beginning of the function makes it compile.
Using MANUAL_FINALIZATION and manually call qt_finalize_target(target) also fix the problem.
[EDIT]
While doing a minimal reproducible project, I found what is causing the problem, it might not be considered as a bug. The error message is not user-friendly to understand what's going on, though.
The problem is that I use a function, my_add_library, to add libraries to my projects. The dependencies used by the libraries are required in this function, i.e. call to find_package(Qt6 REQUIRED COMPONENTS Core...) is not done at the top level CMakeLists.txt of the project, but each time it's needed with the specific needed components when the function is call.
The consequence is that Qt is not considered as FOUND after the call of the function, and so, the way the call to qt_finalize_target is deffered by qt_add_library, make it called at a point where Qt is not considered as FOUND anymore.
Add a call to find_package(Qt6 REQUIRED COMPONENTS Core) prior to the call to my_add_library fixes things, declare my_add_library as a macro rather than a function also "fixes things".
I guess doing the call to find_package in a function was a bad idea by design, I didn't realize that all dependencies have to be found by CMake each time the function is called.
Attachments
Issue Links
- relates to
-
QTBUG-130757 Calling find_pacakge(Qt) in a specific directory scope and using the targets in sibling scopes can lead to issues
-
- Open
-