From 61723bd7948f569e6a0dcc6b0f13eabab8339df9 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 11 Nov 2019 10:56:25 +0300 Subject: [PATCH] Initial Windows Debug build with cmake. --- CMakeLists.txt | 2 +- Telegram/CMakeLists.txt | 79 ++++++++++++++----- Telegram/ThirdParty/libtgvoip | 2 +- Telegram/cmake/lib_ffmpeg.cmake | 10 +++ Telegram/cmake/lib_tgvoip.cmake | 5 ++ Telegram/lib_lottie | 2 +- Telegram/lib_rlottie | 2 +- Telegram/lib_storage | 2 +- Telegram/lib_ui | 2 +- cmake/CMakeLists.txt | 9 ++- cmake/external/CMakeLists.txt | 4 + cmake/external/auto_updates/CMakeLists.txt | 15 ++++ .../external/auto_updates/lzma/CMakeLists.txt | 16 ++++ cmake/external/crash_reports/CMakeLists.txt | 3 +- cmake/external/openal/CMakeLists.txt | 16 ++++ cmake/external/openssl/CMakeLists.txt | 11 +++ cmake/external/opus/CMakeLists.txt | 16 ++++ cmake/external/zlib/CMakeLists.txt | 24 ++++++ cmake/init_target.cmake | 6 ++ cmake/nice_target_sources.cmake | 11 ++- 20 files changed, 201 insertions(+), 36 deletions(-) create mode 100644 cmake/external/auto_updates/CMakeLists.txt create mode 100644 cmake/external/auto_updates/lzma/CMakeLists.txt create mode 100644 cmake/external/openal/CMakeLists.txt create mode 100644 cmake/external/opus/CMakeLists.txt create mode 100644 cmake/external/zlib/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 55281e0e7..d9a0829d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.12) +cmake_minimum_required(VERSION 3.15) cmake_policy(SET CMP0076 NEW) cmake_policy(SET CMP0091 NEW) diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index cab088303..10dd973c5 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -7,6 +7,7 @@ add_subdirectory(lib_base) add_subdirectory(lib_ui) add_subdirectory(lib_tl) add_subdirectory(lib_spellcheck) +add_subdirectory(lib_storage) add_subdirectory(lib_lottie) add_subdirectory(lib_rlottie) add_subdirectory(codegen) @@ -54,17 +55,33 @@ generate_styles(Telegram ${src_loc} "${style_files}" "${dependent_style_files}") generate_lang(Telegram ${res_loc}/langs/lang.strings) generate_numbers(Telegram ${res_loc}/numbers.txt) +set_target_properties(Telegram PROPERTIES AUTOMOC ON) +set_target_properties(Telegram PROPERTIES AUTORCC ON) +set_target_properties(Telegram PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}") + target_link_libraries(Telegram PRIVATE lib_base + lib_crl lib_ui lib_tl lib_spellcheck + lib_storage lib_lottie + lib_rlottie + lib_mtproto lib_scheme lib_export lib_ffmpeg lib_tgvoip + lib_lz4 + external_qt + external_openssl + external_crash_reports + external_auto_updates + external_zlib + external_opus + external_openal ) set(telegram_sources @@ -904,35 +921,55 @@ PRIVATE qt_static_plugins.cpp settings.cpp settings.h - -# platforms: !win -# <(minizip_loc)/crypt.h -# <(minizip_loc)/ioapi.c -# <(minizip_loc)/ioapi.h -# <(minizip_loc)/zip.c -# <(minizip_loc)/zip.h -# <(minizip_loc)/unzip.c -# <(minizip_loc)/unzip.h - -# platforms: win -# <(res_loc)/winrc/Telegram.rc - -# platforms: mac -# <(sp_media_key_tap_loc)/SPMediaKeyTap.m -# <(sp_media_key_tap_loc)/SPMediaKeyTap.h -# <(sp_media_key_tap_loc)/SPInvocationGrabbing/NSObject+SPInvocationGrabbing.m -# <(sp_media_key_tap_loc)/SPInvocationGrabbing/NSObject+SPInvocationGrabbing.h ) nice_target_sources(Telegram ${src_loc} "${telegram_sources}") +set(telegram_resources +PRIVATE + qrc/emoji_1.qrc + qrc/emoji_2.qrc + qrc/emoji_3.qrc + qrc/emoji_4.qrc + qrc/emoji_5.qrc + qrc/emoji_preview.qrc + qrc/telegram/telegram.qrc + qrc/telegram/sounds.qrc + winrc/Telegram.rc + winrc/Telegram.manifest +) +nice_target_sources(Telegram ${res_loc} "${telegram_resources}") + force_include(Telegram stdafx.h) +if (WIN32) + # message(${CMAKE_GENERATOR}) + # mt.exe -manifest "${res_loc}/winrc/Telegram.manifest" "-inputresource:\"$\";#1" "-outputresource:\"$\";#1" >NUL + # set(hash_symbol "#") + # set(release $) + # add_custom_command( + # TARGET + # Telegram + # POST_BUILD COMMAND + # $ $<${release}:-manifest> $<${release}:"${res_loc}/winrc/Telegram.manifest"> $<${release}:-inputresource:"$"$${hash_symbol}1> $<${release}:-outputresource:"$"$${hash_symbol}1> $<${release}:$NUL> + # COMMENT + # $ + # ) +else() + target_link_libraries(Telegram + PRIVATE + external_minizip + ) + if (APPLE) + target_link_libraries(Telegram + PRIVATE + external_sp_media_key_tap + ) + endif() +endif() + target_include_directories(Telegram PRIVATE ${src_loc} - ${libs_loc}/zlib - ${libs_loc}/lzma/C - ${libs_loc}/openal-soft/include ${third_party_loc}/minizip ) diff --git a/Telegram/ThirdParty/libtgvoip b/Telegram/ThirdParty/libtgvoip index 302d42fc2..782436c56 160000 --- a/Telegram/ThirdParty/libtgvoip +++ b/Telegram/ThirdParty/libtgvoip @@ -1 +1 @@ -Subproject commit 302d42fc201f9a8b973ba152e04cf804b0d9d521 +Subproject commit 782436c567ba1a6a7aa294a5a6e09965506d3395 diff --git a/Telegram/cmake/lib_ffmpeg.cmake b/Telegram/cmake/lib_ffmpeg.cmake index 0f38075bb..870a89f44 100644 --- a/Telegram/cmake/lib_ffmpeg.cmake +++ b/Telegram/cmake/lib_ffmpeg.cmake @@ -14,7 +14,17 @@ PUBLIC ${libs_loc}/ffmpeg ) +target_link_directories(lib_ffmpeg +PUBLIC + ${libs_loc}/ffmpeg +) + target_link_libraries(lib_ffmpeg PUBLIC lib_base + ${libs_loc}/ffmpeg/libavformat/libavformat.a + ${libs_loc}/ffmpeg/libavcodec/libavcodec.a + ${libs_loc}/ffmpeg/libavutil/libavutil.a + ${libs_loc}/ffmpeg/libswresample/libswresample.a + ${libs_loc}/ffmpeg/libswscale/libswscale.a ) diff --git a/Telegram/cmake/lib_tgvoip.cmake b/Telegram/cmake/lib_tgvoip.cmake index 037b56423..d5fba61fa 100644 --- a/Telegram/cmake/lib_tgvoip.cmake +++ b/Telegram/cmake/lib_tgvoip.cmake @@ -726,6 +726,11 @@ PRIVATE ${libs_loc}/opus/include ) +target_compile_options(lib_tgvoip +PRIVATE + /wd4244 # conversion from 'int' to 'float', possible loss of data (several in webrtc) +) + target_link_libraries(lib_tgvoip PRIVATE external_openssl diff --git a/Telegram/lib_lottie b/Telegram/lib_lottie index b8127c8aa..3ef08c5ae 160000 --- a/Telegram/lib_lottie +++ b/Telegram/lib_lottie @@ -1 +1 @@ -Subproject commit b8127c8aa2d55a3e110249e63b766db5cbe82f97 +Subproject commit 3ef08c5aec24e544b8fbc6372c9baf56993aa0b0 diff --git a/Telegram/lib_rlottie b/Telegram/lib_rlottie index 3f9823f93..348f27fcc 160000 --- a/Telegram/lib_rlottie +++ b/Telegram/lib_rlottie @@ -1 +1 @@ -Subproject commit 3f9823f939eeb9524d5b15d30993589b8860a168 +Subproject commit 348f27fcc64a82e0a3ae3ec4dbb302e5bd9f5bab diff --git a/Telegram/lib_storage b/Telegram/lib_storage index 6803e7411..3f375807e 160000 --- a/Telegram/lib_storage +++ b/Telegram/lib_storage @@ -1 +1 @@ -Subproject commit 6803e74111186443af5be9ed1eae190536309e33 +Subproject commit 3f375807eacd3411dfe8644df7b0dc494536d3de diff --git a/Telegram/lib_ui b/Telegram/lib_ui index d32f772e5..110a17089 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit d32f772e5274e8490ade20e88c6bfa10b8ecfee5 +Subproject commit 110a17089a2b18e93edf77a0adf596df92e9def0 diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index ec3b9b5e6..d3e9e057e 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -29,8 +29,6 @@ if (WIN32) _WINDOWS _UNICODE UNICODE - # HAVE_STDINT_H - # ZLIB_WINAPI _SCL_SECURE_NO_WARNINGS _USING_V110_SDK71_ NOMINMAX @@ -50,6 +48,10 @@ if (WIN32) /wd5105 # needed for `/experimental:preprocessor`, suppressing C5105 "macro expansion producing 'defined' has undefined behavior" /Zc:wchar_t- # don't tread wchar_t as builtin type ) + target_link_options(common_no_ranges + INTERFACE + /NODEFAULTLIB:LIBCMT + ) target_link_libraries(common_no_ranges INTERFACE winmm @@ -79,7 +81,8 @@ if (WIN32) UxTheme DbgHelp Rstrtmgr - ) + Crypt32 + ) else() endif() diff --git a/cmake/external/CMakeLists.txt b/cmake/external/CMakeLists.txt index 6e7ea170e..e232a576c 100644 --- a/cmake/external/CMakeLists.txt +++ b/cmake/external/CMakeLists.txt @@ -4,3 +4,7 @@ add_subdirectory(variant) add_subdirectory(ranges) add_subdirectory(gsl) add_subdirectory(crash_reports) +add_subdirectory(auto_updates) +add_subdirectory(zlib) +add_subdirectory(opus) +add_subdirectory(openal) diff --git a/cmake/external/auto_updates/CMakeLists.txt b/cmake/external/auto_updates/CMakeLists.txt new file mode 100644 index 000000000..4a2ff4bca --- /dev/null +++ b/cmake/external/auto_updates/CMakeLists.txt @@ -0,0 +1,15 @@ +add_library(external_auto_updates INTERFACE IMPORTED GLOBAL) + +if (WIN32) + add_subdirectory(lzma) + target_link_libraries(external_auto_updates + INTERFACE + external_lzma + ) +else() + add_subdirectory(xz) + target_link_libraries(external_auto_updates + INTERFACE + external_xz + ) +endif() diff --git a/cmake/external/auto_updates/lzma/CMakeLists.txt b/cmake/external/auto_updates/lzma/CMakeLists.txt new file mode 100644 index 000000000..a58fbaab8 --- /dev/null +++ b/cmake/external/auto_updates/lzma/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(external_lzma INTERFACE IMPORTED GLOBAL) + +target_include_directories(external_lzma SYSTEM +INTERFACE + ${libs_loc}/lzma/C +) + +target_link_directories(external_lzma +INTERFACE + ${libs_loc}/lzma/C/Util/LzmaLib/$,Debug,Release> +) + +target_link_libraries(external_lzma +INTERFACE + LzmaLib +) diff --git a/cmake/external/crash_reports/CMakeLists.txt b/cmake/external/crash_reports/CMakeLists.txt index 76485e43c..8633b4a51 100644 --- a/cmake/external/crash_reports/CMakeLists.txt +++ b/cmake/external/crash_reports/CMakeLists.txt @@ -1,8 +1,7 @@ add_library(external_crash_reports INTERFACE IMPORTED GLOBAL) -add_subdirectory(breakpad) - if (WIN32) + add_subdirectory(breakpad) target_link_libraries(external_crash_reports INTERFACE external_breakpad diff --git a/cmake/external/openal/CMakeLists.txt b/cmake/external/openal/CMakeLists.txt new file mode 100644 index 000000000..58f0a5c87 --- /dev/null +++ b/cmake/external/openal/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(external_openal INTERFACE IMPORTED GLOBAL) + +target_include_directories(external_openal SYSTEM +INTERFACE + ${libs_loc}/openal-soft/include +) + +target_link_directories(external_openal +INTERFACE + ${libs_loc}/openal-soft/build/$,Debug,Release> +) + +target_link_libraries(external_openal +INTERFACE + OpenAL32 +) diff --git a/cmake/external/openssl/CMakeLists.txt b/cmake/external/openssl/CMakeLists.txt index 1d476d4e1..8ebdd5901 100644 --- a/cmake/external/openssl/CMakeLists.txt +++ b/cmake/external/openssl/CMakeLists.txt @@ -4,3 +4,14 @@ target_include_directories(external_openssl SYSTEM INTERFACE ${libs_loc}/openssl_1_1_1/include ) + +target_link_directories(external_openssl +INTERFACE + ${libs_loc}/openssl_1_1_1/out32$<$:.dbg> +) + +target_link_libraries(external_openssl +INTERFACE + libcrypto + libssl +) diff --git a/cmake/external/opus/CMakeLists.txt b/cmake/external/opus/CMakeLists.txt new file mode 100644 index 000000000..3aed144fe --- /dev/null +++ b/cmake/external/opus/CMakeLists.txt @@ -0,0 +1,16 @@ +add_library(external_opus INTERFACE IMPORTED GLOBAL) + +target_include_directories(external_opus SYSTEM +INTERFACE + ${libs_loc}/opus/include +) + +target_link_directories(external_opus +INTERFACE + ${libs_loc}/opus/win32/VS2015/Win32/$,Debug,Release> +) + +target_link_libraries(external_opus +INTERFACE + opus +) diff --git a/cmake/external/zlib/CMakeLists.txt b/cmake/external/zlib/CMakeLists.txt new file mode 100644 index 000000000..b29adf098 --- /dev/null +++ b/cmake/external/zlib/CMakeLists.txt @@ -0,0 +1,24 @@ +add_library(external_zlib INTERFACE IMPORTED GLOBAL) + +target_include_directories(external_zlib SYSTEM +INTERFACE + ${libs_loc}/zlib + ${libs_loc}/zlib/contrib/minizip +) + +if (WIN32) + target_compile_definitions(external_zlib + INTERFACE + ZLIB_WINAPI + ) +endif() + +target_link_directories(external_zlib +INTERFACE + ${libs_loc}/zlib/contrib/vstudio/vc14/x86/ZlibStat$,Debug,ReleaseWithoutAsm> +) + +target_link_libraries(external_zlib +INTERFACE + zlibstat +) diff --git a/cmake/init_target.cmake b/cmake/init_target.cmake index 20da15d9d..5753dee6a 100644 --- a/cmake/init_target.cmake +++ b/cmake/init_target.cmake @@ -8,6 +8,12 @@ function(init_target_no_ranges target_name) # init_target(my_target folder_name) init_target_folder(${target_name} "${ARGV1}") set_property(TARGET ${target_name} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") + if (WIN32) + target_compile_options(${target_name} + INTERFACE + /W1 + ) + endif() target_link_libraries(${target_name} PUBLIC common_no_ranges) endfunction() diff --git a/cmake/nice_target_sources.cmake b/cmake/nice_target_sources.cmake index 113ab0c97..85166bc46 100644 --- a/cmake/nice_target_sources.cmake +++ b/cmake/nice_target_sources.cmake @@ -11,16 +11,16 @@ function(nice_target_sources target_name src_loc list) set(writing_now ${file}) else() set(full_name ${src_loc}/${file}) - if (${file} MATCHES "/win/" OR ${file} MATCHES "_win\\." OR ${file} MATCHES "/windows/") + if (${file} MATCHES "(^|/)win/" OR ${file} MATCHES "(^|/)winrc/" OR ${file} MATCHES "(^|/)windows/" OR ${file} MATCHES "[_\\/]win\\.") list(APPEND not_mac_sources ${full_name}) list(APPEND not_linux_sources ${full_name}) - elseif (${file} MATCHES "/mac/" OR ${file} MATCHES "_mac\\." OR ${file} MATCHES "/darwin/") + elseif (${file} MATCHES "(^|/)mac/" OR ${file} MATCHES "(^|/)darwin/" OR ${file} MATCHES "[_\\/]mac\\.") list(APPEND not_win_sources ${full_name}) list(APPEND not_linux_sources ${full_name}) - elseif (${file} MATCHES "/linux/" OR ${file} MATCHES "_linux\\.") + elseif (${file} MATCHES "(^|/)linux/" OR ${file} MATCHES "[_\\/]linux\\.") list(APPEND not_win_sources ${full_name}) list(APPEND not_mac_sources ${full_name}) - elseif (${file} MATCHES "/posix/" OR ${file} MATCHES "_posix\\.") + elseif (${file} MATCHES "(^|/)posix/" OR ${file} MATCHES "[_\\/]posix\\.") list(APPEND not_win_sources ${full_name}) endif() if ("${writing_now}" STREQUAL "PRIVATE") @@ -47,9 +47,12 @@ function(nice_target_sources target_name src_loc list) endif() if (WIN32) set_source_files_properties(${not_win_sources} PROPERTIES HEADER_FILE_ONLY TRUE) + set_source_files_properties(${not_win_sources} PROPERTIES SKIP_AUTOGEN TRUE) elseif (APPLE) set_source_files_properties(${not_mac_sources} PROPERTIES HEADER_FILE_ONLY TRUE) + set_source_files_properties(${not_mac_sources} PROPERTIES SKIP_AUTOGEN TRUE) elseif (LINUX) set_source_files_properties(${not_linux_sources} PROPERTIES HEADER_FILE_ONLY TRUE) + set_source_files_properties(${not_linux_sources} PROPERTIES SKIP_AUTOGEN TRUE) endif() endfunction()