# Handling of IMPORTED targets and MSVC\_RUNTIME\_LIBRARY

**URL:** https://discourse.cmake.org/t/handling-of-imported-targets-and-msvc-runtime-library/11618
**Category:** Code
**Tags:** os:windows, gen:vs
**Created:** [September 9, 2024, 4:54am UTC](https://discourse.cmake.org/t/handling-of-imported-targets-and-msvc-runtime-library/11618 "2024-09-09T04:54:03Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![nappl](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/n/a3d4f5/32.png) [@nappl](https://discourse.cmake.org/u/nappl)
#### Post date: [September 9, 2024, 4:54am UTC](https://discourse.cmake.org/t/handling-of-imported-targets-and-msvc-runtime-library/11618/1 "2024-09-09T04:54:03Z")

</div>

I have a set of header files for a static library along with multiple implementations for different operating systems and build configurations - these include the 4 MSVC runtime library configurations for Windows (md, mdd, mt, mtd). I would like to create a CMake imported target which will select the correct library for the different CMake configs of the imported target (which is determined from `CMAKE_MSVC_RUNTIME_LIBRARY` if it is set, otherwise some default).

If the `IMPORTED_LOCATION` property were able to be set to a generator expression, I think this would be straight-forward, but as generator expressions are not permitted in this context, I am unsure how to approach doing this.

I cannot probe `CMAKE_MSVC_RUNTIME_LIBRARY` with `if()` statements, because it could expand to a string containing a generator expression.

The `IMPORTED_LOCATION_{CONFIG}` properties are no help either, because they also do not accept generator expressions.

The best I can think of is: to have 4 separate targets which correspond to each runtime configuration, and use generator expressions in a `target_link_libraries()` (which is valid) to select the correct one when linking against the imported target. Something like:

```auto
    target_link_libraries(the_thing INTERFACE the_thing_$<IF:$<STREQUAL:${CMAKE_MSVC_RUNTIME_LIBRARY},MultiThreadedDebug>,mtd,$<IF:$<STREQUAL:${CMAKE_MSVC_RUNTIME_LIBRARY},MultiThreaded>,mt,$<IF:$<STREQUAL:${CMAKE_MSVC_RUNTIME_LIBRARY},MultiThreadedDebugDLL>,mdd,md>>>)

```

Any ideas?
