diff --git a/CMakeLists.txt b/CMakeLists.txt index a9cd092..037b2eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,4 +5,6 @@ # https://github.com/desktop-app/legal/blob/master/LEGAL add_subdirectory(external) -add_subdirectory(linux_glibc_wraps) +if (DESKTOP_APP_USE_GLIBC_WRAPS) + add_subdirectory(linux_glibc_wraps) +endif() diff --git a/external/auto_updates/xz/CMakeLists.txt b/external/auto_updates/xz/CMakeLists.txt index fcf5845..7d24cb2 100644 --- a/external/auto_updates/xz/CMakeLists.txt +++ b/external/auto_updates/xz/CMakeLists.txt @@ -7,7 +7,10 @@ add_library(external_xz INTERFACE IMPORTED GLOBAL) add_library(desktop-app::external_xz ALIAS external_xz) -if (APPLE AND NOT build_osx) +if (DESKTOP_APP_USE_PACKAGED) + find_package(LibLZMA REQUIRED) + target_link_libraries(external_xz LibLZMA::LibLZMA) +elseif (APPLE AND NOT build_osx) target_link_libraries(external_xz INTERFACE /usr/local/macos/lib/liblzma.a diff --git a/external/openssl/CMakeLists.txt b/external/openssl/CMakeLists.txt index 244d435..0f338a6 100644 --- a/external/openssl/CMakeLists.txt +++ b/external/openssl/CMakeLists.txt @@ -47,9 +47,8 @@ INTERFACE ) if (LINUX) - target_link_libraries(external_openssl - INTERFACE - desktop-app::linux_glibc_wraps - pthread - ) + if (DESKTOP_APP_USE_GLIBC_WRAPS) + target_link_libraries(external_openssl INTERFACE desktop-app::linux_glibc_wraps) + endif() + target_link_libraries(external_openssl INTERFACE pthread) endif() diff --git a/external/qt/CMakeLists.txt b/external/qt/CMakeLists.txt index 5697dbd..2e8adc1 100644 --- a/external/qt/CMakeLists.txt +++ b/external/qt/CMakeLists.txt @@ -191,9 +191,11 @@ if (LINUX) icuuc icudata ) + if (DESKTOP_APP_USE_GLIBC_WRAPS) + target_link_libraries(external_qt INTERFACE desktop-app::linux_glibc_wraps) + endif() target_link_libraries(external_qt INTERFACE - desktop-app::linux_glibc_wraps xcb X11 X11-xcb diff --git a/linux_glibc_wraps/CMakeLists.txt b/linux_glibc_wraps/CMakeLists.txt index 30ef632..49a4329 100644 --- a/linux_glibc_wraps/CMakeLists.txt +++ b/linux_glibc_wraps/CMakeLists.txt @@ -4,21 +4,19 @@ # For license and copyright information please follow this link: # https://github.com/desktop-app/legal/blob/master/LEGAL -if (LINUX) - add_library(linux_glibc_wraps STATIC) - add_library(desktop-app::linux_glibc_wraps ALIAS linux_glibc_wraps) +add_library(linux_glibc_wraps STATIC) +add_library(desktop-app::linux_glibc_wraps ALIAS linux_glibc_wraps) - get_filename_component(src_loc . REALPATH) +get_filename_component(src_loc . REALPATH) - nice_target_sources(linux_glibc_wraps ${src_loc} - PRIVATE - platform/linux/linux_glibc_wraps.c - platform/linux/linux_glibc_wraps_32.c - platform/linux/linux_glibc_wraps_64.c - ) - if (NOT build_linux32) - set_source_files_properties(${src_loc}/platform/linux/linux_glibc_wraps_32.c PROPERTIES HEADER_FILE_ONLY TRUE) - else() - set_source_files_properties(${src_loc}/platform/linux/linux_glibc_wraps_64.c PROPERTIES HEADER_FILE_ONLY TRUE) - endif() +nice_target_sources(linux_glibc_wraps ${src_loc} +PRIVATE + platform/linux/linux_glibc_wraps.c + platform/linux/linux_glibc_wraps_32.c + platform/linux/linux_glibc_wraps_64.c +) +if (NOT build_linux32) + set_source_files_properties(${src_loc}/platform/linux/linux_glibc_wraps_32.c PROPERTIES HEADER_FILE_ONLY TRUE) +else() + set_source_files_properties(${src_loc}/platform/linux/linux_glibc_wraps_64.c PROPERTIES HEADER_FILE_ONLY TRUE) endif() diff --git a/run_cmake.py b/run_cmake.py new file mode 100644 index 0000000..b926ce5 --- /dev/null +++ b/run_cmake.py @@ -0,0 +1,54 @@ +''' +This file is part of Telegram Desktop, +the official desktop application for the Telegram messaging service. + +For license and copyright information please follow this link: +https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL +''' +import sys, os, shutil, subprocess + +def run(project, arguments): + scriptPath = os.path.dirname(os.path.realpath(__file__)) + basePath = scriptPath + '/../out' + + cmake = ['cmake'] + for arg in arguments: + if arg == 'debug': + cmake.append('-DCMAKE_BUILD_TYPE=Debug') + elif arg != 'fresh': + cmake.append(arg) + + if sys.platform == 'win32': + cmake.append('-AWin32') + elif sys.platform != 'darwin': + if not '-DCMAKE_BUILD_TYPE=Debug' in cmake: + cmake.append('-DCMAKE_BUILD_TYPE=Release') + + specialTarget = '' + specialTargetFile = scriptPath + '/../' + project + '/build/target' + if os.path.isfile(specialTargetFile): + with open(specialTargetFile, 'r') as f: + for line in f: + target = line.strip() + if len(target) > 0: + cmake.append('-DDESKTOP_APP_SPECIAL_TARGET=' + target) + + cmake.extend(['-Werror=dev', '-Werror=deprecated', '--warn-uninitialized', '..']) + command = ' '.join(cmake) + + if not os.path.exists(basePath): + os.mkdir(basePath) + elif 'fresh' in arguments: + paths = os.listdir(basePath) + for path in paths: + if path.lower().startswith('cmake'): + full = basePath + '/' + path + if os.path.isdir(full): + shutil.rmtree(full, ignore_errors=False) + else: + os.remove(full) + print('Cleared previous.') + os.chdir(basePath) + subprocess.call(command, shell=True) + + return 0 diff --git a/variables.cmake b/variables.cmake index e358d27..b3d7ff4 100644 --- a/variables.cmake +++ b/variables.cmake @@ -8,6 +8,8 @@ set(DESKTOP_APP_SPECIAL_TARGET "" CACHE STRING "Use special platform target, lik option(DESKTOP_APP_DISABLE_CRASH_REPORTS "Disable crash report generation." OFF) option(DESKTOP_APP_DISABLE_SPELLCHECK "Disable spellcheck library." OFF) option(DESKTOP_APP_LOTTIE_USE_CACHE "Use caching in lottie animations." ON) +option(DESKTOP_APP_USE_GLIBC_WRAPS "Use wraps for new GLIBC features." OFF) +option(DESKTOP_APP_USE_PACKAGED "Find libraries using CMake instead of exact paths." ON) function(report_bad_special_target) message(FATAL_ERROR "Bad special target '${DESKTOP_APP_SPECIAL_TARGET}'") @@ -19,6 +21,11 @@ if (DESKTOP_APP_SPECIAL_TARGET STREQUAL "" set(disable_autoupdate 1) endif() +if (NOT DESKTOP_APP_SPECIAL_TARGET STREQUAL "") + set(DESKTOP_APP_USE_GLIBC_WRAPS ON) + set(DESKTOP_APP_USE_PACKAGED OFF) +endif() + if (NOT DESKTOP_APP_SPECIAL_TARGET STREQUAL "osx") set(CMAKE_OSX_DEPLOYMENT_TARGET 10.12 CACHE STRING "Minimum OS X deployment version" FORCE) else() @@ -38,6 +45,7 @@ if (WIN32) AND NOT DESKTOP_APP_SPECIAL_TARGET STREQUAL "win") report_bad_special_target() endif() + set(DESKTOP_APP_USE_GLIBC_WRAPS OFF) elseif (APPLE) if (DESKTOP_APP_SPECIAL_TARGET STREQUAL "osx") set(build_osx 1) @@ -48,6 +56,7 @@ elseif (APPLE) AND NOT DESKTOP_APP_SPECIAL_TARGET STREQUAL "mac") report_bad_special_target() endif() + set(DESKTOP_APP_USE_GLIBC_WRAPS OFF) else() set(LINUX 1) execute_process(COMMAND uname -m OUTPUT_VARIABLE machine_uname)