myx-cmake/MyxCMake/modules/MyxCMakePkgConfig.cmake

51 lines
1.6 KiB
CMake
Raw Normal View History

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(
WRITE "${CMAKE_BINARY_DIR}/${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"
"Name: ${BASENAME}\n"
"Description: ${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(
WRITE "${CMAKE_BINARY_DIR}/${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"
"Name: ${BASENAME}\n"
"Description: ${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(
FILES "${CMAKE_BINARY_DIR}/${BASENAME}.pc"
2021-12-08 11:32:04 +00:00
COMPONENT ${ARG_COMPONENT}
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endfunction()