# find\_package for non-installer third party module/library/package

**URL:** <https://discourse.cmake.org/t/find-package-for-non-installer-third-party-module-library-package/8954>\
**Category:** Code\
**Created:** [September 13, 2023, 12:42pm UTC](https://discourse.cmake.org/t/find-package-for-non-installer-third-party-module-library-package/8954 "2023-09-13T12:42:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![HellMaster](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@HellMaster](https://discourse.cmake.org/u/HellMaster)\
**Post date:** [September 13, 2023, 12:42pm UTC](https://discourse.cmake.org/t/find-package-for-non-installer-third-party-module-library-package/8954/1 "2023-09-13T12:42:03Z")

</div>

Hey guys,

I’ve got a project which requires a fast-dds library ([GitHub - eProsima/Fast-DDS: The most complete DDS - Proven: Plenty of success cases.](https://github.com/eProsima/Fast-DDS)). This library relies on several third party libraries. Those are included in the “thirdparty” directory as git submodules or the module allows to use system wide libraries.

However, fast-dds relies also on foonathan-memory-vendor package ([GitHub - eProsima/foonathan\_memory\_vendor: foonathan/memory vendor package for Fast DDS.](https://github.com/eProsima/foonathan_memory_vendor)) which is not part of the repository compared to other libraries + it turns out to be some sort of wrapper around memory package.

I want to be able to build my project, which relies on fast-dds without the need of manually downloading and installing any of the third party packages and I would like to configure the build system in such a way, it uses local packages.

So I’ve created a testing directory like this:

```auto
my_project
|--3rdparty
| |--Fast-DDS # git submodule
| |--foonathan_memory_vendor # git submodule
|--CMakeLists.txt

```

My CMakeLists.txt file looks following way:

> 1 cmake\_minimum\_required (VERSION 3.16)  
> 2  
> 3  
> 4  
> 5 set (THIRDPARTY ON CACHE STRING “” FORCE)  
> 6 set (BUILD\_SHARED\_LIBS OFF CACHE STRING “” FORCE)  
> 7  
> 8 add\_subdirectory(3rdparty/foonathan\_memory\_vendor)  
> 9 add\_subdirectory(3rdparty/Fast-DDS)

Invoking cmake under my\_project like:

> $ cmake -S . -B build

leads to following issue:

> Could not find a package configuration file provided by  
> “foonathan\_memory\_vendor” with any of the following names:
> 
> ```
> foonathan_memory_vendorConfig.cmake
> foonathan_memory_vendor-config.cmake
> 
> ```
> 
> Add the installation prefix of “foonathan\_memory\_vendor” to  
> CMAKE\_PREFIX\_PATH or set “foonathan\_memory\_vendor\_DIR” to a directory  
> containing one of the above files. If “foonathan\_memory\_vendor” provides a  
> separate development package or SDK, be sure it has been installed.

After investigating the issue I found out, that fast-dds CMakeLists.txt file invokes “find\_package(foonathan\_memory\_vendor)”, however, the package is not installed on the system, thus package configuration file is missing and thus it’s not able to locate it.

I was reading the find\_package documentation and it feels, like find\_package is only for installed packages or am I wrong?

I’ve tried to invoke cmake on the foonathan\_memory\_vendor ($ cmake -S . -B build) package and the foonathan\_memory\_vendor-config.cmake becomes part of the build directory, however, the package requires the foonathan\_memory package and it “includes” it using “externalproject\_add” command.

So my question to this topic and also a generic question would be:  
How does one incorporates a third party library, which uses find\_package to search for additional packages, but I don’t have and don’t want to install those packages system wide. I just want to build those packages as part of the whole build of my project locally.

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [September 13, 2023, 6:32pm UTC](https://discourse.cmake.org/t/find-package-for-non-installer-third-party-module-library-package/8954/2 "2023-09-13T18:32:53Z")

</div>

> [@HellMaster](#):
>
> How does one incorporates a third party library, which uses find\_package to search for additional packages, but I don’t have and don’t want to install those packages system wide. I just want to build those packages as part of the whole build of my project locally.

I recommend a superbuild approach using `ExternalProject`. However, `FetchContent` may be a more preferable way of doing it.

Cc: @craig.scott

---

<div class="post-metadata">

**Author:** ![HellMaster](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@HellMaster](https://discourse.cmake.org/u/HellMaster)\
**Post date:** [September 13, 2023, 8:44pm UTC](https://discourse.cmake.org/t/find-package-for-non-installer-third-party-module-library-package/8954/3 "2023-09-13T20:44:50Z")

</div>

Hi Ben,

thank you a lot for your response. I’ve tried FetchContent, but the issue persists. The third party module relying on another module, which gets “included” by find\_package( ) fails due to the fact, that the module is not installed. Not sure this can be solved by FetchContent? It’s true that I haven’t experimented with the FIND\_PACKAGE\_ARGS parameter of FetchContent\_Declare, as my CMake version is 3.16.  
However, I don’t think this will work as well, as the foonathan\_memory\_vendor package is not installed?

To be honest, I don’t understand all the relationships etc. happening there. From what I understand, the package must! be installed to be foundable?

Regarding ExternalProject I’m afraid I’m in the same trap, as one package requires another package, which is not available at build configuration and ExternalProject makes it available during build time, not configuration time?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [September 13, 2023, 8:47pm UTC](https://discourse.cmake.org/t/find-package-for-non-installer-third-party-module-library-package/8954/4 "2023-09-13T20:47:41Z")

</div>

> [@HellMaster](#):
>
> Regarding ExternalProject I’m afraid I’m in the same trap, as one package requires another package, which is not available at build configuration and ExternalProject makes it available during build time, not configuration time?

Here, all projects would use `ExternalProject` (a “superbuild”) and would consume each other’s install trees.

Alas, I’m not familiar enough with `FetchContent` to add much here without just parroting the docs at you.

---

<div class="post-metadata">

**Author:** ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)\
**Post date:** [September 13, 2023, 9:54pm UTC](https://discourse.cmake.org/t/find-package-for-non-installer-third-party-module-library-package/8954/5 "2023-09-13T21:54:46Z")

</div>

FetchContent isn’t going to help here unless you are pulling in the missing dependency with FetchContent before the other things that need it.

---

<div class="post-metadata">

**Author:** ![HellMaster](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/h/8edcca/32.png) [@HellMaster](https://discourse.cmake.org/u/HellMaster)\
**Post date:** [September 13, 2023, 10:18pm UTC](https://discourse.cmake.org/t/find-package-for-non-installer-third-party-module-library-package/8954/6 "2023-09-13T22:18:45Z")

</div>

Ok, so I’ve created a testing repository:

[https://github.com/Renegade85/cmake\_test](https://github.com/Renegade85/cmake_test)

One has to invoke:

> git submodule update --init --recursive

I would like to automate this in the future with cmake, but right now I would like to focus on the issue about dependencies between third party libs.

As I’m just a cmake newbie, the propsed solution using ExternalProject seems to be a bit complex?

Just to be clear, is my assumption correct, that I can’t use the current configuration because Fast-DDS uses find\_package( ), but the library is not installed?

Can this be solved by installing the package somehow locally using cmake in the repository and use it for the Fast-DDS repo somehow?

Another idea was to patch the CMakeLists.txt file of the Fast-DDS repo and replace:

find\_package(foonathan\_memory\_vendor)

by:

add\_subdirectory(…/…/3rdparty/foonathna\_memory\_vendor …/…/build)

However, with no success so far. As the foonathan\_memory\_vendor seems to be just a wrapper around foonathan\_memory, I was thinking to use that repository/package directly. According to the README of `memory` it should be sufficient to use add\_subdirectory( ) in your project and you should be good to go, but if that solution is used, I get:

> CMake Error in 3rdparty/Fast-DDS/src/cpp/CMakeLists.txt:  
> export called with target “fastrtps” which requires target  
> “foonathan\_memory” that is not in any export set.
