From b5640fdb0a5156824af11baa483ce07a13b9f703 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 9 Sep 2016 09:15:11 +0300 Subject: [PATCH] GYP build for Linux done: GYP -> CMake -> make. Testing. --- Telegram/Patches/gyp.diff | 32 +++- .../platform/linux/file_dialog_linux.cpp | 6 +- Telegram/SourceFiles/stdafx.cpp | 12 +- Telegram/build/build.sh | 25 +-- Telegram/gyp/PrecompiledHeader.cmake | 157 ++++++++++++++++++ Telegram/gyp/Telegram.gyp | 1 + Telegram/gyp/common.gypi | 7 +- Telegram/gyp/qt.gypi | 110 ++++++++---- Telegram/gyp/qt_rcc.gypi | 40 +++++ Telegram/gyp/refresh.sh | 22 ++- Telegram/gyp/settings_linux.gypi | 79 +++++++++ Telegram/gyp/settings_mac.gypi | 17 +- Telegram/gyp/settings_win.gypi | 5 + Telegram/gyp/telegram_linux.gypi | 56 ++++++- Telegram/gyp/utils.gyp | 7 + 15 files changed, 500 insertions(+), 76 deletions(-) create mode 100644 Telegram/gyp/PrecompiledHeader.cmake create mode 100644 Telegram/gyp/qt_rcc.gypi create mode 100644 Telegram/gyp/settings_linux.gypi diff --git a/Telegram/Patches/gyp.diff b/Telegram/Patches/gyp.diff index fda8468e2e..13ddd9b7d2 100644 --- a/Telegram/Patches/gyp.diff +++ b/Telegram/Patches/gyp.diff @@ -1,5 +1,33 @@ +diff --git a/pylib/gyp/generator/cmake.py b/pylib/gyp/generator/cmake.py +index a2b9629..68d7020 100644 +--- a/pylib/gyp/generator/cmake.py ++++ b/pylib/gyp/generator/cmake.py +@@ -1070,6 +1070,23 @@ def WriteTarget(namer, qualified_target, target_dicts, build_dir, config_to_use, + + output.write(')\n') + ++ # Precompile header ++ precompiled_header = config.get('cmake_precompiled_header', '') ++ if precompiled_header: ++ precompiled_header_script = config.get('cmake_precompiled_header_script', '') ++ if not precompiled_header_script: ++ print ('ERROR: cmake_precompiled_header requires cmake_precompiled_header_script') ++ cmake_precompiled_header = NormjoinPath(path_from_cmakelists_to_gyp, precompiled_header) ++ cmake_precompiled_header_script = NormjoinPathForceCMakeSource(path_from_cmakelists_to_gyp, precompiled_header_script) ++ output.write('include(') ++ output.write(cmake_precompiled_header_script) ++ output.write(')\n') ++ output.write('add_precompiled_header(') ++ output.write(cmake_target_name) ++ output.write(' ') ++ output.write(cmake_precompiled_header) ++ output.write(')\n') ++ + UnsetVariable(output, 'TOOLSET') + UnsetVariable(output, 'TARGET') + diff --git a/pylib/gyp/generator/xcode.py b/pylib/gyp/generator/xcode.py -index 0e3fb93..0679660 100644 +index db99d6a..f8398cc 100644 --- a/pylib/gyp/generator/xcode.py +++ b/pylib/gyp/generator/xcode.py @@ -72,6 +72,10 @@ generator_additional_non_configuration_keys = [ @@ -13,7 +41,7 @@ index 0e3fb93..0679660 100644 'mac_bundle', 'mac_bundle_resources', 'mac_framework_headers', -@@ -761,6 +765,26 @@ def GenerateOutput(target_list, target_dicts, data, params): +@@ -772,6 +776,26 @@ def GenerateOutput(target_list, target_dicts, data, params): xcode_targets[qualified_target] = xct xcode_target_to_target_dict[xct] = spec diff --git a/Telegram/SourceFiles/platform/linux/file_dialog_linux.cpp b/Telegram/SourceFiles/platform/linux/file_dialog_linux.cpp index f47e871c6b..b030becd7e 100644 --- a/Telegram/SourceFiles/platform/linux/file_dialog_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/file_dialog_linux.cpp @@ -155,9 +155,9 @@ void QGtkDialog::show(Qt::WindowFlags flags, Qt::WindowModality modality, QWindo Libs::gtk_widget_realize(gtkWidget); // creates X window - if (parent) { - Platform::internal::XSetTransientForHint(Libs::gtk_widget_get_window(gtkWidget), parent->winId()); - } + if (parent) { + Platform::internal::XSetTransientForHint(Libs::gtk_widget_get_window(gtkWidget), parent->winId()); + } if (modality != Qt::NonModal) { Libs::gdk_window_set_modal_hint(Libs::gtk_widget_get_window(gtkWidget), true); diff --git a/Telegram/SourceFiles/stdafx.cpp b/Telegram/SourceFiles/stdafx.cpp index 680dd0cd34..06bd4afa5c 100644 --- a/Telegram/SourceFiles/stdafx.cpp +++ b/Telegram/SourceFiles/stdafx.cpp @@ -25,15 +25,19 @@ Copyright (c) 2014-2016 John Preston, https://desktop.telegram.org //Q_IMPORT_PLUGIN(QWinRTIntegrationPlugin) //Q_IMPORT_PLUGIN(QWbmpPlugin) #elif defined Q_OS_WIN // Q_OS_WINRT +Q_IMPORT_PLUGIN(QWebpPlugin) Q_IMPORT_PLUGIN(QWindowsIntegrationPlugin) -Q_IMPORT_PLUGIN(QWebpPlugin) #elif defined Q_OS_MAC // Q_OS_WIN -Q_IMPORT_PLUGIN(QGenericEnginePlugin) -Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) Q_IMPORT_PLUGIN(QWebpPlugin) +Q_IMPORT_PLUGIN(QCocoaIntegrationPlugin) +Q_IMPORT_PLUGIN(QGenericEnginePlugin) #elif defined Q_OS_LINUX // Q_OS_LINUX +Q_IMPORT_PLUGIN(QWebpPlugin) +Q_IMPORT_PLUGIN(QXcbIntegrationPlugin) +Q_IMPORT_PLUGIN(QConnmanEnginePlugin) +Q_IMPORT_PLUGIN(QGenericEnginePlugin) +Q_IMPORT_PLUGIN(QNetworkManagerEnginePlugin) Q_IMPORT_PLUGIN(QComposePlatformInputContextPlugin) Q_IMPORT_PLUGIN(QIbusPlatformInputContextPlugin) Q_IMPORT_PLUGIN(QFcitxPlatformInputContextPlugin) -Q_IMPORT_PLUGIN(QWebpPlugin) #endif diff --git a/Telegram/build/build.sh b/Telegram/build/build.sh index 904fd5a8e0..d903c75872 100755 --- a/Telegram/build/build.sh +++ b/Telegram/build/build.sh @@ -3,8 +3,6 @@ FullExecPath=$PWD pushd `dirname $0` > /dev/null FullScriptPath=`pwd` popd > /dev/null -QMakePath="/usr/local/tdesktop/Qt-5.6.0/bin/qmake" -QMakeArgs="INCLUDEPATH+=/usr/local/include INCLUDEPATH+=/usr/local/include/opus" if [ ! -d "$FullScriptPath/../../../TelegramPrivate" ]; then echo "" @@ -54,15 +52,13 @@ if [ "$BuildTarget" == "linux" ]; then echo "Building version $AppVersionStrFull for Linux 64bit.." UpdateFile="tlinuxupd$AppVersion" SetupFile="tsetup.$AppVersionStrFull.tar.xz" - WorkPath="$HomePath/../Linux" - ReleasePath="$WorkPath/Release" + ReleasePath="$HomePath/../out/Release" BinaryName="Telegram" elif [ "$BuildTarget" == "linux32" ]; then echo "Building version $AppVersionStrFull for Linux 32bit.." UpdateFile="tlinux32upd$AppVersion" SetupFile="tsetup32.$AppVersionStrFull.tar.xz" - WorkPath="$HomePath/../Linux" - ReleasePath="$WorkPath/Release" + ReleasePath="$HomePath/../out/Release" BinaryName="Telegram" elif [ "$BuildTarget" == "mac" ]; then echo "Building version $AppVersionStrFull for OS X 10.8+.." @@ -127,20 +123,9 @@ if [ "$BuildTarget" == "linux" ] || [ "$BuildTarget" == "linux32" ]; then Error "Dropbox path not found!" fi - mkdir -p "$WorkPath/ReleaseIntermediateUpdater" - cd "$WorkPath/ReleaseIntermediateUpdater" - "$QMakePath" "$HomePath/Updater.pro" -r -spec linux-g++ - make - echo "Updater build complete!" - - mkdir -p "$WorkPath/ReleaseIntermediate" - cd "$WorkPath/ReleaseIntermediate" - "$QMakePath" $QMakeArgs "$HomePath/Telegram.pro" -r -spec linux-g++ - - eval "$HomePath/build/makefile_static.sh" - ./../codegen/Debug/codegen_style "-I./../../Telegram/Resources" "-I./../../Telegram/SourceFiles" "-o./GeneratedFiles/styles" all_files.style --rebuild - ./../codegen/Debug/codegen_numbers "-o./GeneratedFiles" "./../../Telegram/Resources/numbers.txt" - ./../DebugLang/MetaLang -lang_in ./../../Telegram/Resources/langs/lang.strings -lang_out ./GeneratedFiles/lang_auto + gyp/refresh.sh + + cd $ReleasePath make -j4 echo "$BinaryName build complete!" diff --git a/Telegram/gyp/PrecompiledHeader.cmake b/Telegram/gyp/PrecompiledHeader.cmake new file mode 100644 index 0000000000..691f0ae2b0 --- /dev/null +++ b/Telegram/gyp/PrecompiledHeader.cmake @@ -0,0 +1,157 @@ +## +## Modified for Telegram Desktop project by Telegram Desktop authors. +## +# Function for setting up precompiled headers. Usage: +# +# add_library/executable(target +# pchheader.c pchheader.cpp pchheader.h) +# +# add_precompiled_header(target pchheader.h +# [FORCEINCLUDE] +# [SOURCE_C pchheader.c] +# [SOURCE_CXX pchheader.cpp]) +# +# Options: +# +# FORCEINCLUDE: Add compiler flags to automatically include the +# pchheader.h from every source file. Works with both GCC and +# MSVC. This is recommended. +# +# SOURCE_C/CXX: Specifies the .c/.cpp source file that includes +# pchheader.h for generating the pre-compiled header +# output. Defaults to pchheader.c. Only required for MSVC. +# +# Caveats: +# +# * Its not currently possible to use the same precompiled-header in +# more than a single target in the same directory (No way to set +# the source file properties differently for each target). +# +# * MSVC: A source file with the same name as the header must exist +# and be included in the target (E.g. header.cpp). Name of file +# can be changed using the SOURCE_CXX/SOURCE_C options. +# +# License: +# +# Copyright (C) 2009-2013 Lars Christensen +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation files +# (the 'Software') deal in the Software without restriction, +# including without limitation the rights to use, copy, modify, merge, +# publish, distribute, sublicense, and/or sell copies of the Software, +# and to permit persons to whom the Software is furnished to do so, +# subject to the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS +# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN +# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +include(CMakeParseArguments) + +macro(combine_arguments _variable) + set(_result "") + foreach(_element ${${_variable}}) + set(_result "${_result} \"${_element}\"") + endforeach() + string(STRIP "${_result}" _result) + set(${_variable} "${_result}") +endmacro() + +function(export_all_flags _filename _source_name_for_flags) + set(_include_directories "$") + set(_compile_definitions "$") + get_source_file_property(_compile_flags "${_source_name_for_flags}" COMPILE_FLAGS) + set(_compile_options "$") + set(_include_directories "$<$:-I$\n>") + set(_compile_definitions "$<$:-D$\n>") + set(_compile_flags "$<$:$\n>") + set(_compile_options "$<$:$\n>") + file(GENERATE OUTPUT "${_filename}" CONTENT "${_source_name_for_flags}\n${_compile_definitions}${_include_directories}${_compile_flags}${_compile_options}\n") +endfunction() + +function(add_precompiled_header _target _input) + if(CMAKE_COMPILER_IS_GNUCXX) + get_filename_component(_name ${_input} NAME) + set(_pch_header "${CMAKE_CURRENT_SOURCE_DIR}/${_input}") + set(_pch_binary_dir "${CMAKE_CURRENT_BINARY_DIR}/${_target}_pch") + set(_pchfile "${_pch_binary_dir}/${_name}") + set(_outdir "${_pch_binary_dir}/${_name}.gch") + make_directory(${_outdir}) + set(_output_cxx "${_outdir}/.c++") + set(_output_c "${_outdir}/.c") + + get_property(_sources TARGET ${_target} PROPERTY SOURCES) + foreach(_source ${_sources}) + if(_source MATCHES \\.\(c\)$ AND NOT _source_for_c_flags) + set(_source_for_c_flags "${_source}") + elseif(_source MATCHES \\.\(cc|cxx|cpp\)$ AND NOT _source_for_cpp_flags) + set(_source_for_cpp_flags "${_source}") + endif() + endforeach() + + add_custom_command( + OUTPUT "${_pchfile}" + COMMAND "${CMAKE_COMMAND}" -E copy "${_pch_header}" "${_pchfile}" + DEPENDS "${_pch_header}" + COMMENT "Updating ${_name}") + + if(_source_for_c_flags) + set(_pch_c_flags_file "${_pch_binary_dir}/compile_flags_c.rsp") + export_all_flags("${_pch_c_flags_file}" "${_source_for_c_flags}") + set(_compiler_FLAGS "@${_pch_c_flags_file}") + add_custom_command( + OUTPUT "${_output_c}" + COMMAND "${CMAKE_C_COMPILER}" ${_compiler_FLAGS} -x c-header -o "${_output_c}" -c "${_pchfile}" + DEPENDS "${_pchfile}" "${_pch_c_flags_file}" + COMMENT "Precompiling ${_name} for ${_target} (C)") + endif() + if(_source_for_cpp_flags) + set(_pch_cpp_flags_file "${_pch_binary_dir}/compile_flags_cpp.rsp") + export_all_flags("${_pch_cpp_flags_file}" "${_source_for_cpp_flags}") + set(_compiler_FLAGS "@${_pch_cpp_flags_file}") + add_custom_command( + OUTPUT "${_output_cxx}" + COMMAND "${CMAKE_CXX_COMPILER}" ${_compiler_FLAGS} -x c++-header -o "${_output_cxx}" -c "${_pchfile}" + DEPENDS "${_pchfile}" "${_pch_cpp_flags_file}" + COMMENT "Precompiling ${_name} for ${_target} (C++)") + endif() + + foreach(_source ${_sources}) + set(_pch_compile_flags "") + + if(_source MATCHES \\.\(cc|cxx|cpp|c\)$) + get_source_file_property(_pch_compile_flags "${_source}" COMPILE_FLAGS) + if(NOT _pch_compile_flags) + set(_pch_compile_flags) + endif() + separate_arguments(_pch_compile_flags) + list(APPEND _pch_compile_flags -Winvalid-pch -include "${_pchfile}") + + get_source_file_property(_object_depends "${_source}" OBJECT_DEPENDS) + if(NOT _object_depends) + set(_object_depends) + endif() + list(APPEND _object_depends "${_pchfile}") + if(_source MATCHES \\.\(cc|cxx|cpp\)$) + list(APPEND _object_depends "${_output_cxx}") + else() + list(APPEND _object_depends "${_output_c}") + endif() + + combine_arguments(_pch_compile_flags) + set_source_files_properties(${_source} PROPERTIES + COMPILE_FLAGS "${_pch_compile_flags}" + OBJECT_DEPENDS "${_object_depends}") + endif() + endforeach() + endif(CMAKE_COMPILER_IS_GNUCXX) +endfunction() diff --git a/Telegram/gyp/Telegram.gyp b/Telegram/gyp/Telegram.gyp index 0583d2dbd8..93cbf98c69 100644 --- a/Telegram/gyp/Telegram.gyp +++ b/Telegram/gyp/Telegram.gyp @@ -57,6 +57,7 @@ 'telegram_mac.gypi', 'telegram_linux.gypi', 'qt.gypi', + 'qt_rcc.gypi', 'codegen_rules.gypi', ], diff --git a/Telegram/gyp/common.gypi b/Telegram/gyp/common.gypi index df4b6eb726..a050623b60 100644 --- a/Telegram/gyp/common.gypi +++ b/Telegram/gyp/common.gypi @@ -18,10 +18,11 @@ # Copyright (c) 2014 John Preston, https://desktop.telegram.org { - 'includes': [ + 'includes': [ 'settings_win.gypi', 'settings_mac.gypi', - ], + 'settings_linux.gypi', + ], 'variables': { 'variables': { 'variables': { @@ -58,7 +59,7 @@ 'build_mac%': '<(build_mac)', 'build_linux%': '<(build_linux)', - 'official_build_target%': ' /dev/null FullScriptPath=`pwd` popd > /dev/null +MySystem=`uname -s` cd $FullScriptPath -#gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=ninja -#gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=xcode-ninja -#gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=xcode -# use patched gyp with Xcode project generator -../../../Libraries/gyp/gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=xcode + +if [ "$MySystem" == "Linux" ]; then + ../../../Libraries/gyp/gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=cmake + cd ../../out/Debug + ../../../Libraries/cmake-3.6.2/bin/cmake . + cd ../Release + ../../../Libraries/cmake-3.6.2/bin/cmake . + cd ../../Telegram/gyp +else + #gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=ninja + #gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=xcode-ninja + #gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=xcode + # use patched gyp with Xcode project generator + ../../../Libraries/gyp/gyp --depth=. --generator-output=../.. -Goutput_dir=out Telegram.gyp --format=xcode +fi + cd ../.. cd $FullExecPath diff --git a/Telegram/gyp/settings_linux.gypi b/Telegram/gyp/settings_linux.gypi new file mode 100644 index 0000000000..3356b979c2 --- /dev/null +++ b/Telegram/gyp/settings_linux.gypi @@ -0,0 +1,79 @@ +# This file is part of Telegram Desktop, +# the official desktop version of Telegram messaging app, see https://telegram.org +# +# Telegram Desktop is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# It is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# In addition, as a special exception, the copyright holders give permission +# to link the code of portions of this program with the OpenSSL library. +# +# Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE +# Copyright (c) 2014 John Preston, https://desktop.telegram.org + +{ + 'conditions': [ + [ 'build_linux', { + 'variables': { + 'linux_common_flags': [ + '-pipe', + '-g', + '-Wall', + '-W', + '-fPIC', + '-Wno-unused-result', + '-Wno-unused-variable', + '-Wno-unused-parameter', + '-Wno-unused-function', + '-Wno-switch', + '-Wno-comment', + '-Wno-unused-but-set-variable', + '-Wno-missing-field-initializers', + ], + }, + 'conditions': [ + [ '" createPlatformIntegration -> QXcbIntegrationPlugin::create + #'xkbcommon', + ], + }, 'include_dirs': [ '/usr/local/include', '<(libs_loc)/openssl-xcode/include' @@ -26,11 +35,52 @@ 'library_dirs': [ '/usr/local/lib', '<(libs_loc)/libexif-0.6.20/libexif/.libs', + '<(libs_loc)/breakpad/src/client/linux', ], 'libraries': [ - '-lssl', - '-lcrypto', - '-llzma', + 'breakpad_client', + 'composeplatforminputcontextplugin', + 'ibusplatforminputcontextplugin', + 'fcitxplatforminputcontextplugin', + 'liblzma.a', + 'libopenal.a', + 'libavformat.a', + 'libavcodec.a', + 'libswresample.a', + 'libswscale.a', + 'libavutil.a', + 'libopus.a', + 'libva-x11.a', + 'libva-drm.a', + 'libva.a', + 'libz.a', +# ' /dev/null --libs <@(pkgconfig_libs))', ], + 'cflags_cc': [ + ' /dev/null --cflags appindicator-0.1)', + ' /dev/null --cflags gtk+-2.0)', + ' /dev/null --cflags glib-2.0)', + ' /dev/null --cflags dee-1.0)', + ], + 'configurations': { + 'Release': { + 'cflags': [ + '-Ofast', + '-flto', + '-fno-strict-aliasing', + ], + 'cflags_cc': [ + '-Ofast', + '-flto', + '-fno-strict-aliasing', + ], + 'ldflags': [ + '-Ofast', + '-flto', + ], + }, + }, + 'cmake_precompiled_header': '<(src_loc)/stdafx.h', + 'cmake_precompiled_header_script': 'PrecompiledHeader.cmake', }]], } diff --git a/Telegram/gyp/utils.gyp b/Telegram/gyp/utils.gyp index bd7c7e675d..117c87aa51 100644 --- a/Telegram/gyp/utils.gyp +++ b/Telegram/gyp/utils.gyp @@ -84,6 +84,13 @@ 'LzmaLib', ], }], + [ 'build_linux', { + 'libraries': [ + 'ssl', + 'crypto', + 'lzma', + ], + }], ], 'xcode_settings': { 'OTHER_LDFLAGS': [