2023-01-29 14:10:39 +01:00
|
|
|
cmake_minimum_required(VERSION 3.15)
|
|
|
|
cmake_policy(SET CMP0087 NEW) # evaluates generator expressions in `install(CODE/SCRIPT)`
|
|
|
|
cmake_policy(SET CMP0091 NEW) # select MSVC runtime library through `CMAKE_MSVC_RUNTIME_LIBRARY`
|
2024-10-27 14:10:52 +01:00
|
|
|
if (POLICY CMP0167)
|
|
|
|
cmake_policy(SET CMP0167 NEW) # find Boost's own CMake config file
|
|
|
|
endif ()
|
2021-03-28 16:58:51 +02:00
|
|
|
include(FeatureSummary)
|
2019-05-11 14:13:03 +02:00
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
list(APPEND CMAKE_MODULE_PATH
|
|
|
|
"${CMAKE_SOURCE_DIR}/cmake"
|
2021-04-10 13:26:20 +02:00
|
|
|
"${CMAKE_SOURCE_DIR}/cmake/sanitizers-cmake/cmake"
|
2021-03-28 16:58:51 +02:00
|
|
|
)
|
2019-05-11 14:13:03 +02:00
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
option(BUILD_APP "Build Chatterino" ON)
|
|
|
|
option(BUILD_TESTS "Build the tests for Chatterino" OFF)
|
2021-08-08 14:16:30 +02:00
|
|
|
option(BUILD_BENCHMARKS "Build the benchmarks for Chatterino" OFF)
|
2021-03-28 16:58:51 +02:00
|
|
|
option(USE_SYSTEM_PAJLADA_SETTINGS "Use system pajlada settings library" OFF)
|
|
|
|
option(USE_SYSTEM_LIBCOMMUNI "Use system communi library" OFF)
|
2021-08-08 12:37:37 +02:00
|
|
|
option(USE_SYSTEM_QTKEYCHAIN "Use system QtKeychain library" OFF)
|
2021-10-31 20:45:23 +01:00
|
|
|
option(BUILD_WITH_QTKEYCHAIN "Build Chatterino with support for your system key chain" ON)
|
2023-10-04 15:38:53 +02:00
|
|
|
option(USE_SYSTEM_MINIAUDIO "Build Chatterino with your system miniaudio" OFF)
|
2023-02-12 20:36:58 +01:00
|
|
|
option(BUILD_WITH_CRASHPAD "Build chatterino with crashpad" OFF)
|
2021-05-08 15:57:00 +02:00
|
|
|
option(USE_PRECOMPILED_HEADERS "Use precompiled headers" ON)
|
2024-11-17 12:39:22 +01:00
|
|
|
option(BUILD_WITH_QT6 "Build with Qt6" On)
|
2022-11-05 11:04:35 +01:00
|
|
|
option(CHATTERINO_GENERATE_COVERAGE "Generate coverage files" OFF)
|
2023-01-29 12:12:49 +01:00
|
|
|
# We don't use translations, and we don't want qtkeychain to build translations
|
|
|
|
option(BUILD_TRANSLATIONS "" OFF)
|
2022-12-20 23:09:07 +01:00
|
|
|
option(BUILD_SHARED_LIBS "" OFF)
|
2022-12-24 20:06:52 +01:00
|
|
|
option(CHATTERINO_LTO "Enable LTO for all targets" OFF)
|
2024-05-06 17:03:17 +02:00
|
|
|
option(CHATTERINO_PLUGINS "Enable ALPHA plugin support in Chatterino" OFF)
|
2024-11-12 23:20:40 +01:00
|
|
|
option(CHATTERINO_USE_GDI_FONTENGINE "Use the legacy GDI fontengine instead of the new DirectWrite one on Windows (Qt 6.8.0 and later)" ON)
|
2020-12-26 12:42:39 +01:00
|
|
|
|
2023-10-02 11:43:20 +02:00
|
|
|
option(CHATTERINO_UPDATER "Enable update checks" ON)
|
|
|
|
mark_as_advanced(CHATTERINO_UPDATER)
|
|
|
|
|
2023-10-10 13:41:09 +02:00
|
|
|
if(BUILD_TESTS)
|
|
|
|
list(APPEND VCPKG_MANIFEST_FEATURES "tests")
|
|
|
|
endif()
|
|
|
|
if(BUILD_BENCHMARKS)
|
|
|
|
list(APPEND VCPKG_MANIFEST_FEATURES "benchmarks")
|
|
|
|
endif()
|
|
|
|
|
2023-11-03 18:19:50 +01:00
|
|
|
project(chatterino
|
2024-04-28 11:36:58 +02:00
|
|
|
VERSION 2.5.1
|
2023-11-03 18:19:50 +01:00
|
|
|
DESCRIPTION "Chat client for twitch.tv"
|
|
|
|
HOMEPAGE_URL "https://chatterino.com/"
|
|
|
|
)
|
2023-10-10 13:41:09 +02:00
|
|
|
|
2022-12-24 18:42:59 +01:00
|
|
|
if(CHATTERINO_LTO)
|
|
|
|
include(CheckIPOSupported)
|
|
|
|
check_ipo_supported(RESULT CHATTERINO_ENABLE_LTO OUTPUT IPO_ERROR)
|
2023-10-10 13:41:09 +02:00
|
|
|
message(STATUS "LTO: Enabled (Supported: ${CHATTERINO_ENABLE_LTO} - ${IPO_ERROR})")
|
2022-12-24 18:42:59 +01:00
|
|
|
else()
|
|
|
|
message(STATUS "LTO: Disabled")
|
|
|
|
endif()
|
|
|
|
|
2021-08-08 12:37:37 +02:00
|
|
|
if (BUILD_WITH_QT6)
|
|
|
|
set(MAJOR_QT_VERSION "6")
|
|
|
|
else()
|
|
|
|
set(MAJOR_QT_VERSION "5")
|
|
|
|
endif()
|
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
find_program(CCACHE_PROGRAM ccache)
|
2023-06-11 12:31:04 +02:00
|
|
|
find_program(SCCACHE_PROGRAM sccache)
|
|
|
|
if (SCCACHE_PROGRAM)
|
|
|
|
set(_compiler_launcher ${SCCACHE_PROGRAM})
|
|
|
|
elseif (CCACHE_PROGRAM)
|
|
|
|
set(_compiler_launcher ${CCACHE_PROGRAM})
|
2021-03-28 16:58:51 +02:00
|
|
|
endif ()
|
|
|
|
|
2023-07-01 14:01:47 +02:00
|
|
|
|
|
|
|
# Alternate linker code taken from heavyai/heavydb
|
|
|
|
# https://github.com/heavyai/heavydb/blob/0517d99b467806f6af7b4c969e351368a667497d/CMakeLists.txt#L87-L103
|
|
|
|
macro(set_alternate_linker linker)
|
|
|
|
find_program(LINKER_EXECUTABLE ld.${USE_ALTERNATE_LINKER} ${USE_ALTERNATE_LINKER})
|
|
|
|
if(LINKER_EXECUTABLE)
|
|
|
|
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND "${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 12.0.0)
|
|
|
|
add_link_options("-ld-path=${USE_ALTERNATE_LINKER}")
|
|
|
|
else()
|
|
|
|
add_link_options("-fuse-ld=${USE_ALTERNATE_LINKER}")
|
|
|
|
endif()
|
|
|
|
else()
|
|
|
|
set(USE_ALTERNATE_LINKER "" CACHE STRING "Use alternate linker" FORCE)
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
|
|
|
set(USE_ALTERNATE_LINKER "" CACHE STRING "Use alternate linker. Leave empty for system default; alternatives are 'gold', 'lld', 'bfd', 'mold'")
|
|
|
|
if(NOT "${USE_ALTERNATE_LINKER}" STREQUAL "")
|
|
|
|
set_alternate_linker(${USE_ALTERNATE_LINKER})
|
|
|
|
endif()
|
|
|
|
|
2023-06-11 12:31:04 +02:00
|
|
|
if (_compiler_launcher)
|
|
|
|
set(CMAKE_CXX_COMPILER_LAUNCHER "${_compiler_launcher}" CACHE STRING "CXX compiler launcher")
|
|
|
|
message(STATUS "Using ${_compiler_launcher} for speeding up build")
|
|
|
|
|
|
|
|
if (MSVC)
|
|
|
|
# /Zi can't be used with (s)ccache
|
|
|
|
# Use /Z7 instead (debug info in object files)
|
|
|
|
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
|
|
|
|
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}")
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL "Release")
|
|
|
|
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
|
|
|
|
elseif(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo")
|
|
|
|
string(REPLACE "/Zi" "/Z7" CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO}")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
include(${CMAKE_CURRENT_LIST_DIR}/cmake/GIT.cmake)
|
|
|
|
|
2021-08-08 12:37:37 +02:00
|
|
|
find_package(Qt${MAJOR_QT_VERSION} REQUIRED
|
2021-03-28 16:58:51 +02:00
|
|
|
COMPONENTS
|
|
|
|
Core
|
|
|
|
Widgets
|
|
|
|
Gui
|
|
|
|
Network
|
|
|
|
Svg
|
|
|
|
Concurrent
|
|
|
|
)
|
2021-02-13 19:17:22 +01:00
|
|
|
|
2023-01-08 13:07:06 +01:00
|
|
|
message(STATUS "Qt version: ${Qt${MAJOR_QT_VERSION}_VERSION}")
|
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
if (WIN32)
|
2023-10-13 18:49:12 +02:00
|
|
|
add_subdirectory(lib/WinToast EXCLUDE_FROM_ALL)
|
2021-03-28 16:58:51 +02:00
|
|
|
endif ()
|
2021-02-13 19:17:22 +01:00
|
|
|
|
2023-06-17 17:01:16 +02:00
|
|
|
find_package(Sanitizers QUIET)
|
2021-04-10 13:26:20 +02:00
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
# Find boost on the system
|
2023-09-09 12:23:20 +02:00
|
|
|
find_package(Boost REQUIRED OPTIONAL_COMPONENTS headers)
|
2021-02-13 19:17:22 +01:00
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
# Find OpenSSL on the system
|
|
|
|
find_package(OpenSSL REQUIRED)
|
2021-02-13 19:17:22 +01:00
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
find_package(Threads REQUIRED)
|
2019-05-11 14:13:03 +02:00
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
find_library(LIBRT rt)
|
2019-05-11 14:13:03 +02:00
|
|
|
|
2021-06-13 13:49:59 +02:00
|
|
|
if (USE_SYSTEM_LIBCOMMUNI)
|
|
|
|
find_package(LibCommuni REQUIRED)
|
|
|
|
else()
|
|
|
|
set(LIBCOMMUNI_ROOT_LIB_FOLDER "${CMAKE_SOURCE_DIR}/lib/libcommuni")
|
|
|
|
if (NOT EXISTS "${LIBCOMMUNI_ROOT_LIB_FOLDER}/CMakeLists.txt")
|
|
|
|
message(FATAL_ERROR "Submodules probably not loaded, unable to find lib/libcommuni/CMakeLists.txt")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
add_subdirectory("${LIBCOMMUNI_ROOT_LIB_FOLDER}" EXCLUDE_FROM_ALL)
|
|
|
|
endif()
|
|
|
|
|
2021-10-31 20:45:23 +01:00
|
|
|
if (BUILD_WITH_QTKEYCHAIN)
|
|
|
|
# Link QtKeychain statically
|
|
|
|
if (USE_SYSTEM_QTKEYCHAIN)
|
|
|
|
find_package(Qt${MAJOR_QT_VERSION}Keychain REQUIRED)
|
|
|
|
else()
|
|
|
|
set(QTKEYCHAIN_ROOT_LIB_FOLDER "${CMAKE_SOURCE_DIR}/lib/qtkeychain")
|
|
|
|
if (NOT EXISTS "${QTKEYCHAIN_ROOT_LIB_FOLDER}/CMakeLists.txt")
|
|
|
|
message(FATAL_ERROR "Submodules probably not loaded, unable to find lib/qtkeychain/CMakeLists.txt")
|
|
|
|
endif()
|
|
|
|
|
2024-11-05 22:11:14 +01:00
|
|
|
set(_prev_testing ${BUILD_TESTING})
|
|
|
|
set(BUILD_TESTING Off)
|
2021-10-31 20:45:23 +01:00
|
|
|
add_subdirectory("${QTKEYCHAIN_ROOT_LIB_FOLDER}" EXCLUDE_FROM_ALL)
|
2024-11-05 22:11:14 +01:00
|
|
|
set(BUILD_TESTING ${_prev_testing})
|
|
|
|
|
2021-10-31 20:45:23 +01:00
|
|
|
if (NOT TARGET qt${MAJOR_QT_VERSION}keychain)
|
|
|
|
message(FATAL_ERROR "qt${MAJOR_QT_VERSION}keychain target was not created :@")
|
|
|
|
endif()
|
2024-11-05 22:11:14 +01:00
|
|
|
if (MSVC AND "${MAJOR_QT_VERSION}" STREQUAL "5")
|
|
|
|
target_compile_definitions(qt5keychain PRIVATE UNICODE)
|
|
|
|
target_compile_options(qt5keychain PRIVATE /utf-8)
|
|
|
|
set_target_properties(qt5keychain PROPERTIES CXX_STANDARD 17)
|
|
|
|
endif()
|
2021-03-28 16:58:51 +02:00
|
|
|
endif()
|
2021-06-13 13:49:59 +02:00
|
|
|
endif()
|
2020-12-26 12:42:39 +01:00
|
|
|
|
2021-06-13 13:49:59 +02:00
|
|
|
find_package(RapidJSON REQUIRED)
|
2019-05-11 14:13:03 +02:00
|
|
|
|
2021-06-13 13:49:59 +02:00
|
|
|
find_package(Websocketpp REQUIRED)
|
2019-05-11 14:13:03 +02:00
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
if (BUILD_TESTS)
|
2023-06-24 15:03:27 +02:00
|
|
|
include(GoogleTest)
|
2022-10-01 20:46:59 +02:00
|
|
|
# For MSVC: Prevent overriding the parent project's compiler/linker settings
|
|
|
|
# See https://github.com/google/googletest/blob/main/googletest/README.md#visual-studio-dynamic-vs-static-runtimes
|
|
|
|
set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
|
|
|
|
|
2022-05-22 15:43:41 +02:00
|
|
|
add_subdirectory("${CMAKE_CURRENT_LIST_DIR}/lib/googletest" "lib/googletest")
|
|
|
|
|
|
|
|
mark_as_advanced(
|
2022-10-01 20:46:59 +02:00
|
|
|
BUILD_GMOCK BUILD_GTEST BUILD_SHARED_LIBS
|
|
|
|
gmock_build_tests gtest_build_samples gtest_build_tests
|
|
|
|
gtest_disable_pthreads gtest_force_shared_crt gtest_hide_internal_symbols
|
2022-05-22 15:43:41 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
set_target_properties(gtest PROPERTIES FOLDER lib)
|
|
|
|
set_target_properties(gtest_main PROPERTIES FOLDER lib)
|
|
|
|
set_target_properties(gmock PROPERTIES FOLDER lib)
|
|
|
|
set_target_properties(gmock_main PROPERTIES FOLDER lib)
|
2021-03-28 16:58:51 +02:00
|
|
|
endif ()
|
2020-12-26 12:42:39 +01:00
|
|
|
|
2021-08-08 14:16:30 +02:00
|
|
|
if (BUILD_BENCHMARKS)
|
|
|
|
# Include system benchmark (Google Benchmark)
|
|
|
|
find_package(benchmark REQUIRED)
|
|
|
|
endif ()
|
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
find_package(PajladaSerialize REQUIRED)
|
|
|
|
find_package(PajladaSignals REQUIRED)
|
|
|
|
find_package(LRUCache REQUIRED)
|
2022-05-07 17:22:39 +02:00
|
|
|
find_package(MagicEnum REQUIRED)
|
2024-05-04 12:39:14 +02:00
|
|
|
find_package(Doxygen)
|
2020-12-26 23:40:47 +01:00
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
if (USE_SYSTEM_PAJLADA_SETTINGS)
|
|
|
|
find_package(PajladaSettings REQUIRED)
|
|
|
|
else()
|
|
|
|
if (NOT EXISTS "${CMAKE_SOURCE_DIR}/lib/settings/CMakeLists.txt")
|
|
|
|
message(FATAL_ERROR "Submodules probably not loaded, unable to find lib/settings/CMakeLists.txt")
|
|
|
|
endif()
|
2020-12-26 23:40:47 +01:00
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
add_subdirectory("${CMAKE_SOURCE_DIR}/lib/settings" EXCLUDE_FROM_ALL)
|
|
|
|
endif()
|
2020-08-22 15:37:03 +02:00
|
|
|
|
2023-04-02 15:31:53 +02:00
|
|
|
if (CHATTERINO_PLUGINS)
|
|
|
|
set(LUA_INCLUDE_DIRS "${CMAKE_SOURCE_DIR}/lib/lua/src")
|
|
|
|
add_subdirectory(lib/lua)
|
2024-10-20 11:57:05 +02:00
|
|
|
|
|
|
|
find_package(Sol2 REQUIRED)
|
2023-04-02 15:31:53 +02:00
|
|
|
endif()
|
|
|
|
|
2023-02-12 20:36:58 +01:00
|
|
|
if (BUILD_WITH_CRASHPAD)
|
2023-12-24 15:38:58 +01:00
|
|
|
add_subdirectory("${CMAKE_SOURCE_DIR}/tools/crash-handler")
|
2023-02-12 20:36:58 +01:00
|
|
|
endif()
|
|
|
|
|
2023-06-17 19:43:39 +02:00
|
|
|
# Used to provide a date of build in the About page (for nightly builds). Getting the actual time of
|
|
|
|
# compilation in CMake is a more involved, as documented in https://stackoverflow.com/q/24292898.
|
|
|
|
# For CI runs, however, the date of build file generation should be consistent with the date of
|
|
|
|
# compilation so this approximation is "good enough" for our purpose.
|
|
|
|
if (DEFINED ENV{CHATTERINO_SKIP_DATE_GEN})
|
|
|
|
set(cmake_gen_date "1970-01-01")
|
|
|
|
else ()
|
|
|
|
string(TIMESTAMP cmake_gen_date "%Y-%m-%d")
|
|
|
|
endif ()
|
|
|
|
|
2022-12-24 12:56:11 +01:00
|
|
|
set(CMAKE_CXX_STANDARD 20)
|
2021-03-28 16:58:51 +02:00
|
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
2020-08-22 15:37:03 +02:00
|
|
|
|
2022-11-19 12:29:12 +01:00
|
|
|
# Generate resource files
|
|
|
|
include(cmake/resources/generate_resources.cmake)
|
|
|
|
|
2021-06-13 13:49:59 +02:00
|
|
|
add_subdirectory(src)
|
|
|
|
|
2023-05-20 12:54:50 +02:00
|
|
|
if (BUILD_TESTS OR BUILD_BENCHMARKS)
|
|
|
|
add_subdirectory(mocks)
|
|
|
|
endif ()
|
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
if (BUILD_TESTS)
|
|
|
|
enable_testing()
|
|
|
|
add_subdirectory(tests)
|
|
|
|
endif ()
|
2020-12-20 16:43:35 +01:00
|
|
|
|
2021-08-08 14:16:30 +02:00
|
|
|
if (BUILD_BENCHMARKS)
|
|
|
|
add_subdirectory(benchmarks)
|
|
|
|
endif ()
|
|
|
|
|
2021-03-28 16:58:51 +02:00
|
|
|
feature_summary(WHAT ALL)
|