summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/CMake
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-09-29 14:24:23 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-09-29 19:04:02 +0300
commit8e36edeef44005c24fa574fbb90556442a6a516f (patch)
treee4766ace481283264e172b243b3026c26f47bd89 /protocols/Telegram/tdlib/td/CMake
parent55793991ad8b130f5146c1b72bfa0d126ce13456 (diff)
TDLIB: copyright updates & code cleaning
Diffstat (limited to 'protocols/Telegram/tdlib/td/CMake')
-rw-r--r--protocols/Telegram/tdlib/td/CMake/AddCXXCompilerFlag.cmake4
-rw-r--r--protocols/Telegram/tdlib/td/CMake/FindAtomics.cmake62
-rw-r--r--protocols/Telegram/tdlib/td/CMake/GeneratePkgConfig.cmake1
-rw-r--r--protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake2
-rw-r--r--protocols/Telegram/tdlib/td/CMake/TdSetUpCompiler.cmake14
-rw-r--r--protocols/Telegram/tdlib/td/CMake/iOS.cmake37
6 files changed, 110 insertions, 10 deletions
diff --git a/protocols/Telegram/tdlib/td/CMake/AddCXXCompilerFlag.cmake b/protocols/Telegram/tdlib/td/CMake/AddCXXCompilerFlag.cmake
index 2162dadb26..6fb615a1f7 100644
--- a/protocols/Telegram/tdlib/td/CMake/AddCXXCompilerFlag.cmake
+++ b/protocols/Telegram/tdlib/td/CMake/AddCXXCompilerFlag.cmake
@@ -21,14 +21,14 @@ include(CheckCXXCompilerFlag)
function(mangle_compiler_flag FLAG OUTPUT)
string(TOUPPER "HAVE_CXX_FLAG_${FLAG}" SANITIZED_FLAG)
- string(REPLACE "+" "X" SANITIZED_FLAG "${SANITIZED_FLAG}")
+ string(REPLACE "+" "X" SANITIZED_FLAG ${SANITIZED_FLAG})
string(REGEX REPLACE "[^A-Za-z_0-9]" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
string(REGEX REPLACE "_+" "_" SANITIZED_FLAG ${SANITIZED_FLAG})
set(${OUTPUT} "${SANITIZED_FLAG}" PARENT_SCOPE)
endfunction(mangle_compiler_flag)
function(add_cxx_compiler_flag FLAG)
- string(REPLACE "-Wno-" "-W" MAIN_FLAG "${FLAG}")
+ string(REPLACE "-Wno-" "-W" MAIN_FLAG ${FLAG})
mangle_compiler_flag("${MAIN_FLAG}" MANGLED_FLAG_NAME)
if (DEFINED CMAKE_REQUIRED_FLAGS)
set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
diff --git a/protocols/Telegram/tdlib/td/CMake/FindAtomics.cmake b/protocols/Telegram/tdlib/td/CMake/FindAtomics.cmake
new file mode 100644
index 0000000000..a855132581
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/CMake/FindAtomics.cmake
@@ -0,0 +1,62 @@
+# Original issue:
+# * https://gitlab.kitware.com/cmake/cmake/-/issues/23021#note_1098733
+#
+# For reference:
+# * https://gcc.gnu.org/wiki/Atomic/GCCMM
+#
+# riscv64 specific:
+# * https://lists.debian.org/debian-riscv/2022/01/msg00009.html
+#
+# ATOMICS_FOUND - system has C++ atomics
+# ATOMICS_LIBRARIES - libraries needed to use C++ atomics
+
+if (ATOMICS_FOUND)
+ return()
+endif()
+
+include(CheckCXXSourceCompiles)
+
+# RISC-V only has 32-bit and 64-bit atomic instructions. GCC is supposed
+# to convert smaller atomics to those larger ones via masking and
+# shifting like LLVM, but it's a known bug that it does not. This means
+# anything that wants to use atomics on 1-byte or 2-byte types needs
+# to link atomic library, but not 4-byte or 8-byte (though it does no harm).
+set(ATOMIC_CODE
+ "
+ #include <atomic>
+ #include <cstdint>
+ std::atomic<std::uint8_t> n8{0}; // riscv64
+ std::atomic<std::uint64_t> n64{0}; // armel, mipsel, powerpc
+ int main() {
+ ++n8;
+ ++n64;
+ }")
+
+set(ATOMICS_LIBS " " "-latomic")
+if (CMAKE_SYSTEM_NAME MATCHES "NetBSD")
+ set(ATOMICS_LIBS "${ATOMICS_LIBS}" /usr/pkg/gcc12/x86_64--netbsd/lib/libatomic.so /usr/pkg/gcc12/i486--netbsdelf/lib/libatomic.so)
+endif()
+
+foreach (ATOMICS_LIBRARY ${ATOMICS_LIBS})
+ unset(ATOMICS_FOUND CACHE)
+ set(CMAKE_REQUIRED_LIBRARIES "${ATOMICS_LIBRARY}")
+ check_cxx_source_compiles("${ATOMIC_CODE}" ATOMICS_FOUND)
+ unset(CMAKE_REQUIRED_LIBRARIES)
+ if (ATOMICS_FOUND)
+ if (NOT ATOMICS_LIBRARY STREQUAL " ")
+ include(FindPackageHandleStandardArgs)
+ find_package_handle_standard_args(Atomics DEFAULT_MSG ATOMICS_LIBRARY)
+ set(ATOMICS_LIBRARIES "${ATOMICS_LIBRARY}" CACHE STRING "Atomic library" FORCE)
+ else()
+ set(ATOMICS_LIBRARIES "" CACHE STRING "Atomic operations library" FORCE)
+ endif()
+ break()
+ endif()
+endforeach()
+if (Atomics_FIND_REQUIRED AND NOT ATOMICS_FOUND)
+ message(FATAL_ERROR "Atomic operations library isn't found.")
+endif()
+
+unset(ATOMICS_LIBRARY)
+unset(ATOMICS_LIBS)
+unset(ATOMIC_CODE)
diff --git a/protocols/Telegram/tdlib/td/CMake/GeneratePkgConfig.cmake b/protocols/Telegram/tdlib/td/CMake/GeneratePkgConfig.cmake
index afbe06ac60..a2800e1073 100644
--- a/protocols/Telegram/tdlib/td/CMake/GeneratePkgConfig.cmake
+++ b/protocols/Telegram/tdlib/td/CMake/GeneratePkgConfig.cmake
@@ -27,6 +27,7 @@ function(get_relative_link OUTPUT PATH)
set(${OUTPUT} "${LINK}" PARENT_SCOPE)
endfunction()
+# TODO: support interface libraries in dependencies
function(generate_pkgconfig TARGET DESCRIPTION)
# message("Generating pkg-config for ${TARGET}")
get_filename_component(PREFIX "${CMAKE_INSTALL_PREFIX}" REALPATH)
diff --git a/protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake b/protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake
index 420772966c..724d078216 100644
--- a/protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake
+++ b/protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake
@@ -71,7 +71,7 @@ function(get_git_head_revision _refspecvar _hashvar)
return()
endif()
- find_package(Git)
+ find_package(Git QUIET)
# Check if the current source dir is a git submodule or a worktree.
# In both cases .git is a file instead of a directory.
diff --git a/protocols/Telegram/tdlib/td/CMake/TdSetUpCompiler.cmake b/protocols/Telegram/tdlib/td/CMake/TdSetUpCompiler.cmake
index 536c5efb29..747d0aaa75 100644
--- a/protocols/Telegram/tdlib/td/CMake/TdSetUpCompiler.cmake
+++ b/protocols/Telegram/tdlib/td/CMake/TdSetUpCompiler.cmake
@@ -1,4 +1,4 @@
-# - Configures C++14 compiler, setting TDLib-specific compilation options.
+# Configures C++14 compiler, setting TDLib-specific compilation options.
function(td_set_up_compiler)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1 PARENT_SCOPE)
@@ -62,6 +62,8 @@ function(td_set_up_compiler)
set(TD_LINKER_FLAGS "-Wl,-z,ignore")
elseif (EMSCRIPTEN)
set(TD_LINKER_FLAGS "-Wl,--gc-sections")
+ elseif (ANDROID)
+ set(TD_LINKER_FLAGS "-Wl,--gc-sections -Wl,--exclude-libs,ALL -Wl,--icf=safe")
else()
set(TD_LINKER_FLAGS "-Wl,--gc-sections -Wl,--exclude-libs,ALL")
endif()
@@ -121,8 +123,12 @@ function(td_set_up_compiler)
add_cxx_compiler_flag("-Wdeprecated")
add_cxx_compiler_flag("-Wno-unused-command-line-argument")
add_cxx_compiler_flag("-Qunused-arguments")
+ add_cxx_compiler_flag("-Wno-unknown-warning-option")
add_cxx_compiler_flag("-Wodr")
add_cxx_compiler_flag("-flto-odr-type-merging")
+ add_cxx_compiler_flag("-Wno-psabi")
+ add_cxx_compiler_flag("-Wunused-member-function")
+ add_cxx_compiler_flag("-Wunused-private-field")
# add_cxx_compiler_flag("-Werror")
@@ -135,7 +141,7 @@ function(td_set_up_compiler)
# add_cxx_compiler_flag("-Wzero-as-null-pointer-constant")
endif()
- if (GCC AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0))
+ if (GCC)
add_cxx_compiler_flag("-Wno-maybe-uninitialized") # too many false positives
endif()
if (WIN32 AND GCC AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 8.0))
@@ -154,6 +160,10 @@ function(td_set_up_compiler)
# https://stackoverflow.com/questions/26744556/warning-returning-a-captured-reference-from-a-lambda
add_cxx_compiler_flag("-Wno-return-stack-address")
endif()
+ if (GCC AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 13.0))
+ # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104030
+ add_cxx_compiler_flag("-Wbidi-chars=none")
+ endif()
if (MINGW)
add_cxx_compiler_flag("-ftrack-macro-expansion=0")
diff --git a/protocols/Telegram/tdlib/td/CMake/iOS.cmake b/protocols/Telegram/tdlib/td/CMake/iOS.cmake
index 55e3f42c18..4ef76bd0f6 100644
--- a/protocols/Telegram/tdlib/td/CMake/iOS.cmake
+++ b/protocols/Telegram/tdlib/td/CMake/iOS.cmake
@@ -45,7 +45,7 @@ set (CMAKE_OSX_DEPLOYMENT_TARGET "" CACHE STRING "Force unset of the deployment
# Determine the cmake host system version so we know where to find the iOS SDKs
find_program (CMAKE_UNAME uname /bin /usr/bin /usr/local/bin)
if (CMAKE_UNAME)
- exec_program(uname ARGS -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION)
+ execute_process(COMMAND uname -r OUTPUT_VARIABLE CMAKE_HOST_SYSTEM_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE)
string (REGEX REPLACE "^([0-9]+)\\.([0-9]+).*$" "\\1" DARWIN_MAJOR_VERSION "${CMAKE_HOST_SYSTEM_VERSION}")
endif (CMAKE_UNAME)
@@ -114,6 +114,23 @@ elseif (IOS_PLATFORM STREQUAL "TVSIMULATOR")
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-tvsimulator")
set (APPLE_TV True)
+elseif (IOS_PLATFORM STREQUAL "VISIONOS")
+ set (IOS_PLATFORM_LOCATION "XROS.platform")
+ set (XCODE_IOS_PLATFORM xros)
+
+ # This causes the installers to properly locate the output libraries
+ set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-xros")
+
+ set (APPLE_VISION True)
+elseif (IOS_PLATFORM STREQUAL "VISIONSIMULATOR")
+ set (SIMULATOR_FLAG true)
+ set (IOS_PLATFORM_LOCATION "XRSimulator.platform")
+ set (XCODE_IOS_PLATFORM xros-simulator)
+
+ # This causes the installers to properly locate the output libraries
+ set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-xrsimulator")
+
+ set (APPLE_VISION True)
else (IOS_PLATFORM STREQUAL "OS")
message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS, SIMULATOR, or WATCHOS.")
endif ()
@@ -163,7 +180,7 @@ set (IOS_DEPLOYMENT_TARGET ${IOS_DEPLOYMENT_TARGET} CACHE STRING "Minimum iOS ve
# Setup iOS developer location unless specified manually with CMAKE_IOS_DEVELOPER_ROOT
# Note Xcode 4.3 changed the installation location, choose the most recent one available
-exec_program(/usr/bin/xcode-select ARGS -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR)
+execute_process(COMMAND /usr/bin/xcode-select -print-path OUTPUT_VARIABLE CMAKE_XCODE_DEVELOPER_DIR OUTPUT_STRIP_TRAILING_WHITESPACE)
set (XCODE_POST_43_ROOT "${CMAKE_XCODE_DEVELOPER_DIR}/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer")
if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
@@ -195,17 +212,27 @@ set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS su
# Set the architectures unless specified manually with IOS_ARCH
if (NOT DEFINED IOS_ARCH)
if (IOS_PLATFORM STREQUAL "OS")
- set (IOS_ARCH "armv7;armv7s;arm64")
+ set (IOS_ARCH "arm64")
elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
- set (IOS_ARCH "i386;x86_64;arm64")
+ set (IOS_ARCH "x86_64;arm64")
elseif (IOS_PLATFORM STREQUAL "WATCHOS")
set (IOS_ARCH "armv7k;arm64_32;arm64")
+
+ # Include C++ Standard Library for Xcode 15 builds.
+ include_directories(SYSTEM "${CMAKE_IOS_SDK_ROOT}/usr/include/c++/v1")
elseif (IOS_PLATFORM STREQUAL "WATCHSIMULATOR")
- set (IOS_ARCH "i386;x86_64;arm64")
+ set (IOS_ARCH "x86_64;arm64")
+
+ # Include C++ Standard Library for Xcode 15 builds.
+ include_directories(SYSTEM "${CMAKE_IOS_SDK_ROOT}/usr/include/c++/v1")
elseif (IOS_PLATFORM STREQUAL "TVOS")
set (IOS_ARCH "arm64")
elseif (IOS_PLATFORM STREQUAL "TVSIMULATOR")
set (IOS_ARCH "x86_64;arm64")
+ elseif (IOS_PLATFORM STREQUAL "VISIONOS")
+ set (IOS_ARCH "arm64")
+ elseif (IOS_PLATFORM STREQUAL "VISIONSIMULATOR")
+ set (IOS_ARCH "x86_64;arm64")
endif()
endif()
message (STATUS "The iOS architectures: ${IOS_ARCH}")