include_guard(GLOBAL) function(myx_cmake_generate_pkgconfig target) set(options) set(oneVA COMPONENT BASENAME) set(multiVA) cmake_parse_arguments(ARG "${options}" "${oneVA}" "${multiVA}" ${ARGN}) if(NOT ARG_BASENAME) set(ARG_BASENAME ${target}) endif() if(NOT ARG_COMPONENT) set(ARG_COMPONENT dev) endif() get_target_property(__target_type ${target} TYPE) if(__target_type STREQUAL INTERFACE_LIBRARY) file( WRITE "${CMAKE_BINARY_DIR}/${ARG_BASENAME}.pc" "prefix=${CMAKE_INSTALL_PREFIX}\n" "exec_prefix=${CMAKE_INSTALL_PREFIX}\n" "includedir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n" "\n" "Name: ${ARG_BASENAME}\n" "Description: ${ARG_BASENAME} header-only library\n" "Version: ${PROJECT_VERSION}\n" "\n" "Requires:\n" "Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n") else() file( WRITE "${CMAKE_BINARY_DIR}/${ARG_BASENAME}.pc" "prefix=${CMAKE_INSTALL_PREFIX}\n" "exec_prefix=${CMAKE_INSTALL_PREFIX}\n" "libdir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}\n" "includedir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n" "\n" "Name: ${ARG_BASENAME}\n" "Description: ${ARG_BASENAME} library\n" "Version: ${PROJECT_VERSION}\n" "\n" "Requires:\n" "Libs: -L${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR} -l${target}\n" "Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n") endif() install( FILES "${CMAKE_BINARY_DIR}/${ARG_BASENAME}.pc" COMPONENT ${ARG_COMPONENT} DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig") endfunction()