# Better way to work by modules with CMake and GTest or any library.

**URL:** https://discourse.cmake.org/t/better-way-to-work-by-modules-with-cmake-and-gtest-or-any-library/3699
**Category:** Usage
**Tags:** os:windows, comp:msvc
**Created:** [July 6, 2021, 1:09pm UTC](https://discourse.cmake.org/t/better-way-to-work-by-modules-with-cmake-and-gtest-or-any-library/3699 "2021-07-06T13:09:26Z")
**Posts on this page:** 1
**Showing post:** 7

<div class="post-metadata">

### Author: ![xhustango](https://discourse.cmake.org/user_avatar/discourse.cmake.org/xhustango/32/1614_2.png) [@xhustango](https://discourse.cmake.org/u/xhustango)
#### Post date: [July 16, 2021, 9:57am UTC](https://discourse.cmake.org/t/better-way-to-work-by-modules-with-cmake-and-gtest-or-any-library/3699/7 "2021-07-16T09:57:17Z")

</div>

The structure is as follows:

```auto
+-- 3rdparty/
| +-- LibA // contains fetching gtest and json to read config files
| +-- LibB/ // contains fetching gtest
| +-- LibC/ // contains fetching gtest
+-- ProjectA
| +-- include/
| | +-- header files 
| +--src
| | +-- source files
| +-- test
| | +-- test source files
| | +-- CMakeLists.txt // It was containing ExternalProject_Add for get GTest to build the test binaries.
| +-- CMakeLists.txt // Building projectA
+-- CMakeLists.txt // main CMake where I do add_subdirectory(ProjectA); add_subdirectory(LibA)

```

The error I was getting it was related to using the external project module of CMake that was realizing that the GoogleTest was already fetched at the project level. Changing the external project module to use the FetchingContent did the trick. All this is was coming from a previous configuration where ExternalProject\_Add was being used.

So FetchContent fixes the issue, and as well I even removed it from there because there is no need anymore to fetch as its coming from one of the libraries I built.

---

_[View the full topic](https://discourse.cmake.org/t/better-way-to-work-by-modules-with-cmake-and-gtest-or-any-library/3699)._
