build: Use Fetch Content for Gtest
Use Fetch Content to get gtest and gmock
This commit is contained in:
parent
b1fa9eadd9
commit
949e1c0d71
6 changed files with 13 additions and 94 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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')
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,17 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
Loading…
Reference in a new issue