

Now, in your tests directory: add_subdirectory( "$)ġ. I would recommend using something like PROJECT_NAME STREQUAL CMAKE_PROJECT_NAME to set the default for the PACKAGE_TESTS option, since this should only build by default if this is the current project.Īs mentioned before, you have to do the enable_testing in your main CMakeLists. GTest exports the following targets: GTest::gtest GTest::gtestmain GTest::gmock GTest::gmockmain This targets should also be available when adding gtest with addsubdirectory (or FetchContent), because this should behave the same way as adding GTest with findpackage. Compatible build tools include Make, Ninja, and others - see CMake Generators for more information. Then, in your main CMakeLists.txt: option(PACKAGE_TESTS "Build the tests" ON) CMake and a compatible build tool for building the project. In this post, we look at three different ways to achieve this: Explaining the project setup. Also, having cmakeminimumrequired(VERSION 3. Getting started with Google Tests in a CMake project is very easy. The two dots next to cmake mean to look for the CMakeLists.txt script file in.

To use this method, just checkout GoogleTest as a submodule: 1 git submodule add -branch=release- 1.8. Adding GoogleMock is also often painful - and you need GoogleMock to get matchers, which are a default feature in Catch2 (but not doctest). Pulling GTest as a third-party dependency with Vcpkg. Pulling GTest as a third-party dependency with Conan. Using CMake’s fetchcontent to pull GTest’s code. See also "/glade/u/home/kshores/googletest/build/CMakeFiles/CMakeError.log".GoogleTest and GoogleMock are classic options personally, I personally would recommend Catch2 instead, as GoogleTest heavily follows the Google development philosophy it drops old compilers very quickly, it assumes users want to live at HEAD, etc. Getting started with Google Tests in a CMake project is very easy. See also "/glade/u/home/kshores/googletest/build/CMakeFiles/CMakeOutput.log". Configuring incomplete, errors occurred! Gmake: *** Error 2ĬMake will not be able to correctly generate this project. Gmake: Leaving directory '/glade/u/home/kshores/googletest/build/CMakeFiles/CMakeScratch/Tr圜ompile-yHoxfU' adddefinitions (-DGTESTCREATESHAREDLIBRARY1) creates compiler definition, not a CMake setting. If this will succeed, remove everything from your project except building googletest: your executable, Boost and so, and try again. "/usr/include/c++/7/type_traits", line 1817: error: incomplete type is not allowed First, try to build googletest using its CMakeLists.txt directly (without external project or so). module load nvhpc/23.1 cmake/3.5 #(or higher cmake version)įor me, running these steps produces this error: Building CXX object googletest/CMakeFiles/gtest.dir/src/.o

So far, I'm able to link all of my source files. These are the commands that I'm trying to use to build: cmake. NVHPC 23.1 cannot handle compiling google test with c++20. Here's the file structure that I want to use: -root -build -googletest-build -googletest-src -googletest-test -src -test -src -CMakeLists.txt -AllOfMySourceFiles -test -CMakeLists.txt -testgtest.cpp -CMakeLists.txt.
