find_package-stack: Export tracking doesn't follow nested dependencies correctly
CMakeLists:
cmake_minimum_required(VERSION 3.18)
project(proj)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}")
# Incorrect tracking of dependencies
find_package(CTK REQUIRED)
find_package(Threads REQUIRED)
add_library(demo STATIC f.cpp)
target_link_libraries(demo PRIVATE Threads::Threads)
install(TARGETS demo EXPORT mytargets)
install(EXPORT mytargets DESTINATION lib/cmake/ FILE mytargets.cmake EXPORT_DEPENDENCIES)
export(EXPORT mytargets FILE mytargets.cmake EXPORT_DEPENDENCIES)
CTK:
find_package(Threads REQUIRED)
set(CTK_FOUND TRUE)
set(ctk_FOUND TRUE)
The generated mytargets has:
# Generated by CMake
include(CMakeFindDependencyMacro)
find_dependency(CTK REQUIRED)
# Generated by CMake
In this given configuration we incorrectly build a dependency between mytargets
and CTK
even though no target generated by CTK
is used. This is due to the fact that CTK
brings in Threads
which is what we use.