8

I have a git repository with some test code in C++ and I want to use Googletest to write some tests. I used git submodule to get it as part of the above repository. I want to use meson as the build engine. So far, so good.

However, I cannot fathom how to get meson to build and link my tests with the googletest submodule… Should I use a wrap? An external dependency? what?

Note that meson supports dependencies on packaged versions of gtest/gmock but this is not what I want since the developers of gtest/gmock recommend against it. Plus, I want bleeding edge 'cause I am crazy⸮

Furthermore, I do not think ninja plays a role here but I mentioned that I use it just in case.

Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156

2 Answers2

10

I tried using the wrap for gtest with

gtest_proj = subproject('gtest')
gtest_dep = gtest_proj.get_variable('gtest_dep')
gmock_dep = gtest_proj.get_variable('gmock_dep')

in meson.build. This builds a local copies of googletest which can then be used like so:

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)

Note that libshield is a shared library created from my (toy) code so I can link to it.

Sardathrion - against SE abuse
  • 17,269
  • 27
  • 101
  • 156
9

If you would like to use a project that is not meson project you need to find that project in wrapDB:

meson wrap search gtest

If that command gives you name of the wrap then you need to install it to your project:

mkdir -p subprojects
meson wrap install gtest

Then you should reconfigure your project and meson will download that project for you:

meson --reconfigure path/to/build/dir

Additional information you can find in documentation of wrap tool.

--reconfigure - supported since 0.49.0

Umed
  • 227
  • 4
  • 13