CMake warning : the target is mentionned as dependency but not declared
-
Hi
After a little refactoring of my CMakeLists.txt files in my project, I'm now facing the warning message :
CMake Warning at /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake:285 (message): [cmake] The HttpServer target is mentioned as a dependency for HttpManagerLib, but [cmake] not declared. The linking might be incomplete. [cmake] Call Stack (most recent call first): [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake:249 (__qt_internal_walk_libs) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake:337 (__qt_internal_walk_libs) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:713 (__qt_internal_collect_all_target_dependencies) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:818 (_qt_internal_finalize_executable) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:787:EVAL:1 (qt6_finalize_target) [cmake] Src/Main/CMakeLists.txt:DEFERRED
I've had this issue a few days ago, but it was among my own modules, I had found a link suggesting that it was due to a missordered add_subdirectories, the depending one being built before the depended one. and indeed Placing the add_subdirectories in the right order fixed the problem.
Now the issue occurs but between one of mine and a Qt one (Qt6::HttpServer).
Here's Src/Application/HttpManager/CMakeLists.txtset (LIBNAME HttpManager) set (QT_LIBS Core Qml Concurrent Network HttpServer) set (CPP_FILES somesources.h somesources.cpp) ################################################################################ project(${LIBNAME}Lib LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS ${QT_LIBS}) qt_add_library(${PROJECT_NAME} STATIC ${CPP_FILES}) qt_add_resources (${PROJECT_NAME} ...) # SSL certificate files for HTTPS server target_include_directories (${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/Src/Entities) target_link_directories (${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/Entities) foreach (module IN LISTS QT_LIBS) target_link_libraries(${PROJECT_NAME} PUBLIC Qt6::${module}) endforeach() target_link_libraries(${PROJECT_NAME} PUBLIC EntitiesLib)
I've checked and rechecked again in other CMakeList.txt files, and all add_subdirectory directives are called in the right build order, dependencies first, dependent libs next, then executables last.
In Src/CMakeLists.txt
add_subdirectory (Entities ${CMAKE_BINARY_DIR}/Entities) add_subdirectory (Application) # HttpManager module inside that directory, along with another plugin manager module, both depending on Entities, no dependency one to the other add_subdirectory (Plugins) # dynamic plugins, depends on Entities add_subdirectory (GlobalManager ${CMAKE_BINARY_DIR}/GlobalManager) # Depends on both modules in Application, serves as facade pattern in both main.cpp in Main and TestUI executables # add_subdirectory (UI) # for user interface, not implemented yet # add_subdirectory (TestUI ${CMAKE_BINARY_DIR}/TestUI) # QML hot reloader executable, not imported yet from another project, depends on GlobalManager add_subdirectory (Main ${CMAKE_BINARY_DIR}/Main) # release executable, same depends on GlobalManager
Qt is my sole external dependency, no other library added
Does anyone have any idea about what I'm doing wrong ?
-
Hi
After a little refactoring of my CMakeLists.txt files in my project, I'm now facing the warning message :
CMake Warning at /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake:285 (message): [cmake] The HttpServer target is mentioned as a dependency for HttpManagerLib, but [cmake] not declared. The linking might be incomplete. [cmake] Call Stack (most recent call first): [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake:249 (__qt_internal_walk_libs) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake:337 (__qt_internal_walk_libs) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:713 (__qt_internal_collect_all_target_dependencies) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:818 (_qt_internal_finalize_executable) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:787:EVAL:1 (qt6_finalize_target) [cmake] Src/Main/CMakeLists.txt:DEFERRED
I've had this issue a few days ago, but it was among my own modules, I had found a link suggesting that it was due to a missordered add_subdirectories, the depending one being built before the depended one. and indeed Placing the add_subdirectories in the right order fixed the problem.
Now the issue occurs but between one of mine and a Qt one (Qt6::HttpServer).
Here's Src/Application/HttpManager/CMakeLists.txtset (LIBNAME HttpManager) set (QT_LIBS Core Qml Concurrent Network HttpServer) set (CPP_FILES somesources.h somesources.cpp) ################################################################################ project(${LIBNAME}Lib LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS ${QT_LIBS}) qt_add_library(${PROJECT_NAME} STATIC ${CPP_FILES}) qt_add_resources (${PROJECT_NAME} ...) # SSL certificate files for HTTPS server target_include_directories (${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/Src/Entities) target_link_directories (${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/Entities) foreach (module IN LISTS QT_LIBS) target_link_libraries(${PROJECT_NAME} PUBLIC Qt6::${module}) endforeach() target_link_libraries(${PROJECT_NAME} PUBLIC EntitiesLib)
I've checked and rechecked again in other CMakeList.txt files, and all add_subdirectory directives are called in the right build order, dependencies first, dependent libs next, then executables last.
In Src/CMakeLists.txt
add_subdirectory (Entities ${CMAKE_BINARY_DIR}/Entities) add_subdirectory (Application) # HttpManager module inside that directory, along with another plugin manager module, both depending on Entities, no dependency one to the other add_subdirectory (Plugins) # dynamic plugins, depends on Entities add_subdirectory (GlobalManager ${CMAKE_BINARY_DIR}/GlobalManager) # Depends on both modules in Application, serves as facade pattern in both main.cpp in Main and TestUI executables # add_subdirectory (UI) # for user interface, not implemented yet # add_subdirectory (TestUI ${CMAKE_BINARY_DIR}/TestUI) # QML hot reloader executable, not imported yet from another project, depends on GlobalManager add_subdirectory (Main ${CMAKE_BINARY_DIR}/Main) # release executable, same depends on GlobalManager
Qt is my sole external dependency, no other library added
Does anyone have any idea about what I'm doing wrong ?
@ankou29666 How does CMakeLists.txt look like for EntitiesLib?
-
Hi
After a little refactoring of my CMakeLists.txt files in my project, I'm now facing the warning message :
CMake Warning at /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake:285 (message): [cmake] The HttpServer target is mentioned as a dependency for HttpManagerLib, but [cmake] not declared. The linking might be incomplete. [cmake] Call Stack (most recent call first): [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake:249 (__qt_internal_walk_libs) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6/QtPublicWalkLibsHelpers.cmake:337 (__qt_internal_walk_libs) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:713 (__qt_internal_collect_all_target_dependencies) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:818 (_qt_internal_finalize_executable) [cmake] /Volumes/User/Users/yann/Qt/6.9.1/macos/lib/cmake/Qt6Core/Qt6CoreMacros.cmake:787:EVAL:1 (qt6_finalize_target) [cmake] Src/Main/CMakeLists.txt:DEFERRED
I've had this issue a few days ago, but it was among my own modules, I had found a link suggesting that it was due to a missordered add_subdirectories, the depending one being built before the depended one. and indeed Placing the add_subdirectories in the right order fixed the problem.
Now the issue occurs but between one of mine and a Qt one (Qt6::HttpServer).
Here's Src/Application/HttpManager/CMakeLists.txtset (LIBNAME HttpManager) set (QT_LIBS Core Qml Concurrent Network HttpServer) set (CPP_FILES somesources.h somesources.cpp) ################################################################################ project(${LIBNAME}Lib LANGUAGES CXX) find_package(Qt6 REQUIRED COMPONENTS ${QT_LIBS}) qt_add_library(${PROJECT_NAME} STATIC ${CPP_FILES}) qt_add_resources (${PROJECT_NAME} ...) # SSL certificate files for HTTPS server target_include_directories (${PROJECT_NAME} PUBLIC ${CMAKE_SOURCE_DIR}/Src/Entities) target_link_directories (${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/Entities) foreach (module IN LISTS QT_LIBS) target_link_libraries(${PROJECT_NAME} PUBLIC Qt6::${module}) endforeach() target_link_libraries(${PROJECT_NAME} PUBLIC EntitiesLib)
I've checked and rechecked again in other CMakeList.txt files, and all add_subdirectory directives are called in the right build order, dependencies first, dependent libs next, then executables last.
In Src/CMakeLists.txt
add_subdirectory (Entities ${CMAKE_BINARY_DIR}/Entities) add_subdirectory (Application) # HttpManager module inside that directory, along with another plugin manager module, both depending on Entities, no dependency one to the other add_subdirectory (Plugins) # dynamic plugins, depends on Entities add_subdirectory (GlobalManager ${CMAKE_BINARY_DIR}/GlobalManager) # Depends on both modules in Application, serves as facade pattern in both main.cpp in Main and TestUI executables # add_subdirectory (UI) # for user interface, not implemented yet # add_subdirectory (TestUI ${CMAKE_BINARY_DIR}/TestUI) # QML hot reloader executable, not imported yet from another project, depends on GlobalManager add_subdirectory (Main ${CMAKE_BINARY_DIR}/Main) # release executable, same depends on GlobalManager
Qt is my sole external dependency, no other library added
Does anyone have any idea about what I'm doing wrong ?
Hi @ankou29666,
It's not entirely clear, but given that your CMake error call stack ends (ie starts) with:
[cmake] Src/Main/CMakeLists.txt:DEFERRED
The issue is likely that you have not found the Qt
HttpServer
package in thatCMakeLists.txt
file.Although you've included
Main
afterApplication
, ie:add_subdirectory (Application) # HttpManager module inside that directory, along with another plugin manager module, both ... add_subdirectory (Main ${CMAKE_BINARY_DIR}/Main) # release executable, same depends on GlobalManager
The modules found in
Application/CMakeLists.txt
are (by default) scoped to that subdirectory only. Try doing a web search for "add_subdirectory scope".I would guess you need to either:
- remove the dependency from
Src/Main/CMakeLists.txt
; or - more likely, move the
find_package(Qt6 ...)
to the topSrc/CMakeLists.txt
file, before theadd_subdirectory
calls.
Cheers.
- remove the dependency from
-
Hi Paul and thanks for your reply.
Yes I had completely missed the
Src/Main/CMakeLists.txt
Line, thank you very much for pointing it out.Yes indeed that was it. As I had turned some dependencies from PRIVATE to PUBLIC, I had removed that dependency from Main/CMakeLists.txt file and adding it back again fixes the problem.
However I'm still a little surprized that, as my module HttpManager relies non only on Qt's HttpServer, but also on Concurrent and Network, the warning is gone only if I add back HttpServer, without adding back Concurrent and Network.
So even though topic is solved, I still would like to add one more question : as Qt::HttpServer module depends on classes defined Qt::Network module (QTcpServer, as as QHttpServer depends on QTcpServer), and also likely QFuture in Qt::Concurrent module, I guess that importing Qt::HttpServer module also brings Qt::Concurrent and Qt::Network as implicit dependencies, that don't need to be declared explicitly ?@Paul-Colby said in CMake warning : the target is mentionned as dependency but not declared:
more likely, move the find_package(Qt6 ...) to the top Src/CMakeLists.txt file, before the add_subdirectory calls.
Yeah I currently have a find_package statement near the beginning of EVERY subfolder's CMakeLists.txt. I've been watching a few CMake videos on youtube and find one that was making the same suggestion.
That's what I'm planning to do this afternoon. -
-
Hi Paul and thanks for your reply.
Yes I had completely missed the
Src/Main/CMakeLists.txt
Line, thank you very much for pointing it out.Yes indeed that was it. As I had turned some dependencies from PRIVATE to PUBLIC, I had removed that dependency from Main/CMakeLists.txt file and adding it back again fixes the problem.
However I'm still a little surprized that, as my module HttpManager relies non only on Qt's HttpServer, but also on Concurrent and Network, the warning is gone only if I add back HttpServer, without adding back Concurrent and Network.
So even though topic is solved, I still would like to add one more question : as Qt::HttpServer module depends on classes defined Qt::Network module (QTcpServer, as as QHttpServer depends on QTcpServer), and also likely QFuture in Qt::Concurrent module, I guess that importing Qt::HttpServer module also brings Qt::Concurrent and Qt::Network as implicit dependencies, that don't need to be declared explicitly ?@Paul-Colby said in CMake warning : the target is mentionned as dependency but not declared:
more likely, move the find_package(Qt6 ...) to the top Src/CMakeLists.txt file, before the add_subdirectory calls.
Yeah I currently have a find_package statement near the beginning of EVERY subfolder's CMakeLists.txt. I've been watching a few CMake videos on youtube and find one that was making the same suggestion.
That's what I'm planning to do this afternoon.@ankou29666 said in CMake warning : the target is mentionned as dependency but not declared:
guess that importing Qt::HttpServer module also brings Qt::Concurrent and Qt::Network as implicit dependencies, that don't need to be declared explicitly ?
correct, that's why you have to use PRIVATE, PUBLIC and INTERFACE in your target_link_libraries() call: https://cmake.org/cmake/help/latest/command/target_link_libraries.html#libraries-for-a-target-and-or-its-dependents