From ac62bc1469cc9cf725e53d6eabc94a59be3fb36e Mon Sep 17 00:00:00 2001 From: Stanislav Ershov Date: Fri, 26 Oct 2018 04:01:17 +0300 Subject: [PATCH] Improve cmake --- CMakeLists.txt | 39 +++++++----- Telegram/CMakeLists.txt | 67 ++++++++------------ Telegram/ThirdParty/libtgvoip/CMakeLists.txt | 3 - 3 files changed, 52 insertions(+), 57 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a4cbc8614..a41808742 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,13 +1,32 @@ cmake_minimum_required(VERSION 3.10) -project(kepka-desktop) +project(Kepka + LANGUAGES C CXX + VERSION 2.0.0 + DESCRIPTION "Unofficial Telegram Desktop fork" +# HOMEPAGE_URL "https://github.com/procxx/kepka" +) + +set(PROJECT_VERSION_RC 1) + +if(PROJECT_VERSION_RC) + set(PROJECT_VERSION "${PROJECT_VERSION}-rc${PROJECT_VERSION_RC}") +endif() set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/modules/") -include(CTest) if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.10) cmake_policy(SET CMP0071 NEW) endif() +# includes block +include(CTest) +# clang-format +include(modules/clang-cxx-dev-tools.cmake) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED YES) +set(CMAKE_CXX_EXTENSIONS OFF) + if (UNIX AND NOT APPLE) set(LINUX 1) endif() @@ -31,28 +50,20 @@ else() find_package(OpenSSL REQUIRED) endif() -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED YES) -set(CMAKE_CXX_EXTENSIONS OFF) - -set(CMAKE_AUTOMOC ON) -set(CMAKE_INCLUDE_CURRENT_DIR ON) - if (LINUX) find_package(OpenAL REQUIRED) find_package(ALSA) find_package(PulseAudio) find_package(Qt5 COMPONENTS DBus) -else(LINUX) +else() # Needs OpenAL-SOFT # Install via `brew install openal-soft` and configure with cmake call from README.md find_package(OpenAL REQUIRED NO_MODULE) set(OPENAL_LIBRARY OpenAL::OpenAL) -endif(LINUX) +endif() set(THREADS_PREFER_PTHREAD_FLAG ON) find_package(Threads) - find_package(ZLIB REQUIRED) find_package(FFmpeg REQUIRED) find_package(Opus REQUIRED) @@ -74,6 +85,7 @@ endif() option(BUILD_DOC "Build documentation" OFF) +mark_as_advanced(BUILD_DOC) if(BUILD_DOC) find_package(Doxygen) @@ -89,6 +101,3 @@ endif() # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") # set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address -O1 -fno-omit-frame-pointer -g") add_subdirectory(Telegram) - -# clang-format -include(modules/clang-cxx-dev-tools.cmake) diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index c6907080e..00e700d36 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -7,24 +7,16 @@ if (LINUX) endif() endif() -if (PACKAGED_BUILD) - add_definitions(-DTDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME) - add_definitions(-DTDESKTOP_DISABLE_DESKTOP_FILE_GENERATION) -endif() - - #set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -H") - +set(CMAKE_INCLUDE_CURRENT_DIR ON) ##================================================ ## Codegen Tools ##================================================ - include_directories(SourceFiles) add_subdirectory(SourceFiles/codegen) file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/styles) -#-w<(PRODUCT_DIR)/../.. -- wtf is that add_custom_command( COMMENT "Generating palette" OUTPUT @@ -144,7 +136,6 @@ list(APPEND style_files ) foreach (src ${style_files}) -# '-w<(PRODUCT_DIR)/../..', get_filename_component(src_file ${src} NAME) add_custom_command( COMMENT "Generating ${src_file}" @@ -176,21 +167,14 @@ endforeach() ##================================================ ## Branding ##================================================ - set(KEPKA_APPNAME "Kepka" CACHE STRING "Application name") configure_file(SourceFiles/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) -include_directories(${CMAKE_CURRENT_BINARY_DIR}) ##================================================ ## Kepka app ##================================================ - -#add_subdirectory(SourceFiles/boxes) -# ^ Unused: cotire PCH needs more rigid structure with targets defined from the same -# cmakelists file. To do: get rid of the PCH requirement for more flexible build structure. - add_executable(Kepka WIN32 MACOSX_BUNDLE ${CMAKE_CURRENT_BINARY_DIR}/styles/palette.cpp ${CMAKE_CURRENT_BINARY_DIR}/numbers.cpp @@ -543,7 +527,6 @@ list(APPEND tg_RESOURCES qt5_add_resources(tg_RESOURCES_RCC ${tg_RESOURCES}) target_sources(Kepka PRIVATE - ${tg_RESOURCES} ${tg_RESOURCES_RCC} ) @@ -552,7 +535,7 @@ if (APPLE) ThirdParty/SPMediaKeyTap/SPMediaKeyTap.m ThirdParty/SPMediaKeyTap/SPInvocationGrabbing/NSObject+SPInvocationGrabbing.m ) - include_directories(ThirdParty/SPMediaKeyTap) + target_include_directories(Kepka PRIVATE ThirdParty/SPMediaKeyTap) endif() target_sources(Kepka PRIVATE @@ -563,16 +546,12 @@ target_sources(Kepka PRIVATE ThirdParty/emoji_suggestions/emoji_suggestions.cpp ) -include_directories(ThirdParty) # For minizip/ but we use fully-qualified -# include path to avoid ambiguity. - -include_directories(ThirdParty/GSL/include ThirdParty/variant/include - ThirdParty/emoji_suggestions ThirdParty/libtgvoip) - -include_directories(SourceFiles) - -include_directories(${OPENAL_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} - ${OPUS_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS} ${ALSA_INCLUDE_DIRS} ${PULSEAUDIO_INCLUDE_DIR}) +include_directories(ThirdParty/GSL/include + ThirdParty/variant/include + ThirdParty/emoji_suggestions + ThirdParty/libtgvoip + ThirdParty +) add_subdirectory(ThirdParty/libtgvoip) @@ -581,7 +560,7 @@ if(NOT WIN32) endif() if (WIN32) - add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D_USING_V110_SDK71_ + add_definitions(-D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -DWIN32 -D_WINDOWS -D_UNICODE -DUNICODE -DWINAPI_FAMILY=WINAPI_FAMILY_DESKTOP_APP -DHAVE_STDINT_H -DNOMINMAX) @@ -589,9 +568,6 @@ endif() add_definitions(-DAL_LIBTYPE_STATIC) add_definitions(-DAL_ALEXT_PROTOTYPES) -add_definitions(-DTGVOIP_USE_CXX11_LIB) - -add_definitions(-DTDESKTOP_DISABLE_CRASH_REPORTS) if (LINUX) add_definitions(-D_REENTRANT) @@ -640,17 +616,29 @@ if(NOT WIN32) set_flag_if_supported(Kepka WNCE -Wno-c++1z-extensions) endif() -target_compile_definitions(Kepka PRIVATE ${FFMPEG_DEFINITIONS}) +target_compile_definitions(Kepka PRIVATE + TDESKTOP_DISABLE_CRASH_REPORTS + ${FFMPEG_DEFINITIONS}) + +if (PACKAGED_BUILD) + target_compile_definitions(Kepka PRIVATE + TDESKTOP_DISABLE_REGISTER_CUSTOM_SCHEME + TDESKTOP_DISABLE_DESKTOP_FILE_GENERATION) +endif() if(MSVC AND MSVC_VERSION GREATER_EQUAL 1912) target_compile_options(Kepka PRIVATE /permissive-) endif() +target_include_directories(Kepka PRIVATE ${OPENAL_INCLUDE_DIRS} ${ZLIB_INCLUDE_DIRS} ${OPENSSL_INCLUDE_DIR} + ${OPUS_INCLUDE_DIR} ${FFMPEG_INCLUDE_DIRS} ${ALSA_INCLUDE_DIRS} ${PULSEAUDIO_INCLUDE_DIR} ) + target_link_libraries(Kepka Qt5::Core Qt5::Widgets Qt5::Network Qt5::GuiPrivate + Threads::Threads tgvoip ${OPENAL_LIBRARY} ${FFMPEG_LIBRARIES} @@ -709,15 +697,17 @@ if (LINUX) target_link_libraries(Kepka Qt5::DBus dl ${ALSA_LIBRARIES} ${PULSEAUDIO_LIBRARIES}) endif() -target_link_libraries(Kepka Threads::Threads) - ##================================================ ## Installlation ##================================================ include(GNUInstallDirs) -set_target_properties(Kepka PROPERTIES OUTPUT_NAME "kepka") +set_target_properties(Kepka PROPERTIES + OUTPUT_NAME "kepka" + AUTOMOC ON +) + install(TARGETS Kepka RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} BUNDLE DESTINATION ${CMAKE_INSTALL_BINDIR}) @@ -743,8 +733,7 @@ endforeach(icon_size) ## Tests ##================================================ -if (BUILD_TESTING) +if(BUILD_TESTING) include_directories(ThirdParty/Catch/single_include) - add_subdirectory(SourceFiles/base/tests) endif() diff --git a/Telegram/ThirdParty/libtgvoip/CMakeLists.txt b/Telegram/ThirdParty/libtgvoip/CMakeLists.txt index 912b0b33a..171670b4a 100644 --- a/Telegram/ThirdParty/libtgvoip/CMakeLists.txt +++ b/Telegram/ThirdParty/libtgvoip/CMakeLists.txt @@ -116,9 +116,6 @@ if (APPLE) endif() if (LINUX) - find_package(ALSA) - find_package(PulseAudio) - if (ALSA_FOUND) target_sources(tgvoip PRIVATE os/linux/AudioInputALSA.cpp