# Find subdependency built / installed with execute\_command

**URL:** <https://discourse.cmake.org/t/find-subdependency-built-installed-with-execute-command/7903>\
**Category:** Code\
**Created:** [April 13, 2023, 11:30am UTC](https://discourse.cmake.org/t/find-subdependency-built-installed-with-execute-command/7903 "2023-04-13T11:30:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leon0402](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/l/ccd318/32.png) [@Leon0402](https://discourse.cmake.org/u/Leon0402)\
**Post date:** [April 13, 2023, 11:30am UTC](https://discourse.cmake.org/t/find-subdependency-built-installed-with-execute-command/7903/1 "2023-04-13T11:30:25Z")

</div>

I use the library HERE Data SDK for C++ which has leveldb as a dependency. This library is (for some reasons) not pulled in via FetchContent / GitSubmodule + add\_subdirectory, but via some execute\_process commands:

> <https://github.com/heremaps/here-data-sdk-cpp/blob/master/external/leveldb/CMakeLists.txt#L37>

If I understand it correctly leveldb will be build and installed in some seperate process and everything put in some directory in the build dir. Then the library uses find\_package(Leveldb) to find it.

> <https://github.com/heremaps/here-data-sdk-cpp/blob/master/CMakeLists.txt#L79>

> <https://github.com/heremaps/here-data-sdk-cpp/blob/master/olp-cpp-sdk-core/CMakeLists.txt#L28>

Now I have a library A, which pulls this library as a dependency and also defines a config:

```auto
include(CMakeFindDependencyMacro)
find_dependency(olp-cpp-sdk-core)
include(${CMAKE_CURRENT_LIST_DIR}/As.cmake)

```

Now come the problems. First of olp-cpp-sdk-core doesn’t list leveldb as a dependency. So I could fix this by specying it myself:

```auto
include(CMakeFindDependencyMacro)
find_dependency(olp-cpp-sdk-core)
find_dependency(leveldb) # Should belong in olp-cpp-sdk-core, but nevermind
include(${CMAKE_CURRENT_LIST_DIR}/As.cmake)

```

But leveldb is not found anymore, because this variable above from the lib` list(APPEND CMAKE_PREFIX_PATH ${EXTERNAL_BINARY_INSTALL_DIR})` is not in scope anymore. I could probably write some logic to get this path set in here too. But this doesn’t seem like a good fix.  
The installed leveldb is still after all installed somewhere in the build directory. And not installed together with olp-cpp-sdk-core somehwere.

So to me the solution has to be somehow install olp-cpp-sdk-core again at the proper place or kind of copy the leveldb install folder from the the build directory to the install directory when installing olp-cpp-sdk-core. I’m not quite sure what the best approach would be here.

I hope the problem is clear, it is kind of hard to explain. It seems to be like the way olp-sdk currently pulls in leveldb is really not how you should do it. I don’t want to rewrite half of their cmake logic. Ideally I don’t have to change anything upstream here, but workaround the problem in my project A. So reinstall leveldb as part of my Project A install logic.

I managed to get this working by pulling leveldeb again with FetchContent and everything. But this is bad for a few reasons. First of all leveldb has to be rebuilt and secondly there might be differences between the versions for instance. I would rather want to “reuse” the already build and installed leveldb.

---

<div class="post-metadata">

**Author:** ![assignUser](https://discourse.cmake.org/user_avatar/discourse.cmake.org/assignuser/32/3367_2.png) [@assignUser](https://discourse.cmake.org/u/assignUser)\
**Post date:** [April 20, 2023, 11:29pm UTC](https://discourse.cmake.org/t/find-subdependency-built-installed-with-execute-command/7903/2 "2023-04-20T23:29:26Z")

</div>

> [@Leon0402](#):
>
> `set(EXTERNAL_BINARY_INSTALL_DIR ${CMAKE_CURRENT_BINARY_DIR}/install)`

This means that the leveldb will be installed into a ‘install’ folder in the build dir (the exact path depends on your project setup). You should be able to find it by looking for `leveldbConfig.cmake` in the build tree. By adding this path to CMAKE\_PREFIX\_PATH within your own project (after here sdk was configured so after the `FetchContent_MakeAvailable(<here-sdk>)`) find\_package should be able to find it.
