Make Meson-provided packages optional (#7459)

* Make Google Test optional

* Download googletest with brew

* Set gtest and gmock lib vars in Libraries.cmake

* Fixed cmake format

* Add googletest-devel for openSUSE

* Fixed missing Meson arg for Windows

* Add gmock-devel for openSUSE

* Fixed openSUSE package names

* Fixed openSUSE package names (correct OS)

* Add success message to disambiguate confusing messages

* Restore original gtest lib var for subproject

* Make WinToast optional

* Fixed formatting

* Fixed cmake format

* Only build WinToast sources if found
This commit is contained in:
Nick Bolton 2024-09-02 09:28:27 +01:00 committed by GitHub
parent 1e6c603739
commit bcdf70a298
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 87 additions and 21 deletions

View file

@ -2,3 +2,4 @@ brew 'make'
brew 'cmake'
brew 'openssl'
brew 'ninja'
brew 'googletest'

View file

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

View file

@ -120,6 +120,8 @@ config:
qt6-base-devel \
qt6-tools-devel \
gtk3-devel \
googletest-devel \
googlemock-devel \
pugixml-devel \
libei-devel \
libportal-devel

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -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 <VersionHelpers.h>
#include <Windows.h>
#include <conio.h>
#include <iostream>
#include <memory>
#include <sstream>
#include <Windows.h>
#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
}

View file

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