# building/referencing a library

**URL:** https://discourse.cmake.org/t/building-referencing-a-library/1446
**Category:** Usage
**Created:** [June 25, 2020, 11:25pm UTC](https://discourse.cmake.org/t/building-referencing-a-library/1446 "2020-06-25T23:25:46Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![mzimmers](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mzimmers/32/679_2.png) [@mzimmers](https://discourse.cmake.org/u/mzimmers)
#### Post date: [June 25, 2020, 11:25pm UTC](https://discourse.cmake.org/t/building-referencing-a-library/1446/1 "2020-06-25T23:25:46Z")

</div>

Hi, all -

Brand new to using CMake.

I need to port an RTP library to a new platform (the Espressif ESP32). I pulled a copy of ortp from github. It depends on bctoolbox (from the same author), which in turn depends on mbedtls.

The bctoolbox path is (Windows) C:\esp32-projects\ortp.  
The mbedtls (furnished by Espressif) path for source is C:\esp-idf\components\mbedtls.  
The mbedls path for the binary is C:\esp32-projects\ortp\build\esp-idf\mbedtls.

So I’ve looked at the documentation, and found the add\_library command. Is this the appropriate way to make bctoolbox “aware” of this library? It seems like the right command, but it also seems kind of odd that I’d have to list all the source files in this directory structure.

Or…am I doing this totally wrong?

Thanks for any clarification.

---

<div class="post-metadata">

### Author: ![jwm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jwm/32/654_2.png) [@jwm](https://discourse.cmake.org/u/jwm)
#### Post date: [July 8, 2020, 12:17am UTC](https://discourse.cmake.org/t/building-referencing-a-library/1446/2 "2020-07-08T00:17:03Z")

</div>

It’s not 100% clear (to me) what you are trying to do.

If, what you are saying is that you want to build these tools using CMake (and they don’t already support it), then there are two different things you need to do.

The first is, you need to build your library dependencies. So, for example, in your `ortp\CMakeLists.txt` file you would have `add_library`. While it is possible to specify the files in the library using a glob pattern, the best practice is to list all the files. If you want full IDE support, you might want to list all the headers too.

The second is, you need to tell your project about your library. If you build them as a single “super project” then CMake knows about it already. If you built it as an independent project, you will need to support `find_package`.

FWIW, I’m still looking for a good tutorial on the second topic.

---

<div class="post-metadata">

### Author: ![mzimmers](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mzimmers/32/679_2.png) [@mzimmers](https://discourse.cmake.org/u/mzimmers)
#### Post date: [July 8, 2020, 5:12pm UTC](https://discourse.cmake.org/t/building-referencing-a-library/1446/3 "2020-07-08T17:12:22Z")

</div>

Hi Jim -

Thanks for answering. In this case, both ortp and bctoolbox appear to use CMake. When I attempt to build bctoolbox, I get this error:  
– Could NOT find Decaf (missing: Decaf\_DIR)  
– DTLS SRTP not available  
CMake Error at CMakeLists.txt:121 (find\_package):  
Could not find a package configuration file provided by “BcUnit” with any  
of the following names:

```
BcUnitConfig.cmake
bcunit-config.cmake

```

Add the installation prefix of “BcUnit” to CMAKE\_PREFIX\_PATH or set  
“BcUnit\_DIR” to a directory containing one of the above files. If “BcUnit”  
provides a separate development package or SDK, be sure it has been  
installed.  
So, it looks like I have two issues:

I don’t have this decaf thing  
CMake can’t find BcUnit (for that matter, neither can I).

I don’t really know that this is a CMake problem at this point, but…do you have any insight into either of these problems?

Thanks.

---

<div class="post-metadata">

### Author: ![sszabo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/sszabo/32/6030_2.png) [@sszabo](https://discourse.cmake.org/u/sszabo)
#### Post date: [July 8, 2020, 5:19pm UTC](https://discourse.cmake.org/t/building-referencing-a-library/1446/4 "2020-07-08T17:19:36Z")

</div>

Looking at the CMakeLists.txt at [https://github.com/BelledonneCommunications/bctoolbox/blob/master/CMakeLists.txt](https://github.com/BelledonneCommunications/bctoolbox/blob/master/CMakeLists.txt) BcUnit stuff seems to be if ENABLE\_TESTS\_COMPONENT is set (which is the default).

It seems to be a CUnit fork at [https://github.com/BelledonneCommunications/bcunit](https://github.com/BelledonneCommunications/bcunit)

Decaf seems to be optional but used for a feature described as “Enable Elliptic Curve Cryptography support”.

---

<div class="post-metadata">

### Author: ![mzimmers](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mzimmers/32/679_2.png) [@mzimmers](https://discourse.cmake.org/u/mzimmers)
#### Post date: [July 8, 2020, 5:31pm UTC](https://discourse.cmake.org/t/building-referencing-a-library/1446/5 "2020-07-08T17:31:33Z")

</div>

Hi Stephan - I commented out this line:  
#option(ENABLE\_TESTS\_COMPONENT “Enable compilation of tests helper library” ON)

I also tried this:  
option(ENABLE\_TESTS\_COMPONENT “Enable compilation of tests helper library” OFF)

I’m still getting the error message. What might I be doing wrong?

---

<div class="post-metadata">

### Author: ![sszabo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/sszabo/32/6030_2.png) [@sszabo](https://discourse.cmake.org/u/sszabo)
#### Post date: [July 8, 2020, 5:36pm UTC](https://discourse.cmake.org/t/building-referencing-a-library/1446/6 "2020-07-08T17:36:15Z")

</div>

You’ll also need to remove the cmake cache if you haven’t.

---

<div class="post-metadata">

### Author: ![mzimmers](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mzimmers/32/679_2.png) [@mzimmers](https://discourse.cmake.org/u/mzimmers)
#### Post date: [July 8, 2020, 5:42pm UTC](https://discourse.cmake.org/t/building-referencing-a-library/1446/7 "2020-07-08T17:42:05Z")

</div>

Ah yes…I’m still adjusting to that requirement.

So, this is progress. Now I’m getting this:  
CMake Error at C:/Qt/Tools/CMake\_32/share/cmake-3.17/Modules/FindPackageHandleStandardArgs.cmake:164 (message):  
Could NOT find Threads (missing: Threads\_FOUND)

A brief search within the bctoolbox structure didn’t reveal anything by the name “threads,” and it’s not mentioned in the README. Any ideas on this one?

Thanks…

---

<div class="post-metadata">

### Author: ![sszabo](https://discourse.cmake.org/user_avatar/discourse.cmake.org/sszabo/32/6030_2.png) [@sszabo](https://discourse.cmake.org/u/sszabo)
#### Post date: [July 8, 2020, 6:49pm UTC](https://discourse.cmake.org/t/building-referencing-a-library/1446/8 "2020-07-08T18:49:10Z")

</div>

That’s for finding the threading library on the system (like pthreads, etc), see cmake’s Modules/FindThreads.cmake for what it’s doing.

---

<div class="post-metadata">

### Author: ![mzimmers](https://discourse.cmake.org/user_avatar/discourse.cmake.org/mzimmers/32/679_2.png) [@mzimmers](https://discourse.cmake.org/u/mzimmers)
#### Post date: [July 8, 2020, 8:42pm UTC](https://discourse.cmake.org/t/building-referencing-a-library/1446/9 "2020-07-08T20:42:44Z")

</div>

Oh, I see. (I didn’t know about pthreads.)

I think this is where the exercise is going to become more difficult, and it’s not a CMake issue. I was intending to build the ortp library for an ESP32, which runs FreeRTOS (and not the version with the POSIX stuff). Espressif does supply a pthread library in their IDF, but it appears to be proprietary:  
[ESP-IDF pthread header file](https://github.com/espressif/esp-idf/blob/v4.0.1/components/pthread/include/esp_pthread.h)  
So, I’m probably out of luck.  
Thank you for the help with CMake, though…it’s been educational.

EDIT:

I suppose there’s no harm in trying. So, if the path to the pthread directory is “C:\esp-idf\components\pthread,” what is the CMake construct that I use to tell the bctoolbox build to look here?

Thanks.
