Install EXPORT for multiple build types

Hi all,

I have a project for which I can do a Debug and Release build. Using a debug postfix, libraries are named differently. So I though I could do a make install in both build directories, resulting in a mixed installation.

I also have an install(EXPORT …) task, and this generates a Targets-Release or Targets-Debug, depending on the build type. But when installing the second build type, the files for the first build type are removed. So I always end up with either a Targets-Release, or Targets-Debug, and not both.

What is the proper way to do a Release and Debug installation so that I can have both build types installed and useable? I kinda expected the Targets-* files to be left, especially since the Targets.cmake file itself seems to be the same for the different build types.

TiA!

I think the only way, right now, is to use a multi-config generator. 3.17 has Ninja-Multi you can use. I don’t know the history of removing all the old targets.cmake files off-hand, but it might be something we can address.

Cc: @kyle.edwards

Thanks for the reply,

I’m now looking at ninja, although a more generic fix would be nice to have!

Question regarding multi-config, previously I could use a BUILD_TYPE variable to get the buildtype, but that doesn’t work now. How can I differentiate between the different configs? In my case I generate a file, which has config specific content (lib name with debug postfix vs regular lib name).

Perhaps I’m looking in the wrong place, but I can’t find a simple answer…

Again, thanks!

For this bit, what you’re looking for is most likely the command file(GENERATE)

I am already using file(GENERATE …) with INPUT and OUTPUT. But get an error

CMake Error in bundles/remote_services/discovery_configured/CMakeLists.txt:
   Evaluation file to be written multiple times with different content.  This
   is generally caused by the content evaluating the configuration type,
   language, or location of object files:

The documentation mentions to use ${CONFIG} to have a config specific output, but I must be doing something wrong…

It’s mentioning using $<CONFIG>, not ${CONFIG}. The former is a generator expression, the latter is a CMake variable expansion. If you post your use of file(GENERATE), someone might be able to help (I have to go offline now, but I can take a look tomorrow if it’s not resolved by then).

Ah yes, now I see, my bad. This works!

Many thanks!

Hi Ben,

Petr helped me with getting ninja going, but I’d still like to see this work with Makefiles as well. Any feedback/ideas on the targets.cmake behaviour are still welcome!

I suggest filing an issue about the -targets.cmake removal being unconditional. Maybe some control can be given over that behavior somehow.

1 Like

Somehow I ended up with different configs for my release and debug build. This triggered the deletion of the Targets file.

See issue: https://gitlab.kitware.com/cmake/cmake/-/issues/20589

So making the config the same again makes it all work as expected!