[cmake-developers] [PATCH] CMakeExpandImportedTargets: use INTERFACE_LINK_LIBRARIES if non-empty
Tamás Kenéz
tamas.kenez at gmail.com
Thu Jul 16 11:29:39 EDT 2015
I submitted a patch to update `CMakeExpandImportedTargets` with
`INTERFACE_LINK_LIBRARIES`.
Shortly after I read the discussion at http://www.cmake
.org/Bug/view.php?id=15299 which suggested `CMakeExpandImportedTargets` is
deprecated and one should use `BundleUtilities` instead.
Well, it seems that `BundleUtilities` can't expand a single static imported
library target to the list of all dependent libraries (that's what I need)
so I think `CMakeExpandImportedTargets` is still benefitial and could be
benefitial to others, too.
My patch enables `CMakeExpandImportedTargets` to use the
`INTERFACE_LINK_LIBRARIES`
property and also resolves the $<CONFIG>, $<NOT> and $<0|1:> generator
expressions. I found no elegant way to resolve all generator expressions
(`file(GENERATE ...)` can't be used since it does not output the resolved
content instantly).
Tamas
On Wed, Jul 15, 2015 at 5:56 PM, Tamás Kenéz <tamas.kenez at gmail.com> wrote:
> The CMakeExpandedImportedTargets module used only the deprecated
> IMPORTED_LINK_INTERFACE_LIBRARIES property to resolve transitive
> dependencies.
> Since the current `install(EXPORT ...)` command generates target files
> that populate INTERFACE_LINK_LIBRARIES instead, the expand module was not
> working correctly with the imported libraries generated by `install(EXPORT
> ...)`.
>
> I considered this a bugfix so I based the commit onto the release branch.
>
> Please review and apply if it's ok.
> Tamas
>
>
> From f2df88ec4180595a3fcc4c6be9b2d38e46162cc3 Mon Sep 17 00:00:00 2001
> From: Tamas Kenez <tamas.kenez at gmail.com>
> Date: Wed, 15 Jul 2015 17:47:50 +0200
> Subject: [PATCH] CMakeExpandImportedTargets: use INTERFACE_LINK_LIBRARIES
> if
> non-empty
>
> The deprecated IMPORTED_LINK_INTERFACE_LIBRARIES should be
> overridden by INTERFACE_LINK_LIBRARIES if it's non-empty.
>
> Unlike IMPORTED_LINK_INTERFACE_LIBRARIES, INTERFACE_LINK_LIBRARIES
> usually contains config-related generator expressions which must
> be resolved according to the selected configuration.
> ---
> Modules/CMakeExpandImportedTargets.cmake | 22 +++++++++++++++++++++-
> 1 file changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/Modules/CMakeExpandImportedTargets.cmake
> b/Modules/CMakeExpandImportedTargets.cmake
> index 8ac3364..b110e51 100644
> --- a/Modules/CMakeExpandImportedTargets.cmake
> +++ b/Modules/CMakeExpandImportedTargets.cmake
> @@ -102,7 +102,27 @@ function(CMAKE_EXPAND_IMPORTED_TARGETS _RESULT )
> list(GET _importedConfigs ${_configIndexToUse}
> _importedConfigToUse)
>
> get_target_property(_importedLocation "${_CURRENT_LIB}"
> IMPORTED_LOCATION_${_importedConfigToUse})
> - get_target_property(_linkInterfaceLibs "${_CURRENT_LIB}"
> IMPORTED_LINK_INTERFACE_LIBRARIES_${_importedConfigToUse} )
> + get_target_property(_linkInterfaceLibs "${_CURRENT_LIB}"
> INTERFACE_LINK_LIBRARIES)
> + if(_linkInterfaceLibs)
> + # resolve $<CONFIG:...> generator expressions
> + string(REGEX REPLACE "\\$<CONFIG:${_importedConfigToUse}>"
> "1"
> + _linkInterfaceLibs "${_linkInterfaceLibs}")
> + string(REGEX REPLACE "\\$<CONFIG:[^>]*>" "0"
> + _linkInterfaceLibs "${_linkInterfaceLibs}")
> + # resolve $<NOT:(0|1)>
> + string(REGEX REPLACE "\\$<NOT:0>" "1"
> + _linkInterfaceLibs "${_linkInterfaceLibs}")
> + string(REGEX REPLACE "\\$<NOT:1>" "0"
> + _linkInterfaceLibs "${_linkInterfaceLibs}")
> + # resolve $<(0|1):...>
> + # empty items will be ignored by `foreach` later
> + string(REGEX REPLACE "\\$<0:[^>]*>" ""
> + _linkInterfaceLibs "${_linkInterfaceLibs}")
> + string(REGEX REPLACE "\\$<1:([^>]*)>" "\\1"
> + _linkInterfaceLibs "${_linkInterfaceLibs}")
> + else()
> + get_target_property(_linkInterfaceLibs "${_CURRENT_LIB}"
> IMPORTED_LINK_INTERFACE_LIBRARIES_${_importedConfigToUse} )
> + endif()
>
> list(APPEND _CCSR_NEW_REQ_LIBS "${_importedLocation}")
> # message(STATUS "Appending lib ${_CURRENT_LIB} as
> ${_importedLocation}")
> --
> 1.9.4.msysgit.2
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake-developers/attachments/20150716/128fc9da/attachment.html>
More information about the cmake-developers
mailing list