Find subdependency built / installed with execute_command

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:

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.

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

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:

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.

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.