# 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(_compile_features_to_gcc_flags _res _features) set(features ${_features}) # leave only cxx_std_nn items list(FILTER features INCLUDE REGEX cxx_std_) if (${features} STREQUAL "") set(${_res} "" PARENT_SCOPE) else() # if there are more than a single cxx_std_nn feature... list(SORT features) # take the most recent standard, i.e. the last element list(GET features -1 standard) # cmake calls it cxx_std_98, but we (obviously) want -std=c++03 string(REPLACE 98 03 standard "${standard}") string(REPLACE cxx_std_ -std=c++ standard "${standard}") set(${_res} "${standard}" PARENT_SCOPE) endif() endfunction() function(_get_target_property_merging_configs _var_name _target_name _propert_name) 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(CMAKE_CONFIGURATION_TYPES) list(APPEND configs ${CMAKE_CONFIGURATION_TYPES}) endif() foreach(cfg ${configs}) string(TOUPPER "${cfg}" 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_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 # that generator expression 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()