# install with EXPORT and multiple CONFIGURATIONS

**URL:** https://discourse.cmake.org/t/install-with-export-and-multiple-configurations/1292
**Category:** Code
**Created:** [May 29, 2020, 5:01am UTC](https://discourse.cmake.org/t/install-with-export-and-multiple-configurations/1292 "2020-05-29T05:01:24Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![alex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex/32/125_2.png) [@alex](https://discourse.cmake.org/u/alex)
#### Post date: [May 29, 2020, 5:01am UTC](https://discourse.cmake.org/t/install-with-export-and-multiple-configurations/1292/1 "2020-05-29T05:01:24Z")

</div>

I want to make a multi configuration package using `cpack -C` and the Visual Studio multi-generator. So, knowing that each of `RUNTIME`, `LIBRARY`, and `ARCHIVE` can appear only once in a call to `install()`, I tried writing the code below, which involves two nearly identical calls to `install()`. However, I get the following error:

```auto
CMake Error: install(EXPORT "Halide_Targets" ...) includes target "Halide" more than once in the export set.

```

If I remove the second “EXPORT” line, then the targets aren’t populated for the release builds! What am I supposed to do here?

> **Install code**
>
> ```auto
> install(TARGETS Halide Halide_Plugin Halide_Runtime ${EXTRA_TARGETS}
> EXPORT Halide_Targets
>   
> RUNTIME
> DESTINATION ${CMAKE_INSTALL_BINDIR}/Debug
> COMPONENT Halide_Runtime
> CONFIGURATIONS Debug
>   
> LIBRARY
> DESTINATION ${CMAKE_INSTALL_LIBDIR}/Debug
> COMPONENT Halide_Runtime
> NAMELINK_COMPONENT Halide_Development
> CONFIGURATIONS Debug
>   
> ARCHIVE
> DESTINATION ${CMAKE_INSTALL_LIBDIR}/Debug
> COMPONENT Halide_Development
> CONFIGURATIONS Debug
>   
> INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
> 
> install(TARGETS Halide Halide_Plugin Halide_Runtime ${EXTRA_TARGETS}
> EXPORT Halide_Targets
>   
> RUNTIME
> DESTINATION ${CMAKE_INSTALL_BINDIR}/Release
> COMPONENT Halide_Runtime
> CONFIGURATIONS Release RelWithDebInfo MinSizeRel
>   
> LIBRARY
> DESTINATION ${CMAKE_INSTALL_LIBDIR}/Release
> COMPONENT Halide_Runtime
> NAMELINK_COMPONENT Halide_Development
> CONFIGURATIONS Release RelWithDebInfo MinSizeRel
>   
> ARCHIVE
> DESTINATION ${CMAKE_INSTALL_LIBDIR}/Release
> COMPONENT Halide_Development
> CONFIGURATIONS Release RelWithDebInfo MinSizeRel
>   
> INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
> 
> install(EXPORT Halide_Targets
> DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Halide
> NAMESPACE Halide::
> FILE Halide-Targets.cmake
> COMPONENT Halide_Development)
> 
> ```

---

<div class="post-metadata">

### Author: ![alex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex/32/125_2.png) [@alex](https://discourse.cmake.org/u/alex)
#### Post date: [May 29, 2020, 9:11pm UTC](https://discourse.cmake.org/t/install-with-export-and-multiple-configurations/1292/2 "2020-05-29T21:11:33Z")

</div>

Apparently you just specify the `EXPORT` bit on the _last_ call to `install()` for those targets.

I don’t know whether that works by fluke or by design.

---

<div class="post-metadata">

### Author: ![craig.scott](https://discourse.cmake.org/user_avatar/discourse.cmake.org/craig.scott/32/20_2.png) [@craig.scott](https://discourse.cmake.org/u/craig.scott)
#### Post date: [May 30, 2020, 2:10am UTC](https://discourse.cmake.org/t/install-with-export-and-multiple-configurations/1292/3 "2020-05-30T02:10:07Z")

</div>

That doesn’t seem all that intuitive, I agree. It seems reasonable to expect that if you are separating out the `install(TARGETS)` calls for different configs for the same targets, you should be able to specify the export set for each call (perhaps with the restriction that it always has to be the same export set). @brad.king is this just a restriction of the current implementation, or is there an underlying reason why the original approach used by Alex leads to the reported error?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [June 1, 2020, 10:25am UTC](https://discourse.cmake.org/t/install-with-export-and-multiple-configurations/1292/4 "2020-06-01T10:25:38Z")

</div>

I think it is just a limitation of the current implementation. It probably isn’t tracking the `CONFIGURATIONS` of each time the target is associated with the export set.

---

<div class="post-metadata">

### Author: ![alex](https://discourse.cmake.org/user_avatar/discourse.cmake.org/alex/32/125_2.png) [@alex](https://discourse.cmake.org/u/alex)
#### Post date: [July 22, 2020, 1:02am UTC](https://discourse.cmake.org/t/install-with-export-and-multiple-configurations/1292/5 "2020-07-22T01:02:04Z")

</div>

At some point I discovered that doing this doesn’t work. It results in an empty “Halide-Targets-debug.cmake” file. I was using 3.16 in the OP and am using 3.18 now. Not sure if it never worked or if there was a regression. Regardless, using a generator expression is sufficient for my purposes here and _does_ work.

```auto
# Sends Debug -> Debug, Release/MinSizeRel/RelWithDebInfo -> Release
set(CONFIG_DIR $<IF:$<CONFIG:Debug>,Debug,Release>)

install(TARGETS Halide Halide_Plugin Halide_Runtime ${EXTRA_TARGETS}
        EXPORT Halide_Targets

        RUNTIME
        DESTINATION ${CMAKE_INSTALL_BINDIR}/${CONFIG_DIR}
        COMPONENT Halide_Runtime

        LIBRARY
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CONFIG_DIR}
        COMPONENT Halide_Runtime
        NAMELINK_COMPONENT Halide_Development

        ARCHIVE
        DESTINATION ${CMAKE_INSTALL_LIBDIR}/${CONFIG_DIR}
        COMPONENT Halide_Development

        INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

# install(EXPORT) as usual...

```
