# From-source shared dependency

**URL:** <https://discourse.cmake.org/t/from-source-shared-dependency/10860>\
**Category:** Code\
**Created:** [May 15, 2024, 12:16pm UTC](https://discourse.cmake.org/t/from-source-shared-dependency/10860 "2024-05-15T12:16:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![hainest](https://discourse.cmake.org/user_avatar/discourse.cmake.org/hainest/32/2896_2.png) [@hainest](https://discourse.cmake.org/u/hainest)\
**Post date:** [May 15, 2024, 12:16pm UTC](https://discourse.cmake.org/t/from-source-shared-dependency/10860/1 "2024-05-15T12:16:48Z")

</div>

`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

1. Change `MyProject` to not perform find\_path/find\_library verification when `CommonDep_ROOT_DIR` is provided
2. Update `SuperProject` to use `FetchContent`

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.
