0

I have a C++ project which contains a testing application based on googletest library. It is built with help of cmake, which uses FetchContent to grab googletest from git.
Everything works quite good with one drawback: during the install step the content of gtest/gmock is partially copied to the installation location. These files aren't needed for the application, so I'm wondering how to disable/suppress this mess?

CMakeLists.txt:

cmake_minimum_required(VERSION 3.20)
project(test)

include(FetchContent)
FetchContent_Declare(googletest
    GIT_REPOSITORY https://github.com/google/googletest.git
    GIT_TAG release-1.12.1
)
FetchContent_MakeAvailable(googletest)

add_executable(test main.cpp)
target_link_libraries(test gtest_main)

install(TARGETS test)

main.cpp:

#include <gtest/gtest.h>

int add(int a, int b) {
    return a + b;
}

TEST(testCase, testAdd) {
    EXPECT_EQ(add(2, 3), 5);
}

The commands to execute:

mkdir build
cd build
cmake ..
cmake --build . --config Release
cmake --install . --prefix ../install

The created ../install directory will get (I'm building on Windows):

  1. bin\test.exe, which is expected (OK)
  2. include\gmock\... and include\gtest\... (with a lot of headers, which my app doesn't need)
  3. lib\gmock.lib, lib\gmock_main.lib, etc. (which the app doesn't need either)

I guess, this behavior is provided by FetchContent_MakeAvailable, and I couldn't find a way to tune it.
Probably it is specific to googletest only?

AntonK
  • 1,210
  • 1
  • 16
  • 22
  • "I guess, this behavior is provided by FetchContent_MakeAvailable" - `FetchContent_MakeAvailable` is effectively a `add_subdirectory` call, which makes googletest to be a **part** of your project. Since googletest has its own install commands, they are executed during the installing of your project... unless you disable them somehow. – Tsyvarev Sep 17 '22 at 22:12
  • @Tsyvarev , thanks for reviewing my question and linking it to the similar one, where I could find [the answer](https://stackoverflow.com/a/51746390/536172) which meets my need :) – AntonK Sep 19 '22 at 15:11

0 Answers0