summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/CMake
diff options
context:
space:
mode:
Diffstat (limited to 'protocols/Telegram/tdlib/td/CMake')
-rw-r--r--protocols/Telegram/tdlib/td/CMake/AddCXXCompilerFlag.cmake16
-rw-r--r--protocols/Telegram/tdlib/td/CMake/FindReadline.cmake8
-rw-r--r--protocols/Telegram/tdlib/td/CMake/GeneratePkgConfig.cmake92
-rw-r--r--protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake127
-rw-r--r--protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake.in43
-rw-r--r--protocols/Telegram/tdlib/td/CMake/PreventInSourceBuild.cmake14
-rw-r--r--protocols/Telegram/tdlib/td/CMake/TdSetUpCompiler.cmake174
-rw-r--r--protocols/Telegram/tdlib/td/CMake/iOS.cmake69
-rw-r--r--protocols/Telegram/tdlib/td/CMake/illumos.cmake10
9 files changed, 507 insertions, 46 deletions
diff --git a/protocols/Telegram/tdlib/td/CMake/AddCXXCompilerFlag.cmake b/protocols/Telegram/tdlib/td/CMake/AddCXXCompilerFlag.cmake
index b57fa4dd98..6fb615a1f7 100644
--- a/protocols/Telegram/tdlib/td/CMake/AddCXXCompilerFlag.cmake
+++ b/protocols/Telegram/tdlib/td/CMake/AddCXXCompilerFlag.cmake
@@ -12,7 +12,7 @@
# add_cxx_compiler_flag(-no-strict-aliasing RELEASE)
# Requires CMake 2.6+
-if(__add_cxx_compiler_flag)
+if (__add_cxx_compiler_flag)
return()
endif()
set(__add_cxx_compiler_flag INCLUDED)
@@ -29,22 +29,22 @@ endfunction(mangle_compiler_flag)
function(add_cxx_compiler_flag FLAG)
string(REPLACE "-Wno-" "-W" MAIN_FLAG ${FLAG})
- mangle_compiler_flag("${MAIN_FLAG}" MANGLED_FLAG)
+ mangle_compiler_flag("${MAIN_FLAG}" MANGLED_FLAG_NAME)
if (DEFINED CMAKE_REQUIRED_FLAGS)
set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${FLAG}")
else()
set(CMAKE_REQUIRED_FLAGS "${FLAG}")
endif()
- check_cxx_compiler_flag("${MAIN_FLAG}" ${MANGLED_FLAG})
+ check_cxx_compiler_flag("${MAIN_FLAG}" ${MANGLED_FLAG_NAME})
if (DEFINED OLD_CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}")
else()
unset(CMAKE_REQUIRED_FLAGS)
endif()
- if(${MANGLED_FLAG})
+ if (${MANGLED_FLAG_NAME})
set(VARIANT ${ARGV1})
- if(ARGV1)
+ if (ARGV1)
string(TOUPPER "_${VARIANT}" VARIANT)
endif()
set(CMAKE_CXX_FLAGS${VARIANT} "${CMAKE_CXX_FLAGS${VARIANT}} ${FLAG}" PARENT_SCOPE)
@@ -53,12 +53,12 @@ endfunction()
function(add_required_cxx_compiler_flag FLAG)
string(REPLACE "-Wno-" "-W" MAIN_FLAG ${FLAG})
- mangle_compiler_flag("${MAIN_FLAG}" MANGLED_FLAG)
+ mangle_compiler_flag("${MAIN_FLAG}" MANGLED_FLAG_NAME)
set(OLD_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${FLAG}")
- check_cxx_compiler_flag("${MAIN_FLAG}" ${MANGLED_FLAG})
+ check_cxx_compiler_flag("${MAIN_FLAG}" ${MANGLED_FLAG_NAME})
set(CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}")
- if (${MANGLED_FLAG})
+ if (${MANGLED_FLAG_NAME})
set(VARIANT ${ARGV1})
if (ARGV1)
string(TOUPPER "_${VARIANT}" VARIANT)
diff --git a/protocols/Telegram/tdlib/td/CMake/FindReadline.cmake b/protocols/Telegram/tdlib/td/CMake/FindReadline.cmake
index dab24bb19f..94b92ef558 100644
--- a/protocols/Telegram/tdlib/td/CMake/FindReadline.cmake
+++ b/protocols/Telegram/tdlib/td/CMake/FindReadline.cmake
@@ -1,10 +1,10 @@
if (APPLE)
- find_path(READLINE_INCLUDE_DIR readline/readline.h /usr/local/opt/readline/include /opt/local/include /opt/include /usr/local/include /usr/include NO_DEFAULT_PATH)
+ find_path(READLINE_INCLUDE_DIR readline/readline.h /opt/homebrew/opt/readline/include /usr/local/opt/readline/include /opt/local/include /opt/include /usr/local/include /usr/include NO_DEFAULT_PATH)
endif()
find_path(READLINE_INCLUDE_DIR readline/readline.h)
if (APPLE)
- find_library(READLINE_LIBRARY readline /usr/local/opt/readline/lib /opt/local/lib /opt/lib /usr/local/lib /usr/lib NO_DEFAULT_PATH)
+ find_library(READLINE_LIBRARY readline /opt/homebrew/opt/readline/lib /usr/local/opt/readline/lib /opt/local/lib /opt/lib /usr/local/lib /usr/lib NO_DEFAULT_PATH)
endif()
find_library(READLINE_LIBRARY readline)
@@ -13,7 +13,7 @@ if (READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND NOT GNU_READLINE_FOUND)
set(CMAKE_REQUIRED_LIBRARIES "${READLINE_LIBRARY}")
include(CheckCXXSourceCompiles)
unset(GNU_READLINE_FOUND CACHE)
- CHECK_CXX_SOURCE_COMPILES("#include <stdio.h>\n#include <readline/readline.h>\nint main() { rl_replace_line(\"\", 0); }" GNU_READLINE_FOUND)
+ check_cxx_source_compiles("#include <stdio.h>\n#include <readline/readline.h>\nint main() { rl_replace_line(\"\", 0); }" GNU_READLINE_FOUND)
if (NOT GNU_READLINE_FOUND)
unset(READLINE_INCLUDE_DIR CACHE)
unset(READLINE_LIBRARY CACHE)
@@ -21,5 +21,5 @@ if (READLINE_INCLUDE_DIR AND READLINE_LIBRARY AND NOT GNU_READLINE_FOUND)
endif()
include(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY)
+find_package_handle_standard_args(Readline DEFAULT_MSG READLINE_INCLUDE_DIR READLINE_LIBRARY)
mark_as_advanced(READLINE_INCLUDE_DIR READLINE_LIBRARY)
diff --git a/protocols/Telegram/tdlib/td/CMake/GeneratePkgConfig.cmake b/protocols/Telegram/tdlib/td/CMake/GeneratePkgConfig.cmake
new file mode 100644
index 0000000000..afbe06ac60
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/CMake/GeneratePkgConfig.cmake
@@ -0,0 +1,92 @@
+function(get_relative_link OUTPUT PATH)
+ if (PATH MATCHES "^[$]<[$]<CONFIG:DEBUG>:")
+ set(${OUTPUT} "" PARENT_SCOPE)
+ return()
+ endif()
+ string(REGEX REPLACE "^[$]<[$]<NOT:[$]<CONFIG:DEBUG>>:(.*)>$" "\\1" PATH "${PATH}")
+
+ get_filename_component(NAME "${PATH}" NAME_WE)
+ if (IS_ABSOLUTE ${PATH})
+ get_filename_component(DIRECTORY_NAME "${PATH}" DIRECTORY)
+ if (WIN32)
+ set(${OUTPUT} "-l\"${DIRECTORY_NAME}/${NAME}\"" PARENT_SCOPE)
+ else()
+ get_filename_component(FULL_NAME "${PATH}" NAME)
+ set(${OUTPUT} "-L\"${DIRECTORY_NAME}\" -l:${FULL_NAME}" PARENT_SCOPE)
+ endif()
+ return()
+ endif()
+
+ if (NOT WIN32 AND NAME MATCHES "^lib")
+ string(REGEX REPLACE "^lib" "-l" LINK "${NAME}")
+ elseif (NAME MATCHES "^-")
+ set(LINK "${NAME}")
+ else()
+ string(CONCAT LINK "-l" "${NAME}")
+ endif()
+ set(${OUTPUT} "${LINK}" PARENT_SCOPE)
+endfunction()
+
+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)
+ 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}")
+ if (NOT LINK EQUAL "")
+ list(APPEND LIBS "${LINK}")
+ endif()
+ endif()
+ endforeach()
+
+ if (HAS_REQS)
+ set(REQUIRES "")
+ foreach (REQ ${REQS})
+ set(REQUIRES "${REQUIRES} ${REQ}")
+ endforeach()
+ set(REQUIRES "Requires.private:${REQUIRES}\n")
+ endif()
+ if (HAS_LIBS)
+ set(LIBRARIES "")
+ list(REVERSE LIBS)
+ list(REMOVE_DUPLICATES LIBS)
+ foreach (LIB ${LIBS})
+ set(LIBRARIES " ${LIB}${LIBRARIES}")
+ endforeach()
+ set(LIBRARIES "Libs.private:${LIBRARIES}\n")
+ endif()
+
+ if (IS_ABSOLUTE "${CMAKE_INSTALL_INCLUDEDIR}")
+ set(PKGCONFIG_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}")
+ else()
+ set(PKGCONFIG_INCLUDEDIR "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
+ endif()
+
+ if (IS_ABSOLUTE "${CMAKE_INSTALL_LIBDIR}")
+ set(PKGCONFIG_LIBDIR "${CMAKE_INSTALL_LIBDIR}")
+ else()
+ set(PKGCONFIG_LIBDIR "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
+ endif()
+
+ file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig")
+ file(GENERATE OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" CONTENT
+"prefix=${PREFIX}
+
+Name: ${TARGET}
+Description: ${DESCRIPTION}
+Version: ${PROJECT_VERSION}
+
+CFlags: -I\"${PKGCONFIG_INCLUDEDIR}\"
+Libs: -L\"${PKGCONFIG_LIBDIR}\" -l${TARGET}
+${REQUIRES}${LIBRARIES}")
+
+ install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/${TARGET}.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
+endfunction()
diff --git a/protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake b/protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake
new file mode 100644
index 0000000000..b565582098
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake
@@ -0,0 +1,127 @@
+# - Returns a version string from Git
+#
+# These functions force a re-configure on each git commit so that you can
+# trust the values of the variables in your build system.
+#
+# get_git_head_revision(<refspecvar> <hashvar>)
+#
+# Requires CMake 2.6 or newer (uses the 'function' command)
+#
+# Original Author:
+# 2009-2020 Ryan Pavlik <ryan.pavlik@gmail.com> <abiryan@ryand.net>
+# http://academic.cleardefinition.com
+#
+# Copyright 2009-2013, Iowa State University.
+# Copyright 2013-2020, Ryan Pavlik
+# Copyright 2013-2020, Contributors
+# SPDX-License-Identifier: BSL-1.0
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+
+if (__get_git_revision_description)
+ return()
+endif()
+set(__get_git_revision_description YES)
+
+# We must run the following at "include" time, not at function call time,
+# to find the path to this module rather than the path to a calling list file
+get_filename_component(_gitdescmoddir ${CMAKE_CURRENT_LIST_FILE} PATH)
+
+# Function _git_find_closest_git_dir finds the next closest .git directory
+# that is part of any directory in the path defined by _start_dir.
+# The result is returned in the parent scope variable whose name is passed
+# as variable _git_dir_var. If no .git directory can be found, the
+# function returns an empty string via _git_dir_var.
+#
+# Example: Given a path C:/bla/foo/bar and assuming C:/bla/.git exists and
+# neither foo nor bar contain a file/directory .git. This wil return
+# C:/bla/.git
+#
+function(_git_find_closest_git_dir _start_dir _git_dir_var)
+ set(cur_dir "${_start_dir}")
+ set(git_dir "${_start_dir}/.git")
+ while (NOT EXISTS "${git_dir}")
+ # .git dir not found, search parent directories
+ set(git_previous_parent "${cur_dir}")
+ get_filename_component(cur_dir "${cur_dir}" DIRECTORY)
+ if (cur_dir STREQUAL git_previous_parent)
+ # We have reached the root directory, we are not in git
+ set(${_git_dir_var} "" PARENT_SCOPE)
+ return()
+ endif()
+ set(git_dir "${cur_dir}/.git")
+ endwhile()
+ set(${_git_dir_var} "${git_dir}" PARENT_SCOPE)
+endfunction()
+
+function(get_git_head_revision _refspecvar _hashvar)
+ _git_find_closest_git_dir("${CMAKE_CURRENT_SOURCE_DIR}" GIT_DIR)
+
+ if (NOT GIT_DIR STREQUAL "")
+ file(RELATIVE_PATH _relative_to_source_dir "${CMAKE_CURRENT_SOURCE_DIR}" "${GIT_DIR}")
+ if (_relative_to_source_dir MATCHES "^[.][.]")
+ # We've gone above the CMake root dir.
+ set(GIT_DIR "")
+ endif()
+ endif()
+ if (GIT_DIR STREQUAL "")
+ set(${_refspecvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
+ set(${_hashvar} "GITDIR-NOTFOUND" PARENT_SCOPE)
+ return()
+ endif()
+
+ find_package(Git)
+
+ # Check if the current source dir is a git submodule or a worktree.
+ # In both cases .git is a file instead of a directory.
+ #
+ if ((NOT IS_DIRECTORY ${GIT_DIR}) AND Git_FOUND)
+ # The following git command will return a non empty string that
+ # points to the super project working tree if the current
+ # source dir is inside a git submodule.
+ # Otherwise the command will return an empty string.
+ #
+ execute_process(
+ COMMAND "${GIT_EXECUTABLE}" rev-parse --show-superproject-working-tree
+ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
+ OUTPUT_VARIABLE out
+ ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
+ if (NOT out STREQUAL "")
+ # If out is non-empty, GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a submodule
+ file(READ ${GIT_DIR} submodule)
+ string(REGEX REPLACE "gitdir: (.*)$" "\\1" GIT_DIR_RELATIVE ${submodule})
+ string(STRIP ${GIT_DIR_RELATIVE} GIT_DIR_RELATIVE)
+ get_filename_component(SUBMODULE_DIR ${GIT_DIR} PATH)
+ get_filename_component(GIT_DIR ${SUBMODULE_DIR}/${GIT_DIR_RELATIVE} ABSOLUTE)
+ set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
+ else()
+ # GIT_DIR/CMAKE_CURRENT_SOURCE_DIR is in a worktree
+ file(READ ${GIT_DIR} worktree_ref)
+ # The .git directory contains a path to the worktree information directory
+ # inside the parent git repo of the worktree.
+ string(REGEX REPLACE "gitdir: (.*)$" "\\1" git_worktree_dir ${worktree_ref})
+ string(STRIP ${git_worktree_dir} git_worktree_dir)
+ _git_find_closest_git_dir("${git_worktree_dir}" GIT_DIR)
+ set(HEAD_SOURCE_FILE "${git_worktree_dir}/HEAD")
+ endif()
+ else()
+ set(HEAD_SOURCE_FILE "${GIT_DIR}/HEAD")
+ endif()
+ if (NOT EXISTS "${HEAD_SOURCE_FILE}")
+ return()
+ endif()
+
+ set(GIT_DATA "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/git-data")
+ if (NOT EXISTS "${GIT_DATA}")
+ file(MAKE_DIRECTORY "${GIT_DATA}")
+ endif()
+ set(HEAD_FILE "${GIT_DATA}/HEAD")
+ configure_file("${HEAD_SOURCE_FILE}" "${HEAD_FILE}" COPYONLY)
+
+ configure_file("${_gitdescmoddir}/GetGitRevisionDescription.cmake.in" "${GIT_DATA}/grabRef.cmake" @ONLY)
+ include("${GIT_DATA}/grabRef.cmake")
+
+ set(${_refspecvar} "${HEAD_REF}" PARENT_SCOPE)
+ set(${_hashvar} "${HEAD_HASH}" PARENT_SCOPE)
+endfunction()
diff --git a/protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake.in b/protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake.in
new file mode 100644
index 0000000000..bfc1e54c15
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/CMake/GetGitRevisionDescription.cmake.in
@@ -0,0 +1,43 @@
+#
+# Internal file for GetGitRevisionDescription.cmake
+#
+# Requires CMake 2.6 or newer (uses the 'function' command)
+#
+# Original Author:
+# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net>
+# http://academic.cleardefinition.com
+# Iowa State University HCI Graduate Program/VRAC
+#
+# Copyright 2009-2012, Iowa State University
+# Copyright 2011-2015, Contributors
+# Distributed under the Boost Software License, Version 1.0.
+# (See accompanying file LICENSE_1_0.txt or copy at
+# http://www.boost.org/LICENSE_1_0.txt)
+# SPDX-License-Identifier: BSL-1.0
+
+set(HEAD_HASH)
+
+file(READ "@HEAD_FILE@" HEAD_CONTENTS LIMIT 1024)
+
+string(STRIP "${HEAD_CONTENTS}" HEAD_CONTENTS)
+if (HEAD_CONTENTS MATCHES "ref")
+ # named branch
+ string(REPLACE "ref: " "" HEAD_REF "${HEAD_CONTENTS}")
+ if (EXISTS "@GIT_DIR@/${HEAD_REF}")
+ configure_file("@GIT_DIR@/${HEAD_REF}" "@GIT_DATA@/head-ref" COPYONLY)
+ else()
+ configure_file("@GIT_DIR@/packed-refs" "@GIT_DATA@/packed-refs" COPYONLY)
+ file(READ "@GIT_DATA@/packed-refs" PACKED_REFS)
+ if (PACKED_REFS MATCHES "([0-9a-z]*) ${HEAD_REF}")
+ set(HEAD_HASH "${CMAKE_MATCH_1}")
+ endif()
+ endif()
+else()
+ # detached HEAD
+ configure_file("@GIT_DIR@/HEAD" "@GIT_DATA@/head-ref" COPYONLY)
+endif()
+
+if (NOT HEAD_HASH)
+ file(READ "@GIT_DATA@/head-ref" HEAD_HASH LIMIT 1024)
+ string(STRIP "${HEAD_HASH}" HEAD_HASH)
+endif()
diff --git a/protocols/Telegram/tdlib/td/CMake/PreventInSourceBuild.cmake b/protocols/Telegram/tdlib/td/CMake/PreventInSourceBuild.cmake
new file mode 100644
index 0000000000..1815e82a25
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/CMake/PreventInSourceBuild.cmake
@@ -0,0 +1,14 @@
+function(prevent_in_source_build)
+ get_filename_component(REAL_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" REALPATH)
+ get_filename_component(REAL_BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}" REALPATH)
+
+ if (REAL_BINARY_DIR STREQUAL REAL_SOURCE_DIR)
+ message(" Out-of-source build must be used. Remove the files already")
+ message(" created by CMake and rerun CMake from a new directory:")
+ message(" rm -rf CMakeFiles CMakeCache.txt")
+ message(" mkdir build")
+ message(" cd build")
+ message(" cmake ..")
+ message(FATAL_ERROR "In-source build failed.")
+ endif()
+endfunction()
diff --git a/protocols/Telegram/tdlib/td/CMake/TdSetUpCompiler.cmake b/protocols/Telegram/tdlib/td/CMake/TdSetUpCompiler.cmake
new file mode 100644
index 0000000000..536c5efb29
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/CMake/TdSetUpCompiler.cmake
@@ -0,0 +1,174 @@
+# - Configures C++14 compiler, setting TDLib-specific compilation options.
+
+function(td_set_up_compiler)
+ set(CMAKE_EXPORT_COMPILE_COMMANDS 1 PARENT_SCOPE)
+
+ set(CMAKE_POSITION_INDEPENDENT_CODE ON PARENT_SCOPE)
+
+ include(illumos)
+
+ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
+ set(GCC 1)
+ set(GCC 1 PARENT_SCOPE)
+ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
+ set(CLANG 1)
+ set(CLANG 1 PARENT_SCOPE)
+ elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Intel")
+ set(INTEL 1)
+ set(INTEL 1 PARENT_SCOPE)
+ elseif (NOT MSVC)
+ message(FATAL_ERROR "Compiler isn't supported")
+ endif()
+
+ include(CheckCXXCompilerFlag)
+
+ if (GCC OR CLANG OR INTEL)
+ if (WIN32 AND INTEL)
+ set(STD14_FLAG /Qstd=c++14)
+ else()
+ set(STD14_FLAG -std=c++14)
+ endif()
+ check_cxx_compiler_flag(${STD14_FLAG} HAVE_STD14)
+ if (NOT HAVE_STD14)
+ string(REPLACE "c++14" "c++1y" STD14_FLAG "${STD14_FLAG}")
+ check_cxx_compiler_flag(${STD14_FLAG} HAVE_STD1Y)
+ set(HAVE_STD14 ${HAVE_STD1Y})
+ endif()
+ elseif (MSVC)
+ set(HAVE_STD14 MSVC_VERSION>=1900)
+ endif()
+
+ if (NOT HAVE_STD14)
+ message(FATAL_ERROR "No C++14 support in the compiler. Please upgrade the compiler.")
+ endif()
+
+ if (MSVC)
+ if (CMAKE_CXX_FLAGS_DEBUG MATCHES "/RTC1")
+ string(REPLACE "/RTC1" " " CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
+ endif()
+ add_definitions(-D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8 /GR- /W4 /wd4100 /wd4127 /wd4324 /wd4505 /wd4814 /wd4702 /bigobj")
+ elseif (CLANG OR GCC)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STD14_FLAG} -fno-omit-frame-pointer -fno-exceptions -fno-rtti")
+ if (APPLE)
+ set(TD_LINKER_FLAGS "-Wl,-dead_strip")
+ if (NOT CMAKE_BUILD_TYPE MATCHES "Deb")
+ set(TD_LINKER_FLAGS "${TD_LINKER_FLAGS},-x,-S")
+ endif()
+ else()
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffunction-sections -fdata-sections")
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffunction-sections -fdata-sections")
+ if (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+ set(TD_LINKER_FLAGS "-Wl,-z,ignore")
+ elseif (EMSCRIPTEN)
+ set(TD_LINKER_FLAGS "-Wl,--gc-sections")
+ else()
+ set(TD_LINKER_FLAGS "-Wl,--gc-sections -Wl,--exclude-libs,ALL")
+ endif()
+ endif()
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${TD_LINKER_FLAGS}")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${TD_LINKER_FLAGS}")
+
+ if (WIN32 OR CYGWIN)
+ if (GCC)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")
+ endif()
+ endif()
+ elseif (INTEL)
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${STD14_FLAG}")
+ endif()
+
+ if (WIN32)
+ add_definitions(-DNTDDI_VERSION=0x06020000 -DWINVER=0x0602 -D_WIN32_WINNT=0x0602 -DPSAPI_VERSION=1 -DNOMINMAX -DUNICODE -D_UNICODE -DWIN32_LEAN_AND_MEAN)
+ endif()
+ if (CYGWIN)
+ add_definitions(-D_DEFAULT_SOURCE=1 -DFD_SETSIZE=4096)
+ endif()
+
+ # _FILE_OFFSET_BITS is broken in Android NDK r15, r15b and r17 and doesn't work prior to Android 7.0
+ add_definitions(-D_FILE_OFFSET_BITS=64)
+
+ # _GNU_SOURCE might not be defined by g++
+ add_definitions(-D_GNU_SOURCE)
+
+ if (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lsocket -lnsl")
+ if (ILLUMOS)
+ add_definitions(-DTD_ILLUMOS=1)
+ endif()
+ endif()
+
+ include(AddCXXCompilerFlag)
+ if (NOT MSVC)
+ add_cxx_compiler_flag("-Wall")
+ add_cxx_compiler_flag("-Wextra")
+ add_cxx_compiler_flag("-Wimplicit-fallthrough=2")
+ add_cxx_compiler_flag("-Wpointer-arith")
+ add_cxx_compiler_flag("-Wcast-qual")
+ add_cxx_compiler_flag("-Wsign-compare")
+ add_cxx_compiler_flag("-Wduplicated-branches")
+ add_cxx_compiler_flag("-Wduplicated-cond")
+ add_cxx_compiler_flag("-Walloc-zero")
+ add_cxx_compiler_flag("-Wlogical-op")
+ add_cxx_compiler_flag("-Wno-tautological-compare")
+ add_cxx_compiler_flag("-Wpointer-arith")
+ add_cxx_compiler_flag("-Wvla")
+ add_cxx_compiler_flag("-Wnon-virtual-dtor")
+ add_cxx_compiler_flag("-Wno-unused-parameter")
+ add_cxx_compiler_flag("-Wconversion")
+ add_cxx_compiler_flag("-Wno-sign-conversion")
+ add_cxx_compiler_flag("-Wc++14-compat-pedantic")
+ add_cxx_compiler_flag("-Wdeprecated")
+ add_cxx_compiler_flag("-Wno-unused-command-line-argument")
+ add_cxx_compiler_flag("-Qunused-arguments")
+ add_cxx_compiler_flag("-Wodr")
+ add_cxx_compiler_flag("-flto-odr-type-merging")
+
+ # add_cxx_compiler_flag("-Werror")
+
+ # add_cxx_compiler_flag("-Wcast-align")
+
+ #std::int32_t <-> int and off_t <-> std::size_t/std::int64_t
+ # add_cxx_compiler_flag("-Wuseless-cast")
+
+ #external headers like openssl
+ # add_cxx_compiler_flag("-Wzero-as-null-pointer-constant")
+ endif()
+
+ if (GCC AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0))
+ 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))
+ # warns about casts of function pointers returned by GetProcAddress
+ add_cxx_compiler_flag("-Wno-cast-function-type")
+ endif()
+ if (GCC AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0))
+ # warns about a lot of "return std::move", which are not redundant for compilers without fix for DR 1579, i.e. GCC 4.9 or clang 3.8
+ # see http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#1579
+ add_cxx_compiler_flag("-Wno-redundant-move")
+ endif()
+ if (GCC AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 12.0))
+ add_cxx_compiler_flag("-Wno-stringop-overflow") # some false positives
+ endif()
+ if (CLANG AND (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 3.5))
+ # https://stackoverflow.com/questions/26744556/warning-returning-a-captured-reference-from-a-lambda
+ add_cxx_compiler_flag("-Wno-return-stack-address")
+ endif()
+
+ if (MINGW)
+ add_cxx_compiler_flag("-ftrack-macro-expansion=0")
+ endif()
+
+ #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -isystem /usr/include/c++/v1")
+ #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++")
+ #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=thread")
+ #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address")
+ #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
+ #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=leak")
+
+ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}" PARENT_SCOPE)
+ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}" PARENT_SCOPE)
+ set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS}" PARENT_SCOPE)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS}" PARENT_SCOPE)
+ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}" PARENT_SCOPE)
+endfunction()
diff --git a/protocols/Telegram/tdlib/td/CMake/iOS.cmake b/protocols/Telegram/tdlib/td/CMake/iOS.cmake
index 9b395a0764..9351395422 100644
--- a/protocols/Telegram/tdlib/td/CMake/iOS.cmake
+++ b/protocols/Telegram/tdlib/td/CMake/iOS.cmake
@@ -9,12 +9,16 @@
# OS - the default, used to build for iPhone and iPad physical devices, which have an arm arch.
# SIMULATOR - used to build for the Simulator platforms, which have an x86 arch.
#
+# IOS_ARCH = automatic(default) or "arch1;arch2" (e.q. "x86_64;arm64")
+# By default this value will be automatically chosen based on the IOS_PLATFORM value above.
+# If set manually, it will override the default and force to build those architectures only.
+#
# CMAKE_IOS_DEVELOPER_ROOT = automatic(default) or /path/to/platform/Developer folder
-# By default this location is automatcially chosen based on the IOS_PLATFORM value above.
+# By default this location is automatically chosen based on the IOS_PLATFORM value above.
# If set manually, it will override the default location and force the user of a particular Developer Platform
#
# CMAKE_IOS_SDK_ROOT = automatic(default) or /path/to/platform/Developer/SDKs/SDK folder
-# By default this location is automatcially chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
+# By default this location is automatically chosen based on the CMAKE_IOS_DEVELOPER_ROOT value.
# In this case it will always be the most up-to-date SDK found in the CMAKE_IOS_DEVELOPER_ROOT path.
# If set manually, this will force the use of a specific SDK version
@@ -48,9 +52,9 @@ endif (CMAKE_UNAME)
# Force the compilers to gcc for iOS
set (CMAKE_C_COMPILER /usr/bin/gcc)
set (CMAKE_CXX_COMPILER /usr/bin/g++)
-set(CMAKE_AR ar CACHE FILEPATH "" FORCE)
-set(CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE)
-set(PKG_CONFIG_EXECUTABLE pkg-config CACHE FILEPATH "" FORCE)
+set (CMAKE_AR ar CACHE FILEPATH "" FORCE)
+set (CMAKE_RANLIB ranlib CACHE FILEPATH "" FORCE)
+set (PKG_CONFIG_EXECUTABLE pkg-config CACHE FILEPATH "" FORCE)
# Setup iOS platform unless specified manually with IOS_PLATFORM
if (NOT DEFINED IOS_PLATFORM)
@@ -59,7 +63,7 @@ endif (NOT DEFINED IOS_PLATFORM)
set (IOS_PLATFORM ${IOS_PLATFORM} CACHE STRING "Type of iOS Platform")
# Check the platform selection and setup for developer root
-if (${IOS_PLATFORM} STREQUAL "OS")
+if (IOS_PLATFORM STREQUAL "OS")
set (IOS_PLATFORM_LOCATION "iPhoneOS.platform")
set (XCODE_IOS_PLATFORM iphoneos)
@@ -67,7 +71,7 @@ if (${IOS_PLATFORM} STREQUAL "OS")
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphoneos")
set (APPLE_IOS True)
-elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
+elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
set (SIMULATOR_FLAG true)
set (IOS_PLATFORM_LOCATION "iPhoneSimulator.platform")
set (XCODE_IOS_PLATFORM iphonesimulator)
@@ -76,7 +80,7 @@ elseif (${IOS_PLATFORM} STREQUAL "SIMULATOR")
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-iphonesimulator")
set (APPLE_IOS True)
-elseif (${IOS_PLATFORM} STREQUAL "WATCHOS")
+elseif (IOS_PLATFORM STREQUAL "WATCHOS")
set (IOS_PLATFORM_LOCATION "WatchOS.platform")
set (XCODE_IOS_PLATFORM watchos)
@@ -84,7 +88,7 @@ elseif (${IOS_PLATFORM} STREQUAL "WATCHOS")
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-watchos")
set (APPLE_WATCH True)
-elseif (${IOS_PLATFORM} STREQUAL "WATCHSIMULATOR")
+elseif (IOS_PLATFORM STREQUAL "WATCHSIMULATOR")
set (SIMULATOR_FLAG true)
set (IOS_PLATFORM_LOCATION "WatchSimulator.platform")
set (XCODE_IOS_PLATFORM watchsimulator)
@@ -93,7 +97,7 @@ elseif (${IOS_PLATFORM} STREQUAL "WATCHSIMULATOR")
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-watchsimulator")
set (APPLE_WATCH True)
-elseif (${IOS_PLATFORM} STREQUAL "TVOS")
+elseif (IOS_PLATFORM STREQUAL "TVOS")
set (IOS_PLATFORM_LOCATION "AppleTvOS.platform")
set (XCODE_IOS_PLATFORM tvos)
@@ -101,7 +105,7 @@ elseif (${IOS_PLATFORM} STREQUAL "TVOS")
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-appletvos")
set (APPLE_TV True)
-elseif (${IOS_PLATFORM} STREQUAL "TVSIMULATOR")
+elseif (IOS_PLATFORM STREQUAL "TVSIMULATOR")
set (SIMULATOR_FLAG true)
set (IOS_PLATFORM_LOCATION "AppleTvSimulator.platform")
set (XCODE_IOS_PLATFORM tvsimulator)
@@ -110,7 +114,7 @@ elseif (${IOS_PLATFORM} STREQUAL "TVSIMULATOR")
set (CMAKE_XCODE_EFFECTIVE_PLATFORMS "-tvsimulator")
set (APPLE_TV True)
-else (${IOS_PLATFORM} STREQUAL "OS")
+else (IOS_PLATFORM STREQUAL "OS")
message (FATAL_ERROR "Unsupported IOS_PLATFORM value selected. Please choose OS, SIMULATOR, or WATCHOS.")
endif ()
@@ -132,12 +136,9 @@ if (IOS_DEPLOYMENT_TARGET)
endif()
set (CMAKE_SHARED_LINKER_FLAGS_INIT "-fapplication-extension")
-if (NOT SIMULATOR_FLAG)
- set (BITCODE "-fembed-bitcode")
-endif()
-set (CMAKE_C_FLAGS_INIT "${XCODE_IOS_PLATFORM_VERSION_FLAGS} ${BITCODE}")
+set (CMAKE_C_FLAGS_INIT "${XCODE_IOS_PLATFORM_VERSION_FLAGS}")
# Hidden visibilty is required for cxx on iOS
-set (CMAKE_CXX_FLAGS_INIT "${XCODE_IOS_PLATFORM_VERSION_FLAGS} ${BITCODE} -fvisibility-inlines-hidden")
+set (CMAKE_CXX_FLAGS_INIT "${XCODE_IOS_PLATFORM_VERSION_FLAGS} -fvisibility-inlines-hidden")
set (CMAKE_C_LINK_FLAGS "${XCODE_IOS_PLATFORM_VERSION_FLAGS} -fapplication-extension -Wl,-search_paths_first ${CMAKE_C_LINK_FLAGS}")
set (CMAKE_CXX_LINK_FLAGS "${XCODE_IOS_PLATFORM_VERSION_FLAGS} -fapplication-extension -Wl,-search_paths_first ${CMAKE_CXX_LINK_FLAGS}")
@@ -168,7 +169,7 @@ set (XCODE_PRE_43_ROOT "/Developer/Platforms/${IOS_PLATFORM_LOCATION}/Developer"
if (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
if (EXISTS ${XCODE_POST_43_ROOT})
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_POST_43_ROOT})
- elseif(EXISTS ${XCODE_PRE_43_ROOT})
+ elseif (EXISTS ${XCODE_PRE_43_ROOT})
set (CMAKE_IOS_DEVELOPER_ROOT ${XCODE_PRE_43_ROOT})
endif (EXISTS ${XCODE_POST_43_ROOT})
endif (NOT DEFINED CMAKE_IOS_DEVELOPER_ROOT)
@@ -191,23 +192,23 @@ set (CMAKE_IOS_SDK_ROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Location of the select
# Set the sysroot default to the most recent SDK
set (CMAKE_OSX_SYSROOT ${CMAKE_IOS_SDK_ROOT} CACHE PATH "Sysroot used for iOS support")
-# set the architecture for iOS
-if (IOS_PLATFORM STREQUAL "OS")
- set (IOS_ARCH "armv7;armv7s;arm64")
-elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
- set (IOS_ARCH "i386;x86_64")
-elseif (IOS_PLATFORM STREQUAL "WATCHOS")
- set (IOS_ARCH "armv7k")
-elseif (IOS_PLATFORM STREQUAL "WATCHSIMULATOR")
- set (IOS_ARCH "i386")
-elseif (IOS_PLATFORM STREQUAL "TVOS")
- set (IOS_ARCH "arm64")
-elseif (IOS_PLATFORM STREQUAL "TVSIMULATOR")
- set (IOS_ARCH "x86_64")
-else()
- message (WARNING "Unknown IOS_PLATFORM=<${IOS_PLATFORM}>")
+# 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")
+ elseif (IOS_PLATFORM STREQUAL "SIMULATOR")
+ set (IOS_ARCH "i386;x86_64;arm64")
+ elseif (IOS_PLATFORM STREQUAL "WATCHOS")
+ set (IOS_ARCH "armv7k;arm64_32")
+ elseif (IOS_PLATFORM STREQUAL "WATCHSIMULATOR")
+ set (IOS_ARCH "i386;x86_64;arm64")
+ elseif (IOS_PLATFORM STREQUAL "TVOS")
+ set (IOS_ARCH "arm64")
+ elseif (IOS_PLATFORM STREQUAL "TVSIMULATOR")
+ set (IOS_ARCH "x86_64;arm64")
+ endif()
endif()
-message (STATUS ${IOS_ARCH})
+message (STATUS "The iOS architectures: ${IOS_ARCH}")
set (CMAKE_OSX_ARCHITECTURES ${IOS_ARCH} CACHE STRING "Build architecture for iOS")
diff --git a/protocols/Telegram/tdlib/td/CMake/illumos.cmake b/protocols/Telegram/tdlib/td/CMake/illumos.cmake
new file mode 100644
index 0000000000..70583d1a82
--- /dev/null
+++ b/protocols/Telegram/tdlib/td/CMake/illumos.cmake
@@ -0,0 +1,10 @@
+if (CMAKE_SYSTEM_NAME STREQUAL "SunOS")
+ #
+ # Determine if the host is running an illumos distribution:
+ #
+ execute_process(COMMAND /usr/bin/uname -o OUTPUT_VARIABLE UNAME_O OUTPUT_STRIP_TRAILING_WHITESPACE)
+
+ if (UNAME_O STREQUAL "illumos")
+ set(ILLUMOS 1)
+ endif()
+endif()