macro ( sanitize_property_dirs target property ) set(_cleandirs) get_target_property(_dirs ${target} ${property}) if(_dirs) foreach(_d IN LISTS _dirs) if(EXISTS ${_d}) list(APPEND _cleandirs ${_d}) else() message(DEBUG "removing spurious directory ${_d} from property ${property} of target ${target}") endif() endforeach() set_property(TARGET ${target} PROPERTY ${property} ${_cleandirs}) endif() endmacro ( sanitize_property_dirs ) macro ( sanitize_target_dirs target ) if (TARGET ${target}) message(DEBUG "performing sanitize_target_dirs(${target})") sanitize_property_dirs( ${target} INTERFACE_INCLUDE_DIRECTORIES ) sanitize_property_dirs( ${target} INTERFACE_SYSTEM_INCLUDE_DIRECTORIES ) sanitize_property_dirs( ${target} INTERFACE_LINK_DIRECTORIES ) endif() endmacro ( sanitize_target_dirs ) macro ( generate_pkgconfig_spec template outfile target ) #message(DEBUG "generate_pkgconfig_spec: ${outfile} from template: ${template}") if (TARGET ${target}) # retrieve all the private libs we depend on get_target_property (_libs ${target} INTERFACE_LINK_LIBRARIES) set(_cleanlibs) foreach(_lib IN LISTS _libs) if (TARGET ${_lib}) get_target_property(_tlibs ${_lib} INTERFACE_LINK_LIBRARIES) foreach(_clib IN LISTS _tlibs) get_filename_component(_name "${_clib}" NAME) string(REGEX REPLACE "^lib" "" _clib ${_name}) string(REGEX REPLACE ".so$" "" _clib ${_clib}) list(APPEND _cleanlibs ${_clib}) endforeach() else() list(APPEND _cleanlibs ${_lib}) endif() endforeach() list(REMOVE_DUPLICATES _cleanlibs) set (LIBS_PRIVATE ${_cleanlibs}) # make a copy set ( LIBS_PRIVATE_WITH_PATH ${LIBS_PRIVATE} ) # this matches any path and any flag entries (starting with '-') set ( LIB_LIST_REGEX "(^(.+)\/([^\/]+)$)|(^\-.*$)" ) # remove all entries from the list which are specified by path and which already have -l list ( FILTER LIBS_PRIVATE EXCLUDE REGEX ${LIB_LIST_REGEX} ) # include only entries specifed by path list ( FILTER LIBS_PRIVATE_WITH_PATH INCLUDE REGEX ${LIB_LIST_REGEX} ) # prepend the linker flag to all entries except the ones that already have it list ( TRANSFORM LIBS_PRIVATE PREPEND "-l") list ( JOIN LIBS_PRIVATE " " LIBS_PRIVATE_JOINED ) list ( JOIN LIBS_PRIVATE_WITH_PATH " " LIBS_PRIVATE_WITH_PATH_JOINED ) configure_file ( ${template} ${outfile} IMMEDIATE @ONLY) endif() endmacro ( generate_pkgconfig_spec ) macro ( unset_pkg_config _prefix ) unset ( ${_prefix}_VERSION CACHE ) unset ( ${_prefix}_PREFIX CACHE ) unset ( ${_prefix}_CFLAGS CACHE ) unset ( ${_prefix}_CFLAGS_OTHER CACHE ) unset ( ${_prefix}_LDFLAGS CACHE ) unset ( ${_prefix}_LDFLAGS_OTHER CACHE ) unset ( ${_prefix}_LIBRARIES CACHE ) unset ( ${_prefix}_INCLUDEDIR CACHE ) unset ( ${_prefix}_INCLUDE_DIRS CACHE ) unset ( ${_prefix}_LIBDIR CACHE ) unset ( ${_prefix}_LIBRARY_DIRS CACHE ) unset ( __pkg_config_checked_${_prefix} CACHE ) endmacro ( unset_pkg_config )