# easiest way to build and install different build types for a single third-party library

**URL:** https://discourse.cmake.org/t/easiest-way-to-build-and-install-different-build-types-for-a-single-third-party-library/9975
**Category:** Usage
**Created:** [January 31, 2024, 11:55am UTC](https://discourse.cmake.org/t/easiest-way-to-build-and-install-different-build-types-for-a-single-third-party-library/9975 "2024-01-31T11:55:11Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [January 31, 2024, 11:55am UTC](https://discourse.cmake.org/t/easiest-way-to-build-and-install-different-build-types-for-a-single-third-party-library/9975/1 "2024-01-31T11:55:11Z")

</div>

Hi,

Using third-party open-source libraries that propose a modern cmake support (ie they can be find with `find_package`), how can I build and install several build types of the library.

Usually I manually had a `<somelib>_ROOT` or `<somelib>_DIR` to my path but how can I do for several build types (at least Debug and Release).

The solution should be compliant with linux or msvc makefile generator at least.

Thanks,  
A.

---

<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: [February 4, 2024, 7:41pm UTC](https://discourse.cmake.org/t/easiest-way-to-build-and-install-different-build-types-for-a-single-third-party-library/9975/2 "2024-02-04T19:41:22Z")

</div>

The project needs some consideration of the situation. In particular, library names likely need to change per configuration and headers can’t have config-dependent bits (there’s probably some way to get around that but it’s better if it just isn’t a problem). Once that is supported, you can just install two builds (either 2 build trees with a single-config generator or one build tree with a multi-config generator) into the same prefix.

---

<div class="post-metadata">

### Author: ![jonesv](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/j/ac8455/32.png) [@jonesv](https://discourse.cmake.org/u/jonesv)
#### Post date: [February 6, 2024, 11:34am UTC](https://discourse.cmake.org/t/easiest-way-to-build-and-install-different-build-types-for-a-single-third-party-library/9975/3 "2024-02-06T11:34:50Z")

</div>

> [@adaldev](#):
>
> Usually I manually had a `<somelib>_ROOT` or `<somelib>_DIR` to my path but how can I do for several build types (at least Debug and Release).

Instead of handling each dependency separately, I like to just install them all in the same place (e.g. with `CMAKE_INSTALL_PREFIX=dependencies/build`) and then point my project to that place with `CMAKE_PREFIX_PATH`.

Then it would be easy to just build all the dependencies in Debug mode and install them in e.g. `dependencies/build-debug`, and in Release mode in `dependencies/build-release` (using a setup [like this](https://www.acarg.ch/posts/cmake-deps/)).

That would be my preference. I hope it helps!

---

<div class="post-metadata">

### Author: ![adaldev](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/9dc877/32.png) [@adaldev](https://discourse.cmake.org/u/adaldev)
#### Post date: [February 6, 2024, 5:08pm UTC](https://discourse.cmake.org/t/easiest-way-to-build-and-install-different-build-types-for-a-single-third-party-library/9975/4 "2024-02-06T17:08:36Z")

</div>

Thanks, it pointed to a possible solution.

I configured and generated the third-party lib with `-DCMAKE_DEBUG_POSTFIX=d`.  
I then built (whatever the build directory) and installed in the same location than the release version.

My client code could then be built in `Debug` or `Release`, giving a single path for the third-party library. (As I said, the path was actually in an OS environment variable, set after the library installation, no path was given inside my client CMakeLists).
