SuperProject
consumes my project, MyProject
, via CMake. Both projects have a common dependency CommonDep
. CommonDep
isn’t a CMake project, so MyProject
provides a FindCommonDep.cmake
that uses find_path/find_library to make sure CommonDep
exists and is a usable version. Importantly, it respects the user-provided CommonDep_ROOT_DIR
.
The problem is that SuperProject
wants to build CommonDep
from source and share it with MyProject
. However, SuperProject
is using external_project_add
and setting CommonDep_ROOT_DIR
to the respective directory in their build tree. This makes FindCommonDep.cmake
fail because CommonDep
isn’t available at config time even though CommonDep_ROOT_DIR
is set.
I can’t find any suggestions on what to do in this case. I have considered
- Change
MyProject
to not perform find_path/find_library verification whenCommonDep_ROOT_DIR
is provided - Update
SuperProject
to useFetchContent
I don’t like (1) because an invalid version of CommonDep
will cause build failures instead of CMake errors (or will build and have wrong behavior). I also don’t like (2) because it’s intrusive to SuperProject
.
Suggestions are very much welcome.