2020-10-12 20:31:22 +02:00
|
|
|
function(get_relative_link REL PATH)
|
2020-10-12 20:39:48 +02:00
|
|
|
get_filename_component(NAME ${PATH} NAME_WE)
|
|
|
|
if(${NAME} MATCHES "^lib")
|
|
|
|
string(REGEX REPLACE "^lib" "-l" LINK ${NAME})
|
|
|
|
elseif(${NAME} MATCHES "^-")
|
|
|
|
set(LINK ${NAME})
|
|
|
|
else()
|
|
|
|
string(CONCAT LINK "-l" ${NAME})
|
|
|
|
endif()
|
|
|
|
set(${REL} ${LINK} PARENT_SCOPE)
|
2020-10-12 20:31:22 +02:00
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(generate_pkgconfig TARGET DESCRIPTION)
|
2020-10-12 20:39:48 +02:00
|
|
|
# message("Generating pkg-config for ${TARGET}")
|
|
|
|
get_filename_component(PREFIX ${CMAKE_INSTALL_PREFIX} ABSOLUTE)
|
2020-10-12 20:31:22 +02:00
|
|
|
|
2020-10-12 20:39:48 +02:00
|
|
|
get_target_property(LIST ${TARGET} LINK_LIBRARIES)
|
|
|
|
set(REQS "")
|
|
|
|
set(LIBS "")
|
|
|
|
foreach(LIB ${LIST})
|
|
|
|
if(TARGET ${LIB})
|
|
|
|
set(HAS_REQS 1)
|
|
|
|
list(APPEND REQS ${LIB})
|
|
|
|
else()
|
|
|
|
set(HAS_LIBS 1)
|
|
|
|
get_relative_link(LINK ${LIB})
|
|
|
|
list(APPEND LIBS ${LINK})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
2020-10-12 20:31:22 +02:00
|
|
|
|
2020-10-12 20:39:48 +02:00
|
|
|
if(HAS_REQS)
|
|
|
|
set(REQUIRES "\nRequires.private:")
|
|
|
|
foreach (REQ ${REQS})
|
|
|
|
string(APPEND REQUIRES " ${REQ}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
|
|
|
if(HAS_LIBS)
|
|
|
|
set(LIBRARIES "\nLibs.private:")
|
|
|
|
foreach (LIB ${LIBS})
|
|
|
|
string(APPEND LIBRARIES " ${LIB}")
|
|
|
|
endforeach()
|
|
|
|
endif()
|
2020-10-12 20:31:22 +02:00
|
|
|
|
2020-10-12 20:39:48 +02:00
|
|
|
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" CONTENT
|
2020-10-12 20:31:22 +02:00
|
|
|
"prefix=${PREFIX}
|
|
|
|
includedir=\${prefix}/include
|
|
|
|
libdir=\${prefix}/lib
|
|
|
|
|
|
|
|
Name: ${TARGET}
|
|
|
|
Description: ${DESCRIPTION}
|
|
|
|
Version: ${PROJECT_VERSION}
|
|
|
|
|
|
|
|
CFlags: -I\${includedir}
|
|
|
|
Libs: -L\${libdir} -l${TARGET}${REQUIRES}${LIBRARIES}")
|
|
|
|
|
2020-10-12 20:39:48 +02:00
|
|
|
install(FILES "pkgconfig/${TARGET}.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
|
2020-10-12 20:31:22 +02:00
|
|
|
endfunction()
|