Reorganize gtest
Currently, gtest is included as a source library. This means that every
test application compiles its own version of gtest. This is wasteful,
even though it's likely not that expensive compared to other compile
time things.
Move gtest into a library, upgrade our version of gtest at the same
time.
Tested: unit tests pass
Change-Id: I5064848bd42d6b119a8d4aa9bcac13ad8ec65955
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/meson.build b/meson.build
index f50212c..70d2068 100644
--- a/meson.build
+++ b/meson.build
@@ -258,7 +258,10 @@
systemd = dependency('systemd')
libsystemd = dependency('libsystemd')
-add_project_arguments('-DLIBSYSTEMD_VERSION=' + libsystemd.version(), language: 'cpp')
+add_project_arguments(
+ '-DLIBSYSTEMD_VERSION=' + libsystemd.version(),
+ language: 'cpp',
+)
zlib = dependency('zlib')
bmcweb_dependencies += [libsystemd, zlib]
@@ -312,24 +315,6 @@
endforeach
endif
-if get_option('tests').allowed()
- gtest = dependency(
- 'gtest',
- main: true,
- version: '>=1.14.0',
- disabler: true,
- required: false,
- )
- gmock = dependency('gmock', required: false)
- if not gtest.found() and get_option('tests').allowed()
- gtest_proj = subproject('gtest', required: true)
- gtest = gtest_proj.get_variable('gtest_main_dep')
- gmock = gtest_proj.get_variable('gmock_dep')
- endif
- gtest = gtest.as_system('system')
- gmock = gmock.as_system('system')
-endif
-
systemd_system_unit_dir = systemd.get_variable('systemdsystemunitdir')
bindir = get_option('prefix') + '/' + get_option('bindir')
@@ -457,6 +442,21 @@
)
if (get_option('tests').allowed())
+ gtest = dependency(
+ 'gtest_main',
+ main: true,
+ version: '>=1.15.0',
+ required: true,
+ )
+ gmock = dependency('gmock', required: true)
+ gtestlib = static_library('gtestlib', dependencies: [gtest, gmock])
+ gtestdep = declare_dependency(
+ link_with: gtestlib,
+ dependencies: [
+ gtest.partial_dependency(includes: true),
+ gmock.partial_dependency(includes: true),
+ ],
+ )
# generate the test executable
foreach test_src : srcfiles_unittest
test_bin = executable(
@@ -465,8 +465,8 @@
link_with: bmcweblib,
include_directories: incdir,
install_dir: bindir,
- dependencies: bmcweb_dependencies + [gtest, gmock],
+ dependencies: bmcweb_dependencies + [gtestdep],
)
- test(fs.stem(test_src), test_bin)
+ test(fs.stem(test_src), test_bin, protocol: 'gtest')
endforeach
endif
diff --git a/subprojects/gtest.wrap b/subprojects/gtest.wrap
index 8c067ff..2261ea3 100644
--- a/subprojects/gtest.wrap
+++ b/subprojects/gtest.wrap
@@ -1,16 +1,17 @@
[wrap-file]
-directory = googletest-1.14.0
-source_url = https://github.com/google/googletest/archive/refs/tags/v1.14.0.tar.gz
-source_filename = gtest-1.14.0.tar.gz
-source_hash = 8ad598c73ad796e0d8280b082cebd82a630d73e73cd3c70057938a6501bba5d7
-patch_filename = gtest_1.14.0-1_patch.zip
-patch_url = https://wrapdb.mesonbuild.com/v2/gtest_1.14.0-1/get_patch
-patch_hash = 2e693c7d3f9370a7aa6dac802bada0874d3198ad4cfdf75647b818f691182b50
-source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/gtest_1.14.0-1/gtest-1.14.0.tar.gz
-wrapdb_version = 1.14.0-1
+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
+