diff --git a/Brewfile b/Brewfile index 0c7834c1b..bcc125280 100644 --- a/Brewfile +++ b/Brewfile @@ -2,3 +2,4 @@ brew 'make' brew 'cmake' brew 'openssl' brew 'ninja' +brew 'googletest' diff --git a/cmake/Libraries.cmake b/cmake/Libraries.cmake index f4af3f78d..c3955ec92 100644 --- a/cmake/Libraries.cmake +++ b/cmake/Libraries.cmake @@ -12,9 +12,12 @@ macro(configure_libs) config_qt() configure_openssl() - configure_gtest() configure_coverage() + if(BUILD_TESTS) + configure_gtest() + endif() + endmacro() # @@ -398,9 +401,26 @@ macro(configure_gtest) option(SYSTEM_GTEST "Use system GoogleTest" ${DEFAULT_SYSTEM_GTEST}) if(SYSTEM_GTEST) message(STATUS "Using system GoogleTest") - find_package(GTest REQUIRED) - set(GTEST_LIBS GTest::GTest GTest::Main) + find_package(GTest) + if(GTEST_FOUND) + # Ordinarily, we'd use GTEST_LIBRARIES, but it seems that these do not always export + # the required libraries (e.g. gmock) on some OS (e.g macOS with brew). + set(GTEST_LIB GTest::gtest) + set(GMOCK_LIB GTest::gmock) + else() + message( + FATAL_ERROR + "Google Test not found, re-configure with -DBUILD_TESTS=OFF or -DSYSTEM_GTEST=OFF" + ) + endif() else() + if(NOT EXISTS ${gtest_base_dir}) + message( + FATAL_ERROR + "Google Test subproject not found, reconfigure with -DBUILD_TESTS=OFF" + ) + endif() + message(STATUS "Building GoogleTest") set(gtest_dir ${gtest_base_dir}/googletest) set(gmock_dir ${gtest_base_dir}/googlemock) @@ -416,7 +436,8 @@ macro(configure_gtest) set_target_properties(gmock PROPERTIES COMPILE_FLAGS "-w") endif() - set(GTEST_LIBS gtest gmock) + set(GTEST_LIB gtest) + set(GMOCK_LIB gmock) endif() endmacro() @@ -497,7 +518,14 @@ function(find_openssl_dir_win32 result) endfunction() macro(configure_wintoast) - # WinToast is a pretty niche library, and there doesn't seem to be a package for it. + # WinToast is a pretty niche library, and there doesn't seem to be an installable package, + # so we rely on building from source. file(GLOB WINTOAST_DIR ${CMAKE_SOURCE_DIR}/subprojects/WinToast-*) - include_directories(${WINTOAST_DIR}/include) + if(WINTOAST_DIR) + set(HAVE_WINTOAST true) + include_directories(${WINTOAST_DIR}/include) + else() + message(WARNING "WinToast subproject not found") + endif() + endmacro() diff --git a/config.yaml b/config.yaml index b1e2424cc..a91b48d62 100644 --- a/config.yaml +++ b/config.yaml @@ -120,6 +120,8 @@ config: qt6-base-devel \ qt6-tools-devel \ gtk3-devel \ + googletest-devel \ + googlemock-devel \ pugixml-devel \ libei-devel \ libportal-devel diff --git a/meson.build b/meson.build index bd548f8de..b6f12a908 100644 --- a/meson.build +++ b/meson.build @@ -3,16 +3,17 @@ project('synergy', 'cpp') -gtest = dependency('gtest', required: false) -if not gtest.found() +system_gtest = get_option('system_gtest') +if system_gtest + dependency('gtest', required: false) +else subproject('gtest') endif if host_machine.system() == 'windows' - wintoast = dependency('wintoast', required: false) - if not wintoast.found() - subproject('wintoast') - endif + # WinToast is a niche lib which is not commonly installed, + # so depend only on the subproject. + subproject('wintoast') endif if host_machine.system() == 'linux' diff --git a/meson_options.txt b/meson_options.txt index f6261128c..10145db8a 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,2 +1,3 @@ +option('system_gtest', type: 'boolean', value: true, description: 'Use system gtest') option('system_libportal', type: 'boolean', value: true, description: 'Use system libportal') option('system_libei', type: 'boolean', value: true, description: 'Use system libei') diff --git a/res/config.h.in b/res/config.h.in index e2ff66492..d5af31e46 100644 --- a/res/config.h.in +++ b/res/config.h.in @@ -180,3 +180,6 @@ /* Define if libei ei_device_start_emulating takes a sequence number */ #cmakedefine HAVE_LIBEI_SEQUENCE_NUMBER ${HAVE_LIBEI_SEQUENCE_NUMBER} + +/* Define if wintoast is available */ +#cmakedefine HAVE_WINTOAST ${HAVE_WINTOAST} diff --git a/scripts/install_deps.py b/scripts/install_deps.py index 5179bab7a..9cb354173 100755 --- a/scripts/install_deps.py +++ b/scripts/install_deps.py @@ -50,6 +50,10 @@ def main(): traceback.print_exc() error = True + colors = env.import_colors() + print() + print(f"{colors.SUCCESS_TEXT} Dependencies installed") + if args.pause_on_exit: input("Press enter to continue...") diff --git a/scripts/lib/colors.py b/scripts/lib/colors.py index 64956cf4d..b61697ad6 100644 --- a/scripts/lib/colors.py +++ b/scripts/lib/colors.py @@ -3,6 +3,7 @@ from colorama import Fore # type: ignore colorama.init() +SUCCESS_TEXT = f"{Fore.GREEN}Success:{Fore.RESET}" ERROR_TEXT = f"{Fore.RED}Error:{Fore.RESET}" WARNING_TEXT = f"{Fore.YELLOW}Warning:{Fore.RESET}" HINT_TEXT = f"{Fore.LIGHTBLUE_EX}Hint:{Fore.RESET}" diff --git a/scripts/lib/env.py b/scripts/lib/env.py index c783b6f0a..bc8592bf5 100644 --- a/scripts/lib/env.py +++ b/scripts/lib/env.py @@ -227,3 +227,9 @@ def get_app_version(): with open("VERSION", "r") as f: return f.read().strip() + + +def import_colors(): + import lib.colors as colors + + return colors diff --git a/scripts/lib/meson.py b/scripts/lib/meson.py index 8da6c2f12..bd1fe6e54 100644 --- a/scripts/lib/meson.py +++ b/scripts/lib/meson.py @@ -7,8 +7,15 @@ meson_bin = env.get_python_executable("meson") def setup(): - reconfigure = "--reconfigure" if os.path.exists(build_dir) else "" - cmd_utils.run([meson_bin, "setup", build_dir, reconfigure], print_cmd=True) + cmd = [meson_bin, "setup", build_dir] + + if env.is_windows(): + cmd.append("-Dsystem_gtest=false") + + if os.path.exists(build_dir): + cmd.append("--reconfigure") + + cmd_utils.run(cmd, print_cmd=True) def compile(): diff --git a/src/lib/synergy/CMakeLists.txt b/src/lib/synergy/CMakeLists.txt index 3a0e59244..e92017bac 100644 --- a/src/lib/synergy/CMakeLists.txt +++ b/src/lib/synergy/CMakeLists.txt @@ -21,7 +21,11 @@ file(GLOB sources "*.cpp" "languages/*.cpp") if(WIN32) file(GLOB arch_headers "win32/*.h") file(GLOB arch_sources "win32/*.cpp") - list(APPEND arch_sources ${WINTOAST_DIR}/src/wintoastlib.cpp) + + if(HAVE_WINTOAST) + list(APPEND arch_sources ${WINTOAST_DIR}/src/wintoastlib.cpp) + endif() + elseif(UNIX) file(GLOB arch_headers "unix/*.h") file(GLOB arch_sources "unix/*.cpp") diff --git a/src/lib/synergy/win32/AppUtilWindows.cpp b/src/lib/synergy/win32/AppUtilWindows.cpp index 2821404c4..81908bf39 100644 --- a/src/lib/synergy/win32/AppUtilWindows.cpp +++ b/src/lib/synergy/win32/AppUtilWindows.cpp @@ -1,6 +1,6 @@ /* * synergy -- mouse and keyboard sharing utility - * Copyright (C) 2012-2016 Symless Ltd. + * Copyright (C) 2012 Symless Ltd. * Copyright (C) 2002 Chris Schoeneman * * This package is free software; you can redistribute it and/or @@ -17,6 +17,7 @@ */ #include "synergy/win32/AppUtilWindows.h" + #include "arch/IArchTaskBarReceiver.h" #include "arch/win32/ArchMiscWindows.h" #include "arch/win32/XArchWindows.h" @@ -31,15 +32,17 @@ #include "synergy/ArgsBase.h" #include "synergy/Screen.h" #include "synergy/XSynergy.h" -#include "wintoastlib.h" #include +#include #include #include #include #include -#include +#if HAVE_WINTOAST +#include "wintoastlib.h" +#endif AppUtilWindows::AppUtilWindows(IEventQueue *events) : m_events(events), @@ -198,6 +201,7 @@ HKL AppUtilWindows::getCurrentKeyboardLayout() const { return layout; } +#if HAVE_WINTOAST class WinToastHandler : public WinToastLib::IWinToastHandler { public: WinToastHandler() {} @@ -207,9 +211,11 @@ public: void toastDismissed(WinToastDismissalReason state) const override {} void toastFailed() const override {} }; +#endif void AppUtilWindows::showNotification( const String &title, const String &text) const { +#if HAVE_WINTOAST LOG( (CLOG_INFO "showing notification, title=\"%s\", text=\"%s\"", title.c_str(), text.c_str())); @@ -247,4 +253,7 @@ void AppUtilWindows::showNotification( CLOG_DEBUG "failed to show toast notification, error code: %d", error)); return; } +#else + LOG((CLOG_INFO "toast notifications are not supported")); +#endif } diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index 8236ac4cb..6547a849d 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -129,8 +129,6 @@ macro(config_test_deps) include_directories(${CMAKE_BINARY_DIR}/src/lib/gui/gui_autogen/include) set(test_libs - gtest - gmock arch base client @@ -144,7 +142,8 @@ macro(config_test_deps) ipc license gui - ${GTEST_LIBS} + ${GMOCK_LIB} + ${GTEST_LIB} ${libs}) endmacro()