1

I have the following directory structure:

Project
  |  
  |-CMakeLists.txt

Library
  |
  |-LibProjectA
  |   |-CMakeLists.txt
  |   |-src
  |      |-SomeHeader0.h
  |-LibProjectB
  |   |-CMakeLists.txt
  |   |-src
  |      |-SomeHeader1.h
  |-LibProjectC
      |-CMakeLists.txt
      |-src
         |-SomeHeader2.h

OpenSourceProject
  |
  |-CMakeLists.txt
  |-src
     |-SomeOpenSourceHeader.h

Wherein Project includes the statically linked library LibProjectA in the Library directory. LibProjectA depends on LibProjectB. LibProjectB depends on LibProjectC. LibProjectA, LibProjectB, and LibProjectC all utilize the OpenSourceProject and LibProjectC specifically requires access to SomeOpenSourceHeader.h.

Whenever I perform an add_subdirectory on LibProjectC, I am forced to provide a precise path specifying where SomeOpenSourceHeader.h is. Even if this is in the CMakeLists.txt within the top level Project directory. Is there some way that by merely performing an add_subdirectory on the CMakeLists.txt in the OpenSourceProject, the path can be provided such that files therein can automatically be recognized elsewhere in the code and that the target project doesn't need to have any knowledge about the open source library used at a much lower level.

All libraries are statically linked.

Alex Baum
  • 166
  • 9
  • What include paths are you setting? How are you setting said include paths? – Stephen Newell Aug 10 '22 at 00:42
  • Currently, if `LibProjectC` requires access to `SomeOpenSourceHeader.h` I would have to do `target_include_directories( ${PROJECT_NAME} PUBLIC ../../OpenSourceProject/src`. This is precisely what I want to avoid. If there is already an `add_subdirectory( ../../OpenSourceProject build_osp)`, why should I have also specify the precise location of the header? When using open source libraries like `fmt` this is somehow avoided. – Alex Baum Aug 10 '22 at 14:26
  • 1
    If `OpenSourceProject` sets include paths properly, `target_link_libraries` should handle that for you. If it doesn't, send a patch upstream so that include paths (and other flags) are set properly on the project and will propagate to dependents. – Stephen Newell Aug 10 '22 at 14:32
  • Thank you! That worked. I created a MWE based on the use of `target_include_directories` instead of `include_directories`. – Alex Baum Aug 10 '22 at 15:09

0 Answers0