Struggling to export a project

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 and learned a couple of things, but nothing relevant to the issue at hand.

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.

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:

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.

1 Like