# Struggling to export a project

**URL:** <https://discourse.cmake.org/t/struggling-to-export-a-project/10491>\
**Category:** Code\
**Created:** [March 26, 2024, 5:01pm UTC](https://discourse.cmake.org/t/struggling-to-export-a-project/10491 "2024-03-26T17:01:18Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![jwm](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jwm/32/654_2.png) [@jwm](https://discourse.cmake.org/u/jwm)\
**Post date:** [April 19, 2024, 12:32am UTC](https://discourse.cmake.org/t/struggling-to-export-a-project/10491/6 "2024-04-19T00:32:43Z")

</div>

> [@ClausKlein](#):
>
> - You should not use a macro to build a library

Can you explain why? I am pathological in my commitment to DRY (Don’t Repeat Yourself). The projects I work on are large, with many libraries and executables. A macro seems tailor made to that end. Why is it better to repeat the same boilerplate lines of code in myriad CMakeLists.txt files?

I watched [CppCon 2019: Deep CMake For Library Authors - Crascit](https://crascit.com/2019/10/16/cppcon-2019-deep-cmake-for-library-authors/) and learned a couple of things, but nothing relevant to the issue at hand.

> [@ClausKlein](#):
>
> This is all generated with [cmake-init](https://github.com/friendlyanon/cmake-init) 🤠

I looked at **cmake-init**. The promise of creating `FetchContent`-ready projects is appealing. But, as it says it is “an opinionated CMake project initializer”. I haven’t quite comprehended its opinions.

My code layout is similar to [this one](https://discourse.cmake.org/t/file-set-include-directory-manipulation/10648/6).

In the end, what ultimately solved my issue was to remove `GTest::gtest` from the `target_link_libraries` and just add the include paths like this:

```cmake
if(TARGET GTest::gtest)
  get_target_property(gtest_includes GTest::gtest INCLUDE_DIRECTORIES)
  target_include_directories( ${myTarget} SYSTEM PRIVATE ${gtest_includes})
else()
  message(FATAL_ERROR "GoogleTest must be present to build")
endif()

```

I included them as private because I didn’t want users of this project via `FetchContent` to inherit those paths. This stopped the complaining about not installing GTest.

---

_[View the full topic](https://discourse.cmake.org/t/struggling-to-export-a-project/10491)._
