2022-05-06 09:49:46 +00:00
|
|
|
include_guard(GLOBAL)
|
|
|
|
|
|
|
|
|
2021-12-08 11:32:04 +00:00
|
|
|
function(myx_cmake_generate_pkgconfig target)
|
|
|
|
set(options)
|
2021-12-10 12:33:19 +00:00
|
|
|
set(oneVA COMPONENT BASENAME)
|
2021-12-08 11:32:04 +00:00
|
|
|
set(multiVA)
|
|
|
|
|
|
|
|
cmake_parse_arguments(ARG "${options}" "${oneVA}" "${multiVA}" ${ARGN})
|
|
|
|
|
2021-12-10 12:33:19 +00:00
|
|
|
if(NOT ARG_BASENAME)
|
|
|
|
set(ARG_BASENAME ${target})
|
|
|
|
endif()
|
|
|
|
|
2021-12-08 11:32:04 +00:00
|
|
|
if(NOT ARG_COMPONENT)
|
2021-12-09 14:14:28 +00:00
|
|
|
set(ARG_COMPONENT dev)
|
2021-12-08 11:32:04 +00:00
|
|
|
endif()
|
|
|
|
|
2021-12-10 12:33:19 +00:00
|
|
|
get_target_property(__target_type ${target} TYPE)
|
|
|
|
if(__target_type STREQUAL INTERFACE_LIBRARY)
|
2021-12-08 11:32:04 +00:00
|
|
|
file(
|
2021-12-24 12:09:01 +00:00
|
|
|
WRITE "${CMAKE_BINARY_DIR}/${ARG_BASENAME}.pc"
|
2021-12-08 11:32:04 +00:00
|
|
|
"prefix=${CMAKE_INSTALL_PREFIX}\n"
|
|
|
|
"exec_prefix=${CMAKE_INSTALL_PREFIX}\n"
|
|
|
|
"includedir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n"
|
|
|
|
"\n"
|
2021-12-24 12:09:01 +00:00
|
|
|
"Name: ${ARG_BASENAME}\n"
|
|
|
|
"Description: ${ARG_BASENAME} header-only library\n"
|
2021-12-08 11:32:04 +00:00
|
|
|
"Version: ${PROJECT_VERSION}\n"
|
|
|
|
"\n"
|
|
|
|
"Requires:\n"
|
|
|
|
"Cflags: -I${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n")
|
|
|
|
else()
|
|
|
|
file(
|
2021-12-24 12:09:01 +00:00
|
|
|
WRITE "${CMAKE_BINARY_DIR}/${ARG_BASENAME}.pc"
|
2021-12-08 11:32:04 +00:00
|
|
|
"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"
|
2021-12-24 12:09:01 +00:00
|
|
|
"Name: ${ARG_BASENAME}\n"
|
|
|
|
"Description: ${ARG_BASENAME} library\n"
|
2021-12-08 11:32:04 +00:00
|
|
|
"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(
|
2021-12-24 12:09:01 +00:00
|
|
|
FILES "${CMAKE_BINARY_DIR}/${ARG_BASENAME}.pc"
|
2021-12-08 11:32:04 +00:00
|
|
|
COMPONENT ${ARG_COMPONENT}
|
|
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
|
|
|
endfunction()
|