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

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.

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.

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).

That would be my preference. I hope it helps!

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).