[tdlib] Add new port (#47690)

This commit is contained in:
Saikari
2025-10-20 18:36:57 +03:00
committed by GitHub
parent 8d478ade78
commit 42561dfdce
9 changed files with 271 additions and 0 deletions

158
ports/tdlib/fix-pc.patch Normal file
View File

@@ -0,0 +1,158 @@
diff --git a/CMake/GeneratePkgConfig.cmake b/CMake/GeneratePkgConfig.cmake
index 3d3fa01d1..9303a2f43 100644
--- a/CMake/GeneratePkgConfig.cmake
+++ b/CMake/GeneratePkgConfig.cmake
@@ -9,10 +9,20 @@ function(get_relative_link OUTPUT PATH)
if (IS_ABSOLUTE ${PATH})
get_filename_component(DIRECTORY_NAME "${PATH}" DIRECTORY)
if (WIN32)
- set(${OUTPUT} "-l\"${DIRECTORY_NAME}/${NAME}\"" PARENT_SCOPE)
+ # On Windows, library files can be libname.lib or name.lib
+ get_filename_component(FULL_NAME "${PATH}" NAME)
+ # Extract library name without lib prefix and extension
+ string(REGEX REPLACE "^lib(.+)\\.[^.]+$" "\\1" LIB_NAME "${FULL_NAME}")
+ # If the regex didn't match (no lib prefix), use the name without extension
+ if ("${LIB_NAME}" STREQUAL "${FULL_NAME}")
+ set(LIB_NAME "${NAME}")
+ endif()
+ set(${OUTPUT} "-L\"${DIRECTORY_NAME}\" -l${LIB_NAME}" PARENT_SCOPE)
else()
get_filename_component(FULL_NAME "${PATH}" NAME)
- set(${OUTPUT} "-L\"${DIRECTORY_NAME}\" -l:${FULL_NAME}" PARENT_SCOPE)
+ # Extract library name without lib prefix and extension for all platforms
+ string(REGEX REPLACE "^lib(.+)\\.[^.]+$" "\\1" LIB_NAME "${FULL_NAME}")
+ set(${OUTPUT} "-L\"${DIRECTORY_NAME}\" -l${LIB_NAME}" PARENT_SCOPE)
endif()
return()
endif()
@@ -31,17 +41,86 @@ function(generate_pkgconfig TARGET DESCRIPTION)
# message("Generating pkg-config for ${TARGET}")
get_filename_component(PREFIX "${CMAKE_INSTALL_PREFIX}" REALPATH)
- get_target_property(LIST "${TARGET}" LINK_LIBRARIES)
+ # Get the target type to handle interface libraries differently
+ get_target_property(LIBRARY_TYPE "${TARGET}" TYPE)
+
+ # For interface libraries, use INTERFACE_LINK_LIBRARIES instead of LINK_LIBRARIES
+ if ("${LIBRARY_TYPE}" STREQUAL "INTERFACE_LIBRARY")
+ get_target_property(LIST "${TARGET}" INTERFACE_LINK_LIBRARIES)
+ else()
+ get_target_property(LIST "${TARGET}" LINK_LIBRARIES)
+ endif()
+
+ # Handle the case when no libraries are found
+ if ("${LIST}" STREQUAL "LIST-NOTFOUND")
+ set(LIST "")
+ endif()
+
+ # Special handling for tdcore interface library
+ if ("${TARGET}" STREQUAL "tdcore" AND "${LIBRARY_TYPE}" STREQUAL "INTERFACE_LIBRARY")
+ # For tdcore interface library, we need to link to the actual part libraries
+ # instead of the non-existent tdcore library
+ set(TDCORE_LIBS "")
+ set(COMBINED_REQS "")
+ set(COMBINED_LIBS "")
+
+ foreach (PART_LIB ${LIST})
+ if (TARGET "${PART_LIB}" AND "${PART_LIB}" MATCHES "^tdcore_part[0-9]+$")
+ # Add the actual part library to link against
+ list(APPEND TDCORE_LIBS "-l${PART_LIB}")
+
+ # Collect dependencies from the parts
+ get_target_property(PART_LIST "${PART_LIB}" LINK_LIBRARIES)
+ if (NOT "${PART_LIST}" STREQUAL "PART_LIST-NOTFOUND")
+ foreach (PART_DEP ${PART_LIST})
+ if (TARGET "${PART_DEP}")
+ list(APPEND COMBINED_REQS "${PART_DEP}")
+ else()
+ list(APPEND COMBINED_LIBS "${PART_DEP}")
+ endif()
+ endforeach()
+ endif()
+ elseif (TARGET "${PART_LIB}")
+ list(APPEND COMBINED_REQS "${PART_LIB}")
+ else()
+ list(APPEND COMBINED_LIBS "${PART_LIB}")
+ endif()
+ endforeach()
+
+ # Remove duplicates
+ if (COMBINED_REQS)
+ list(REMOVE_DUPLICATES COMBINED_REQS)
+ endif()
+ if (COMBINED_LIBS)
+ list(REMOVE_DUPLICATES COMBINED_LIBS)
+ endif()
+ if (TDCORE_LIBS)
+ list(REMOVE_DUPLICATES TDCORE_LIBS)
+ endif()
+
+ set(LIST "")
+ list(APPEND LIST ${COMBINED_REQS})
+ list(APPEND LIST ${COMBINED_LIBS})
+
+ # Set a flag to use different Libs line for tdcore
+ set(USE_TDCORE_PARTS TRUE)
+ else()
+ set(USE_TDCORE_PARTS FALSE)
+ endif()
+
set(REQS "")
set(LIBS "")
foreach (LIB ${LIST})
if (TARGET "${LIB}")
- set(HAS_REQS 1)
- list(APPEND REQS "${LIB}")
+ # Skip internal tdcore parts as they don't have their own .pc files
+ if (NOT "${LIB}" MATCHES "^tdcore_part[0-9]+$")
+ set(HAS_REQS 1)
+ list(APPEND REQS "${LIB}")
+ endif()
else()
set(HAS_LIBS 1)
get_relative_link(LINK "${LIB}")
- if (NOT LINK EQUAL "")
+ if (NOT "${LINK}" STREQUAL "")
list(APPEND LIBS "${LINK}")
endif()
endif()
@@ -77,6 +156,19 @@ function(generate_pkgconfig TARGET DESCRIPTION)
endif()
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig")
+
+ # Generate the correct Libs line based on library type
+ if (USE_TDCORE_PARTS)
+ # For tdcore interface library, link to the actual part libraries
+ set(LIBS_LINE "")
+ foreach (PART_LIB ${TDCORE_LIBS})
+ set(LIBS_LINE "${LIBS_LINE} ${PART_LIB}")
+ endforeach()
+ set(LIBS_LINE "Libs: -L\"${PKGCONFIG_LIBDIR}\"${LIBS_LINE}")
+ else()
+ set(LIBS_LINE "Libs: -L\"${PKGCONFIG_LIBDIR}\" -l${TARGET}")
+ endif()
+
file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" CONTENT
"prefix=${PREFIX}
@@ -85,14 +177,14 @@ Description: ${DESCRIPTION}
Version: ${PROJECT_VERSION}
CFlags: -I\"${PKGCONFIG_INCLUDEDIR}\"
-Libs: -L\"${PKGCONFIG_LIBDIR}\" -l${TARGET}
+${LIBS_LINE}
${REQUIRES}${LIBRARIES}")
- get_target_property(LIBRARY_TYPE "${TARGET}" TYPE)
- if (LIBRARY_TYPE STREQUAL "STATIC_LIBRARY" OR LIBRARY_TYPE STREQUAL "SHARED_LIBRARY")
+ if ("${LIBRARY_TYPE}" STREQUAL "STATIC_LIBRARY" OR "${LIBRARY_TYPE}" STREQUAL "SHARED_LIBRARY")
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+ elseif ("${LIBRARY_TYPE}" STREQUAL "INTERFACE_LIBRARY")
+ # Interface libraries are also supported, install the .pc file
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
- elseif (LIBRARY_TYPE STREQUAL "INTERFACE_LIBRARY")
- # TODO: support interface libraries
else()
message(FATAL_ERROR "Don't know how to handle ${TARGET} of type ${LIBRARY_TYPE}")
endif()

View File

@@ -0,0 +1,35 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO tdlib/td
REF 7d257dcda5dd2c616c1146540ef51147c5bb2c69
HEAD_REF master
SHA512 fca25e017e6bc27bcc0a69b35ad478a5acfc46b511917440c3e560c18378c3f4133c1c553eb9a0752db5328f61c5813312d653f4ad5e5d0284b7a79d4f480be8
PATCHES
fix-pc.patch
)
vcpkg_add_to_path(PREPEND "${CURRENT_HOST_INSTALLED_DIR}/tools/gperf")
vcpkg_cmake_configure(
SOURCE_PATH ${SOURCE_PATH}
OPTIONS
-DTD_INSTALL_SHARED_LIBRARIES=OFF
-DTD_INSTALL_STATIC_LIBRARIES=ON
-DTD_ENABLE_JNI=${VCPKG_TARGET_IS_ANDROID}
-DTD_ENABLE_DOTNET=OFF
-DTD_GENERATE_SOURCE_FILES=OFF
-DTD_E2E_ONLY=OFF
-DTD_ENABLE_LTO=${CMAKE_HOST_WIN32}
-DTD_ENABLE_MULTI_PROCESSOR_COMPILATION=${VCPKG_DETECTED_MSVC}
-DBUILD_TESTING=OFF
MAYBE_UNUSED_VARIABLES
TD_ENABLE_MULTI_PROCESSOR_COMPILATION
)
vcpkg_cmake_install()
vcpkg_fixup_pkgconfig()
vcpkg_cmake_config_fixup(CONFIG_PATH "lib/cmake/Td")
vcpkg_copy_pdbs()
file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE_1_0.txt")

24
ports/tdlib/vcpkg.json Normal file
View File

@@ -0,0 +1,24 @@
{
"name": "tdlib",
"version": "1.8.55",
"description": "Cross-platform library for building Telegram clients",
"homepage": "https://github.com/tdlib/td",
"license": "BSL-1.0",
"supports": "((windows & !uwp & !arm & !arm64 & !xbox) | linux | osx) & static",
"dependencies": [
{
"name": "gperf",
"host": true
},
"openssl",
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
},
"zlib"
]
}

View File

@@ -0,0 +1,8 @@
set(VCPKG_POLICY_EMPTY_PACKAGE enabled)
vcpkg_find_acquire_program(PKGCONFIG)
vcpkg_cmake_configure(
SOURCE_PATH "${CURRENT_PORT_DIR}/project"
OPTIONS
"-DPKG_CONFIG_EXECUTABLE=${PKGCONFIG}"
)
vcpkg_cmake_build()

View File

@@ -0,0 +1,13 @@
cmake_minimum_required(VERSION 3.25.1)
project(tdlib-test CXX)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Td CONFIG REQUIRED)
add_executable(main main.cpp)
target_link_libraries(main PRIVATE Td::TdStatic)
find_package(PkgConfig REQUIRED)
pkg_check_modules(tdclient REQUIRED IMPORTED_TARGET tdclient)
add_executable(main2 main.cpp)
target_link_libraries(main2 PRIVATE PkgConfig::tdclient)

View File

@@ -0,0 +1,8 @@
#include <td/telegram/Client.h>
#include <memory>
int main()
{
std::unique_ptr<td::ClientManager> client_manager_;
auto response = client_manager_->receive(10);
return 0;
}

View File

@@ -0,0 +1,12 @@
{
"name": "vcpkg-ci-tdlib",
"version-string": "ci",
"description": "Validates tdlib",
"dependencies": [
"tdlib",
{
"name": "vcpkg-cmake",
"host": true
}
]
}

View File

@@ -9536,6 +9536,10 @@
"baseline": "1.0.3",
"port-version": 0
},
"tdlib": {
"baseline": "1.8.55",
"port-version": 0
},
"tdscpp": {
"baseline": "20250301",
"port-version": 0

9
versions/t-/tdlib.json Normal file
View File

@@ -0,0 +1,9 @@
{
"versions": [
{
"git-tree": "5adfd395e7ebb4f0e14359aee328ca198199d05b",
"version": "1.8.55",
"port-version": 0
}
]
}