我有一个带有一些 C++ 测试代码的 git 存储库,我想使用 Googletest写一些测试。我使用 git submodule
将其作为上述存储库的一部分获取。我想用 meson作为构建引擎。到目前为止,还不错。
但是,我无法理解如何让介子构建并将我的测试与 googletest 子模块链接起来……我应该使用包装吗?外部依赖?什么?
请注意 meson supports dependencies on packaged versions of gtest/gmock但这不是我想要的,因为 gtest/gmock 的开发人员反对它。另外,我想要前沿技术,因为我疯了⸮
此外,我不认为忍者在这里发挥作用,但我提到我使用它以防万一。
最佳答案
我尝试使用 the wrap for gtest与
gtest_proj = subproject('gtest')
gtest_dep = gtest_proj.get_variable('gtest_dep')
gmock_dep = gtest_proj.get_variable('gmock_dep')
在 meson.build
中。这会构建一个 googletest 的本地副本,然后可以像这样使用它:
tests_src = [
'tests/gtest-all.cpp',
'tests/test_MyClass.cpp',
]
e = executable(
'gtest-all',
tests_src,
dependencies : [
gtest_dep,
gmock_dep],
link_with : libshield,
)
test('gtest tests', e)
请注意,libshield
是根据我的(玩具)代码创建的共享库,因此我可以链接到它。
关于linux - 如何使用介子设置 googletest?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57473395/