Fix PkgConfig generation on Arch

Use first available configuration from the IMPORTED_CONFIGURATIONS list
if no valid property value was found via current or mapped
configurations.

Fixes #4416.
This commit is contained in:
Eugene Shalygin 2020-03-23 18:04:44 +01:00 committed by Arvid Norberg
parent edf6660820
commit 2e3080feb0
1 changed files with 19 additions and 7 deletions

View File

@ -28,27 +28,39 @@ function(_compile_features_to_gcc_flags _res _features)
endfunction()
function(_get_target_property_merging_configs _var_name _target_name _propert_name)
get_target_property(vals ${_target_name} ${_propert_name})
if (NOT vals)
set(vals "")
get_property(prop_set TARGET ${_target_name} PROPERTY ${_propert_name} SET)
if (prop_set)
get_property(vals TARGET ${_target_name} PROPERTY ${_propert_name})
else()
if (CMAKE_BUILD_TYPE)
list(APPEND configs ${CMAKE_BUILD_TYPE})
elseif()
elseif(CMAKE_CONFIGURATION_TYPES)
list(APPEND configs ${CMAKE_CONFIGURATION_TYPES})
endif()
foreach(cfg ${configs})
string(TOUPPER "${cfg}" UPPERCFG)
get_target_property(mapped_configs ${_target_name} "MAP_IMPORTED_CONFIG_${UPPERCFG}")
get_property(mapped_configs TARGET ${_target_name} PROPERTY "MAP_IMPORTED_CONFIG_${UPPERCFG}")
if (mapped_configs)
list(GET "${mapped_configs}" 0 target_cfg)
else()
set(target_cfg "${UPPERCFG}")
endif()
get_target_property(val_for_cfg ${_target_name} "${_propert_name}_${target_cfg}")
if (val_for_cfg)
get_property(prop_set TARGET ${_target_name} PROPERTY ${_propert_name}_${target_cfg} SET)
if (prop_set)
get_property(val_for_cfg TARGET ${_target_name} PROPERTY ${_propert_name}_${target_cfg})
list(APPEND vals "$<$<CONFIG:${cfg}>:${val_for_cfg}>")
break()
endif()
endforeach()
if (NOT prop_set)
get_property(imported_cfgs TARGET ${_target_name} PROPERTY IMPORTED_CONFIGURATIONS)
# CMake docs say we can use any of the imported configs
list(GET imported_cfgs 0 imported_config)
get_property(vals TARGET ${_target_name} PROPERTY ${_propert_name}_${imported_config})
# remove config generator expression. Only in this case! Notice we use such expression
# ourselves in the loop above
string(REPLACE "$<$<CONFIG:${imported_config}>:" "$<1:" vals "${vals}")
endif()
endif()
# HACK for static libraries cmake populates link dependencies as $<LINK_ONLY:lib_name>.
# pkg-config does not support special handling for static libraries and as such we will remove