MAP_IMPORTED_CONFIG is hard to use and not documented well enough
The RelWithDebInfo configuration is required in order to perform profiling.
When using an external SDK which provides debug and release variants of libraries, the release variant of libraries should be used in the relwithdebinfo configuration. Otherwise (at least on Windows often) link errors result.
The MAP_IMPORTED_CONFIG_<CONFIG>
target property is provided to allow mapping a configuration CFG
to a location IMPORTED_LOCATION_${CFG}
, such as from RelWithDebInfo
configuration to the IMPORTED_LOCATION_RELEASE
.
It is not entirely clear whether it is the responsibility of the SDK authors to implement that mapping in config-file packages, or the responsibility of the consumer to map all of their third party dependencies properly. I suspect the former should be true, however the MAP_IMPORTED_CONFIG_*
properties are not exported when cmake creates IMPORTED
targets with install(EXPORT)
, so this is not currently implemented simply. Some buildsystems in the wild attempt to implement this externally: https://codereview.appspot.com/6670043/ . It may be by-design that only project code sets these properties: #16091 (closed) .
CMake should possibly document where the responsibility to set MAP_IMPORTED_CONFIG_<CONFIG>
lies and create simpler API for implementing it from the SDK if it should be set from there. Even if an SDK only sets the mappings for configs that it knows about, that would not prevent third parties from implementing mappings for custom configurations.
The somewhat non-intuitive behavior shown here is not documented:
https://cmake.org/pipermail/cmake-developers/2015-July/025843.html
This may or may not be worth documenting.
- The seemingly most-common usecase of mapping relwithdebinfo to release is not well-addressed. It seems to be a common pitfall: #20319
The trick/requirement to reorder configurations in IMPORTED_CONFIGURATIONS
is not documented: #16091 (closed)
Indeed, the order of entries in IMPORTED_CONFIGURATIONS
is not well-defined by the main config-file package generated by install(EXPORT)
.
- It is practical for projects to want to map relwithdebinfo to release using
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE)
and the existing documentation suggests that would be appropriate, but it does not work when some external dependencies (possibly from different third party SDKs) set only the non-config IMPORTED_LOCATION
property. In that case, a confusing error such as
ninja: error: 'thirdparty::somelib-NOTFOUND', needed by 'consumer', missing and no known rule to make it
is issued.
To make that usecase work, something like
set(CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO "" RELEASE)
is needed. This also appears here:
At least the documentation of this property could be improved to better address the common use-cases, but the design ideas in #20319 could also be worth exploring.
The attached project demonstrates the issue and starts to approximate an auto-test. configmap.tar.gz