myx-cmake/MyxCMake/modules/MyxCMakePkgConfig.cmake

54 lines
1.6 KiB
CMake
Raw Normal View History

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)
set(oneVA COMPONENT BASENAME)
2021-12-08 11:32:04 +00:00
set(multiVA)
cmake_parse_arguments(ARG "${options}" "${oneVA}" "${multiVA}" ${ARGN})
if(NOT ARG_BASENAME)
set(ARG_BASENAME ${target})
endif()
2021-12-08 11:32:04 +00:00
if(NOT ARG_COMPONENT)
set(ARG_COMPONENT dev)
2021-12-08 11:32:04 +00:00
endif()
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()