diff --git a/CMakeLists.txt b/CMakeLists.txt index 73a28b181..ef5c2d312 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,39 +58,37 @@ find_package(Threads REQUIRED) find_library(LIBRT rt) -if (BUILD_APP) - 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) +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() - # Link QtKeychain statically - option(QTKEYCHAIN_STATIC "" ON) + add_subdirectory("${LIBCOMMUNI_ROOT_LIB_FOLDER}" EXCLUDE_FROM_ALL) +endif() - if (USE_SYSTEM_QT5KEYCHAIN) - find_package(Qt5Keychain REQUIRED) - else() - set(QT5KEYCHAIN_ROOT_LIB_FOLDER "${CMAKE_SOURCE_DIR}/lib/qtkeychain") - if (NOT EXISTS "${QT5KEYCHAIN_ROOT_LIB_FOLDER}/CMakeLists.txt") - message(FATAL_ERROR "Submodules probably not loaded, unable to find lib/qtkeychain/CMakeLists.txt") - endif() +# Link QtKeychain statically +option(QTKEYCHAIN_STATIC "" ON) - add_subdirectory("${QT5KEYCHAIN_ROOT_LIB_FOLDER}" EXCLUDE_FROM_ALL) - if (NOT TARGET qt5keychain) - message(FATAL_ERROR "qt5keychain target was not created :@") - endif() +if (USE_SYSTEM_QT5KEYCHAIN) + find_package(Qt5Keychain REQUIRED) +else() + set(QT5KEYCHAIN_ROOT_LIB_FOLDER "${CMAKE_SOURCE_DIR}/lib/qtkeychain") + if (NOT EXISTS "${QT5KEYCHAIN_ROOT_LIB_FOLDER}/CMakeLists.txt") + message(FATAL_ERROR "Submodules probably not loaded, unable to find lib/qtkeychain/CMakeLists.txt") endif() - find_package(RapidJSON REQUIRED) + add_subdirectory("${QT5KEYCHAIN_ROOT_LIB_FOLDER}" EXCLUDE_FROM_ALL) + if (NOT TARGET qt5keychain) + message(FATAL_ERROR "qt5keychain target was not created :@") + endif() +endif() - find_package(Websocketpp REQUIRED) -endif () +find_package(RapidJSON REQUIRED) + +find_package(Websocketpp REQUIRED) if (BUILD_TESTS) find_package(GTest REQUIRED) @@ -113,9 +111,12 @@ endif() set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -if (BUILD_APP) - add_subdirectory(src) +if (BUILD_TESTS) + add_definitions(-DCHATTERINO_TEST) endif () + +add_subdirectory(src) + if (BUILD_TESTS) enable_testing() add_subdirectory(tests) diff --git a/lib/settings b/lib/settings index 6a71d6c39..7cf8431d6 160000 --- a/lib/settings +++ b/lib/settings @@ -1 +1 @@ -Subproject commit 6a71d6c395af2134ff56c50a5d056866ac4f3134 +Subproject commit 7cf8431d644332107a51a46c1e3de70e64692f0c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e71eceec3..aa3f8654c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,4 +1,7 @@ -set(SOURCE_FILES main.cpp +set(LIBRARY_PROJECT "${PROJECT_NAME}-lib") +set(EXECUTABLE_PROJECT "${PROJECT_NAME}") + +set(SOURCE_FILES Application.cpp Application.hpp BaseSettings.cpp @@ -471,53 +474,127 @@ endif () # Generate source groups for use in IDEs source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${SOURCE_FILES}) -add_executable(${PROJECT_NAME} ${SOURCE_FILES}) -add_sanitizers(${PROJECT_NAME}) +add_library(${LIBRARY_PROJECT} OBJECT ${SOURCE_FILES}) + +target_link_libraries(${LIBRARY_PROJECT} + PUBLIC + Qt5::Core + Qt5::Widgets + Qt5::Gui + Qt5::Network + Qt5::Multimedia + Qt5::Svg + Qt5::Concurrent + + LibCommuni::LibCommuni + qt5keychain + Pajlada::Serialize + Pajlada::Settings + Pajlada::Signals + websocketpp::websocketpp + Threads::Threads + RapidJSON::RapidJSON + LRUCache + ) + +if (BUILD_APP) + add_executable(${EXECUTABLE_PROJECT} main.cpp) + add_sanitizers(${EXECUTABLE_PROJECT}) + + target_include_directories(${EXECUTABLE_PROJECT} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) + + target_link_libraries(${EXECUTABLE_PROJECT} PUBLIC ${LIBRARY_PROJECT}) + + set_target_properties(${EXECUTABLE_PROJECT} + PROPERTIES + ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" + RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin" + RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin" + RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/bin" + ) + + if (MSVC) + get_target_property(Qt5_Core_Location Qt5::Core LOCATION) + get_filename_component(QT_BIN_DIR ${Qt5_Core_Location} DIRECTORY) + set(WINDEPLOYQT_COMMAND "${QT_BIN_DIR}/windeployqt.exe" $ --release --no-compiler-runtime --no-translations --no-opengl-sw) + + install(TARGETS ${EXECUTABLE_PROJECT} + RUNTIME DESTINATION . + ) + + install(CODE "execute_process(COMMAND ${WINDEPLOYQT_COMMAND} --dir \${CMAKE_INSTALL_PREFIX})") + elseif (APPLE) + install(TARGETS ${EXECUTABLE_PROJECT} + RUNTIME DESTINATION bin + BUNDLE DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static + ) + else () + install(TARGETS ${EXECUTABLE_PROJECT} + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib/static + ) + + install(FILES ${CMAKE_SOURCE_DIR}/resources/com.chatterino.chatterino.desktop + DESTINATION share/applications + ) + + install(FILES ${CMAKE_SOURCE_DIR}/resources/icon.png + RENAME com.chatterino.chatterino.png + DESTINATION share/icons/hicolor/256x256/apps + ) + endif () +endif () if (USE_PRECOMPILED_HEADERS) - target_precompile_headers(${PROJECT_NAME} PRIVATE PrecompiledHeader.hpp) + target_precompile_headers(${LIBRARY_PROJECT} PRIVATE PrecompiledHeader.hpp) endif () # Enable autogeneration of Qts MOC/RCC/UIC -set_target_properties(${PROJECT_NAME} +set_target_properties(${LIBRARY_PROJECT} PROPERTIES AUTOMOC ON AUTORCC ON AUTOUIC ON ) -target_compile_definitions(${PROJECT_NAME} PRIVATE +target_compile_definitions(${LIBRARY_PROJECT} PUBLIC CHATTERINO UNICODE AB_CUSTOM_THEME AB_CUSTOM_SETTINGS IRC_STATIC IRC_NAMESPACE=Communi - ) -if (USE_SYSTEM_QT5KEYCHAIN) - target_compile_definitions(${PROJECT_NAME} PRIVATE - CMAKE_BUILD - ) -endif () -target_compile_definitions(${PROJECT_NAME} PRIVATE + CHATTERINO_GIT_HASH=\"${GIT_HASH}\" CHATTERINO_GIT_RELEASE=\"${GIT_RELEASE}\" CHATTERINO_GIT_COMMIT=\"${GIT_COMMIT}\" ) +if (USE_SYSTEM_QT5KEYCHAIN) + target_compile_definitions(${LIBRARY_PROJECT} PUBLIC + CMAKE_BUILD + ) +endif () if (WIN32) - target_compile_definitions(${PROJECT_NAME} PRIVATE + target_compile_definitions(${LIBRARY_PROJECT} PUBLIC USEWINSDK ) - set_target_properties(${PROJECT_NAME} PROPERTIES WIN32_EXECUTABLE TRUE) + if (BUILD_APP) + set_target_properties(${EXECUTABLE_PROJECT} PROPERTIES WIN32_EXECUTABLE TRUE) + endif () endif () if (MSVC) - target_compile_options(${PROJECT_NAME} PRIVATE /EHsc) + target_compile_options(${LIBRARY_PROJECT} PUBLIC /EHsc) endif () -if (APPLE) - set_target_properties(${PROJECT_NAME} PROPERTIES MACOSX_BUNDLE TRUE) - set_target_properties(${PROJECT_NAME} +if (APPLE AND BUILD_APP) + set_target_properties(${EXECUTABLE_PROJECT} PROPERTIES MACOSX_BUNDLE TRUE) + set_target_properties(${EXECUTABLE_PROJECT} PROPERTIES MACOSX_BUNDLE_BUNDLE_NAME "Chatterino" MACOSX_BUNDLE_GUI_IDENTIFIER "com.chatterino" @@ -529,110 +606,45 @@ if (APPLE) ) endif () -target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) - -target_link_libraries(${PROJECT_NAME} - PRIVATE - Qt5::Core - Qt5::Widgets - Qt5::Gui - Qt5::Network - Qt5::Multimedia - Qt5::Svg - Qt5::Concurrent - ) +target_include_directories(${LIBRARY_PROJECT} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) if (WinToast_FOUND) - target_link_libraries(${PROJECT_NAME} - PRIVATE + target_link_libraries(${LIBRARY_PROJECT} + PUBLIC WinToast) endif () if (USE_CONAN AND TARGET CONAN_PKG::boost) - target_link_libraries(${PROJECT_NAME} - PRIVATE + target_link_libraries(${LIBRARY_PROJECT} + PUBLIC CONAN_PKG::boost ) else () - target_link_libraries(${PROJECT_NAME} - PRIVATE + target_link_libraries(${LIBRARY_PROJECT} + PUBLIC Boost::boost ) endif () if (USE_CONAN AND TARGET CONAN_PKG::openssl) - target_link_libraries(${PROJECT_NAME} - PRIVATE + target_link_libraries(${LIBRARY_PROJECT} + PUBLIC CONAN_PKG::openssl ) else () - target_link_libraries(${PROJECT_NAME} - PRIVATE + target_link_libraries(${LIBRARY_PROJECT} + PUBLIC OpenSSL::SSL OpenSSL::Crypto ) endif () -target_include_directories(${PROJECT_NAME} PRIVATE ${RapidJSON_INCLUDE_DIRS}) -target_link_libraries(${PROJECT_NAME} - PRIVATE - LibCommuni::LibCommuni - qt5keychain - Pajlada::Serialize - Pajlada::Settings - Pajlada::Signals - websocketpp::websocketpp - Threads::Threads - RapidJSON::RapidJSON - LRUCache - ) +target_include_directories(${LIBRARY_PROJECT} PUBLIC ${RapidJSON_INCLUDE_DIRS}) + if (LIBRT) - target_link_libraries(${PROJECT_NAME} - PRIVATE + target_link_libraries(${LIBRARY_PROJECT} + PUBLIC ${LIBRT} ) endif () -set_target_properties(${PROJECT_NAME} - PROPERTIES - ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" - RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" - RUNTIME_OUTPUT_DIRECTORY_RELEASE "${CMAKE_BINARY_DIR}/bin" - RUNTIME_OUTPUT_DIRECTORY_DEBUG "${CMAKE_BINARY_DIR}/bin" - RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO "${CMAKE_BINARY_DIR}/bin" - ) - -if (MSVC) - get_target_property(Qt5_Core_Location Qt5::Core LOCATION) - get_filename_component(QT_BIN_DIR ${Qt5_Core_Location} DIRECTORY) - set(WINDEPLOYQT_COMMAND "${QT_BIN_DIR}/windeployqt.exe" $ --release --no-compiler-runtime --no-translations --no-opengl-sw) - - install(TARGETS ${PROJECT_NAME} - RUNTIME DESTINATION . - ) - - install(CODE "execute_process(COMMAND ${WINDEPLOYQT_COMMAND} --dir \${CMAKE_INSTALL_PREFIX})") -elseif (APPLE) - install(TARGETS ${PROJECT_NAME} - RUNTIME DESTINATION bin - BUNDLE DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib/static - ) -else () - install(TARGETS ${PROJECT_NAME} - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib/static - ) - - install(FILES ${CMAKE_SOURCE_DIR}/resources/com.chatterino.chatterino.desktop - DESTINATION share/applications - ) - - install(FILES ${CMAKE_SOURCE_DIR}/resources/icon.png - RENAME com.chatterino.chatterino.png - DESTINATION share/icons/hicolor/256x256/apps - ) -endif () diff --git a/src/messages/MessageBuilder.cpp b/src/messages/MessageBuilder.cpp index c943ecaf6..58b12f400 100644 --- a/src/messages/MessageBuilder.cpp +++ b/src/messages/MessageBuilder.cpp @@ -12,7 +12,6 @@ #include "singletons/Resources.hpp" #include "singletons/Theme.hpp" #include "util/FormatTime.hpp" -#include "util/IrcHelpers.hpp" #include #include diff --git a/src/providers/twitch/TwitchAccount.hpp b/src/providers/twitch/TwitchAccount.hpp index d45c09881..517aa4cae 100644 --- a/src/providers/twitch/TwitchAccount.hpp +++ b/src/providers/twitch/TwitchAccount.hpp @@ -10,6 +10,7 @@ #include #include +#include #include #include diff --git a/src/providers/twitch/TwitchChannel.hpp b/src/providers/twitch/TwitchChannel.hpp index 3268984ba..af1157992 100644 --- a/src/providers/twitch/TwitchChannel.hpp +++ b/src/providers/twitch/TwitchChannel.hpp @@ -11,7 +11,6 @@ #include "providers/twitch/TwitchEmotes.hpp" #include "providers/twitch/api/Helix.hpp" -#include #include #include #include diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index dad801ed0..8a13c128d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,41 +1,5 @@ project(chatterino-test) -set(main_dir ${CMAKE_SOURCE_DIR}/src) - -include_directories(${main_dir}) - -set(chatterino_SOURCES - ${CMAKE_SOURCE_DIR}/src/BaseSettings.cpp - - ${CMAKE_SOURCE_DIR}/src/common/ChatterinoSetting.cpp - ${CMAKE_SOURCE_DIR}/src/common/Modes.cpp - ${CMAKE_SOURCE_DIR}/src/common/NetworkCommon.cpp - ${CMAKE_SOURCE_DIR}/src/common/NetworkManager.cpp - ${CMAKE_SOURCE_DIR}/src/common/NetworkPrivate.cpp - ${CMAKE_SOURCE_DIR}/src/common/NetworkRequest.cpp - ${CMAKE_SOURCE_DIR}/src/common/NetworkResult.cpp - ${CMAKE_SOURCE_DIR}/src/common/QLogging.cpp - ${CMAKE_SOURCE_DIR}/src/common/ChatterSet.cpp - - ${CMAKE_SOURCE_DIR}/src/debug/Benchmark.cpp - - ${CMAKE_SOURCE_DIR}/src/controllers/highlights/HighlightPhrase.cpp - - ${CMAKE_SOURCE_DIR}/src/messages/Emote.cpp - ${CMAKE_SOURCE_DIR}/src/messages/Image.cpp - ${CMAKE_SOURCE_DIR}/src/messages/ImageSet.cpp - - ${CMAKE_SOURCE_DIR}/src/providers/emoji/Emojis.cpp - - ${CMAKE_SOURCE_DIR}/src/singletons/Paths.cpp - - ${CMAKE_SOURCE_DIR}/src/util/DebugCount.cpp - ${CMAKE_SOURCE_DIR}/src/util/RapidjsonHelpers.cpp - - ${CMAKE_SOURCE_DIR}/resources/resources.qrc - ${CMAKE_SOURCE_DIR}/resources/resources_autogenerated.qrc - ) - set(test_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/main.cpp ${CMAKE_CURRENT_LIST_DIR}/src/AccessGuard.cpp @@ -46,52 +10,17 @@ set(test_SOURCES ${CMAKE_CURRENT_LIST_DIR}/src/Emojis.cpp ) -add_executable(${PROJECT_NAME} - ${chatterino_SOURCES} - ${test_SOURCES} - ) +add_executable(${PROJECT_NAME} ${test_SOURCES}) add_sanitizers(${PROJECT_NAME}) -# Enable autogeneration of Qts MOC/RCC/UIC -set_target_properties(${PROJECT_NAME} - PROPERTIES - AUTOMOC ON - AUTORCC ON - AUTOUIC ON - ) +target_link_libraries(${PROJECT_NAME} PRIVATE chatterino-lib) -target_link_libraries(${PROJECT_NAME} PRIVATE - Qt5::Core - Qt5::Widgets - Qt5::Network - Qt5::Concurrent - gtest gtest_main - Pajlada::Serialize - Pajlada::Settings - Pajlada::Signals - Threads::Threads - LRUCache - ) +target_link_libraries(${PROJECT_NAME} PRIVATE gtest) target_compile_definitions(${PROJECT_NAME} PRIVATE - CHATTERINO CHATTERINO_TEST - UNICODE - AB_CUSTOM_THEME - AB_CUSTOM_SETTINGS - IRC_STATIC - IRC_NAMESPACE=Communi - CHATTERINO_GIT_HASH=\"${GIT_HASH}\" - CHATTERINO_GIT_RELEASE=\"${GIT_RELEASE}\" - CHATTERINO_GIT_COMMIT=\"${GIT_COMMIT}\" ) -if (WIN32) - target_compile_definitions(${PROJECT_NAME} PRIVATE - USEWINSDK - ) -endif () - set_target_properties(${PROJECT_NAME} PROPERTIES ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib"