Make tests use main chatterino project objects (#2840)

This commit is contained in:
pajlada 2021-06-13 13:49:59 +02:00 committed by GitHub
parent 5512437f1b
commit 91b0170241
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 145 additions and 204 deletions

View file

@ -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)

@ -1 +1 @@
Subproject commit 6a71d6c395af2134ff56c50a5d056866ac4f3134
Subproject commit 7cf8431d644332107a51a46c1e3de70e64692f0c

View file

@ -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" $<TARGET_FILE:${EXECUTABLE_PROJECT}> --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" $<TARGET_FILE:${PROJECT_NAME}> --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 ()

View file

@ -12,7 +12,6 @@
#include "singletons/Resources.hpp"
#include "singletons/Theme.hpp"
#include "util/FormatTime.hpp"
#include "util/IrcHelpers.hpp"
#include <QDateTime>
#include <QImageReader>

View file

@ -10,6 +10,7 @@
#include <rapidjson/document.h>
#include <QColor>
#include <QElapsedTimer>
#include <QString>
#include <functional>

View file

@ -11,7 +11,6 @@
#include "providers/twitch/TwitchEmotes.hpp"
#include "providers/twitch/api/Helix.hpp"
#include <IrcConnection>
#include <QColor>
#include <QElapsedTimer>
#include <QRegularExpression>

View file

@ -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"