From 949e1c0d71e63f6f66542f24a8cdd2601fb90c8d Mon Sep 17 00:00:00 2001 From: sithlord48 Date: Wed, 16 Oct 2024 01:31:53 -0400 Subject: [PATCH] build: Use Fetch Content for Gtest Use Fetch Content to get gtest and gmock --- cmake/Libraries.cmake | 63 ----------------------------------------- meson.build | 7 ----- meson_options.txt | 1 - scripts/lib/meson.py | 5 ---- src/test/CMakeLists.txt | 15 ++++++++-- subprojects/gtest.wrap | 16 ----------- 6 files changed, 13 insertions(+), 94 deletions(-) delete mode 100644 subprojects/gtest.wrap diff --git a/cmake/Libraries.cmake b/cmake/Libraries.cmake index 1735a149b..9ad339d05 100644 --- a/cmake/Libraries.cmake +++ b/cmake/Libraries.cmake @@ -30,10 +30,6 @@ macro(configure_libs) configure_openssl() configure_coverage() - if(BUILD_TESTS) - configure_gtest() - endif() - endmacro() # @@ -529,65 +525,6 @@ macro(configure_openssl) endmacro() -macro(configure_gtest) - - file(GLOB gtest_base_dir ${PROJECT_SOURCE_DIR}/subprojects/googletest-*) - if(gtest_base_dir) - set(DEFAULT_SYSTEM_GTEST OFF) - else() - set(DEFAULT_SYSTEM_GTEST ON) - endif() - - # Arch Linux package maintainers: - # We do care about not bundling libs and didn't mean to cause upset. We made some mistakes - # and we're trying to put that right. - # The comment "They BUNDLE a fucking zip for cryptopp" in deskflow.git/PKGBUILD is only - # relevant to a very version of old the code, so the comment should probably be removed. - # If there are any problems like this in future, please do feel free send us a patch! :) - option(SYSTEM_GTEST "Use system GoogleTest" ${DEFAULT_SYSTEM_GTEST}) - if(SYSTEM_GTEST) - message(VERBOSE "Using system GoogleTest") - 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(VERBOSE "Using local GoogleTest") - set(gtest_dir ${gtest_base_dir}/googletest) - set(gmock_dir ${gtest_base_dir}/googlemock) - include_directories(${gtest_dir} ${gmock_dir} ${gtest_dir}/include - ${gmock_dir}/include) - - add_library(gtest STATIC ${gtest_dir}/src/gtest-all.cc) - add_library(gmock STATIC ${gmock_dir}/src/gmock-all.cc) - - if(UNIX) - # Ignore noisy GoogleTest warnings - set_target_properties(gtest PROPERTIES COMPILE_FLAGS "-w") - set_target_properties(gmock PROPERTIES COMPILE_FLAGS "-w") - endif() - - set(GTEST_LIB gtest) - set(GMOCK_LIB gmock) - endif() - -endmacro() - macro(configure_coverage) if(ENABLE_COVERAGE) diff --git a/meson.build b/meson.build index 56cda85d4..6308ead53 100644 --- a/meson.build +++ b/meson.build @@ -9,13 +9,6 @@ if host_machine.system() == 'windows' subproject('wintoast') endif -system_gtest = get_option('system-gtest') -if system_gtest - dependency('gtest', required: false) -else - subproject('gtest') -endif - if host_machine.system() == 'linux' system_libei = get_option('system-libei') diff --git a/meson_options.txt b/meson_options.txt index c83cce109..db87004a3 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -1,3 +1,2 @@ -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/scripts/lib/meson.py b/scripts/lib/meson.py index e5bb250ea..e22481f2b 100644 --- a/scripts/lib/meson.py +++ b/scripts/lib/meson.py @@ -30,11 +30,6 @@ def meson_venv_bin(): def setup(no_system_list, static_list): cmd = [meson_venv_bin(), "setup", build_dir] - # TODO: These special Windows exceptions should probably be in Meson - # or somewhere other than this script, as it's a bit hacky. - if env.is_windows(): - cmd.append("-Dsystem-gtest=false") - for subproject in no_system_list or []: cmd.append(f"-Dsystem-{subproject}=false") diff --git a/src/test/CMakeLists.txt b/src/test/CMakeLists.txt index fd584b270..cad4e171f 100644 --- a/src/test/CMakeLists.txt +++ b/src/test/CMakeLists.txt @@ -14,6 +14,17 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +include(FetchContent) +set(INSTALL_GTEST OFF) +FetchContent_Declare( + googletest + GIT_REPOSITORY https://github.com/google/googletest.git + GIT_TAG b514bdc898e2951020cbdca1304b75f5950d1f59 # release-1.15.2 + GIT_SHALLOW 1 + FIND_PACKAGE_ARGS NAMES GTest +) +FetchContent_MakeAvailable(googletest) + macro(config_all_tests) # Required to load images from .qrc file. @@ -146,8 +157,8 @@ macro(config_test_deps) mt ipc gui - ${GMOCK_LIB} - ${GTEST_LIB} + GTest::gtest + GTest::gmock ${libs}) endmacro() diff --git a/subprojects/gtest.wrap b/subprojects/gtest.wrap deleted file mode 100644 index 91afad57e..000000000 --- a/subprojects/gtest.wrap +++ /dev/null @@ -1,16 +0,0 @@ -[wrap-file] -directory = googletest-1.15.0 -source_url = https://github.com/google/googletest/archive/refs/tags/v1.15.0.tar.gz -source_filename = gtest-1.15.0.tar.gz -source_hash = 7315acb6bf10e99f332c8a43f00d5fbb1ee6ca48c52f6b936991b216c586aaad -patch_filename = gtest_1.15.0-1_patch.zip -patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.15.0-1/get_patch -patch_hash = 5f8e484c48fdc1029c7fd08807bd2615f8c9d16f90df6d81984f4f292752c925 -source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/gtest_1.15.0-1/gtest-1.15.0.tar.gz -wrapdb_version = 1.15.0-1 - -[provide] -gtest = gtest_dep -gtest_main = gtest_main_dep -gmock = gmock_dep -gmock_main = gmock_main_dep