48 lines
1.5 KiB
CMake
48 lines
1.5 KiB
CMake
function(myx_cmake_generate_pkgconfig target)
|
|
set(options)
|
|
set(oneVA COMPONENT)
|
|
set(multiVA)
|
|
|
|
cmake_parse_arguments(ARG "${options}" "${oneVA}" "${multiVA}" ${ARGN})
|
|
|
|
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}/${target}.pc"
|
|
"prefix=${CMAKE_INSTALL_PREFIX}\n"
|
|
"exec_prefix=${CMAKE_INSTALL_PREFIX}\n"
|
|
"includedir=${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}\n"
|
|
"\n"
|
|
"Name: ${target}\n"
|
|
"Description: ${target} 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}/${target}.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: ${target}\n"
|
|
"Description: ${target} 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}/${target}.pc"
|
|
COMPONENT ${ARG_COMPONENT}
|
|
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
|
|
endfunction()
|