From 2e3080feb0a26f6abf4a443f32e51c704ad7e4ea Mon Sep 17 00:00:00 2001 From: Eugene Shalygin Date: Mon, 23 Mar 2020 18:04:44 +0100 Subject: [PATCH] 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. --- cmake/Modules/GeneratePkgConfig.cmake | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/cmake/Modules/GeneratePkgConfig.cmake b/cmake/Modules/GeneratePkgConfig.cmake index 0a2f18a56..2099d68e4 100644 --- a/cmake/Modules/GeneratePkgConfig.cmake +++ b/cmake/Modules/GeneratePkgConfig.cmake @@ -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 "$<$:${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 "$<$:" "$<1:" vals "${vals}") + endif() endif() # HACK for static libraries cmake populates link dependencies as $. # pkg-config does not support special handling for static libraries and as such we will remove