# Issue building third party libraries and including them in same project

**URL:** https://discourse.cmake.org/t/issue-building-third-party-libraries-and-including-them-in-same-project/1695
**Category:** Code
**Tags:** os:linux
**Created:** [August 12, 2020, 7:08pm UTC](https://discourse.cmake.org/t/issue-building-third-party-libraries-and-including-them-in-same-project/1695 "2020-08-12T19:08:25Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![mattchabala](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@mattchabala](https://discourse.cmake.org/u/mattchabala)
#### Post date: [August 12, 2020, 7:08pm UTC](https://discourse.cmake.org/t/issue-building-third-party-libraries-and-including-them-in-same-project/1695/1 "2020-08-12T19:08:26Z")

</div>

Hello,

I’m working on a simple project that uses a third party application to handle data. I’m using CMake to check if the third party application already exists on the machine and if it’s not then CMake downloads the latest version and builds it locally.

The problem I’m running into is that part of this application gets built into an executable which I tell CMake to use when building my part of the project with CMake’s `add_custom_command()` function. If the third party application already exists on the machine then the executable runs fine since the libraries can be found using the `LD_LIBRARY_PATH` but if it was downloaded and built locally then the build fails since the libraries cannot be found and are not on the `LD_LIBRARY_PATH`.

Does anyone have any suggestions on how to add a `COMMAND` in the `add_custom_command()` function that would allow for the executable to find or export the needed libraries when `make` is ran or how to permanently modify the `LD_LIBRARY_PATH` from inside of the CMake files so that when `make` is ran the libraries would be on the `LD_LIBRARY_PATH`? Also, if anyone has any other suggestions or advice that would be greatly appreciated.

Thanks,  
Matt

---

<div class="post-metadata">

### Author: ![mattchabala](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/43a26b/32.png) [@mattchabala](https://discourse.cmake.org/u/mattchabala)
#### Post date: [August 13, 2020, 3:43pm UTC](https://discourse.cmake.org/t/issue-building-third-party-libraries-and-including-them-in-same-project/1695/2 "2020-08-13T15:43:55Z")

</div>

I found out what to do. When running the `COMMAND` call in the `add_custom_command()` function you can use ` ${CMAKE_COMMAND} -E env` to set an environment variable in the shell you’re running. So, if you do something like this:

`COMMAND ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=/my/path/to/libs" actual_command `

The `LD_LIBRARY_PATH` you specify will be applied when running `actual_command`.  
I hope this helps anyone who needs it!
