generate pkg-config files for targets (#1223)
This commit is contained in:
parent
a8355f1749
commit
ba948f8661
57
CMake/GeneratePkgConfig.cmake
Normal file
57
CMake/GeneratePkgConfig.cmake
Normal file
@ -0,0 +1,57 @@
|
||||
function(get_relative_link REL PATH)
|
||||
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)
|
||||
endfunction()
|
||||
|
||||
function(generate_pkgconfig TARGET DESCRIPTION)
|
||||
message("generating pkg-config for ${TARGET}")
|
||||
get_filename_component(PREFIX ${CMAKE_INSTALL_PREFIX} ABSOLUTE)
|
||||
|
||||
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()
|
||||
|
||||
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()
|
||||
|
||||
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" CONTENT
|
||||
"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}")
|
||||
|
||||
install(FILES "pkgconfig/${TARGET}.pc" DESTINATION "${CMAKE_INSTALL_PREFIX}/lib/pkgconfig")
|
||||
endfunction()
|
@ -981,6 +981,27 @@ install(TARGETS tdjson TdJson tdjson_static TdJsonStatic tdjson_private tdclient
|
||||
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
)
|
||||
|
||||
# generate pkg-config files
|
||||
include(GeneratePkgConfig)
|
||||
|
||||
generate_pkgconfig(tdutils "Telegram Library - Utils")
|
||||
generate_pkgconfig(tdactor "Telegram Library - Actor")
|
||||
generate_pkgconfig(tdnet "Telegram Library - Net")
|
||||
generate_pkgconfig(tdsqlite "Telegram Library - SQLite")
|
||||
generate_pkgconfig(tddb "Telegram Library - DataBase")
|
||||
if(MEMPROF)
|
||||
generate_pkgconfig(memprof "memprof - simple library for memory usage profiling")
|
||||
endif()
|
||||
generate_pkgconfig(tdcore "Telegram Library - Core")
|
||||
generate_pkgconfig(tdclient "Telegram Library - C++ Interface")
|
||||
if(TD_ENABLE_DOTNET)
|
||||
generate_pkgconfig(tddotnet "Telegram Library - C# Interface")
|
||||
endif()
|
||||
generate_pkgconfig(tdc "Telegram Library - C Interface")
|
||||
generate_pkgconfig(tdjson_private "Telegram Library - Json Interface (private)")
|
||||
generate_pkgconfig(tdjson "Telegram Library - Json Interface")
|
||||
generate_pkgconfig(tdjson_static "Telegram Library - Json Interface (static)")
|
||||
|
||||
install(EXPORT TdTargets
|
||||
FILE TdTargets.cmake
|
||||
NAMESPACE Td::
|
||||
|
Loading…
Reference in New Issue
Block a user