# This module provides generate_and_install_pkg_config_file() function. # The function takes target name and expects a fully configured project, i.e. with set version and # description. The function extracts interface libraries, include dirs, definitions and options # from the target and generates pkg-config file with install() command # The function expands imported targets and generator expressions # save the current file dir for later use in the generate_and_install_pkg_config_file() function set(_GeneratePkGConfigDir "${CMAKE_CURRENT_LIST_DIR}/GeneratePkgConfig") include(GNUInstallDirs) function(_get_target_property_merging_configs _var_name _target_name _propert_name) get_target_property(vals ${_target_name} ${_propert_name}) if (NOT vals) if (CMAKE_BUILD_TYPE) list(APPEND configs ${CMAKE_BUILD_TYPE}) elseif() 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}") 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) list(APPEND vals "$<$:${val_for_cfg}>") endif() endforeach() endif() # HACK file(GENERATE), which we use foe expanding generator expressions, is BUILD_INTERFACE, # but we need INSTALL_INTERFACE here. As such, let us inter-change them. string(REPLACE "$") configure_file("${_GeneratePkGConfigDir}/generate-pkg-config.cmake.in" "${_generate_target_dir}/${cfg}/generate-pkg-config.cmake" @ONLY) install(SCRIPT "${_generate_target_dir}/${cfg}/generate-pkg-config.cmake") endforeach() endif() endfunction()