This question is related to this one.
I decided to track what happened exactly when resolving a dependency chain.
I set 3 projects A
, B
and C
.
B
depends privately on C
and does find_package(C <REQUIRED>)
.
A
depends privately on B
and does find_package(B REQUIRED)
.
All of them are using the following trivial macro:
macro(find_package)
message("@DEBUG@ in find_packages(${ARGV})")
_find_package(${ARGV})
endmacro()
all package are installed with a configuration file containing:
include(CMakeFindDependencyMacro)
foreach(_lib_ IN ITEMS @MY_REQUIRED_DEPENDENCIES@)
find_dependency(${_lib_})
endforeach()
where MY_REQUIRED_DEPENDENCIES
is a list of project names (namely B
or C
in this case).
First situation, C
is required by B
, I’ve got for B
:
@DEBUG@ in find_packages(C;REQUIRED)
and for A
@DEBUG@ in find_packages(B;REQUIRED)
@DEBUG@ in find_packages(C;REQUIRED)
as expected
Second situation, C
is NOT required by B
, I’ve got for B
:
@DEBUG@ in find_packages(C)
and for A
@DEBUG@ in find_packages(B;REQUIRED)
@DEBUG@ in find_packages(C;REQUIRED)
Which is unexpected. I thought I should get:
@DEBUG@ in find_packages(B;REQUIRED)
@DEBUG@ in find_packages(C)
What did I got wrong?