# Question about internal headers and idiomatic CMake use

**URL:** <https://discourse.cmake.org/t/question-about-internal-headers-and-idiomatic-cmake-use/668>\
**Category:** Code\
**Created:** [February 20, 2020, 5:01pm UTC](https://discourse.cmake.org/t/question-about-internal-headers-and-idiomatic-cmake-use/668 "2020-02-20T17:01:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_K](https://discourse.cmake.org/user_avatar/discourse.cmake.org/michael_k/32/379_2.png) [@Michael\_K](https://discourse.cmake.org/u/Michael_K)\
**Post date:** [February 20, 2020, 5:01pm UTC](https://discourse.cmake.org/t/question-about-internal-headers-and-idiomatic-cmake-use/668/1 "2020-02-20T17:01:05Z")

</div>

Hey,  
I’m quite new to CMake and try make a project with CMake. I need some hints / suggestions on how to make this as easy and as idiomatic as possible (so not to burden possible future users with bad CMake code). My project has the following folder structure:

./include/myproject/subproj1/  
./include/myproject/subproj1/internal/  
./include/myproject/subproj2/  
./include/myproject/subproj2/internal/  
./src/myproject/subproj2/

… and some others (tests etc.). Header files are in the include directory, subproj1 is a header only lib.

Can I make the “internal” folders not accessible to the ide / users of my lib with this folder structure? Do I need to alter the folder structure? I currently use the following code:

```
add_library(subproj1 INTERFACE)

target_include_directories(subproj1
    INTERFACE "${myproject_SOURCE_DIR}/include/"
)

add_library(subproj2 subproj2.cpp)

target_include_directories(subproj2 
    PUBLIC "${myproject_SOURCE_DIR}/include/"
# tried this, didnt have any effects
# PRIVATE "${myproject_SOURCE_DIR}/include/myproject/subproj2/internal/"
)

target_link_libraries(subproj2 PUBLIC subproj1)

```

Are there suggestions on how to structure your directories/code? Where can I find (non-trivial) libraries that use idiomatic, modern CMake (code) to draw some inspiration? I would like to use the includes (C++) in my code like this (kinda similar to boost):

```
#include "myproject/subproj1/subproj1.h"
#include "myproject/subproj2/subproj2.h"

```

Thanks for any help and suggestions  
mike

Edit: Made the layout a bit nicer

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [February 28, 2020, 7:44pm UTC](https://discourse.cmake.org/t/question-about-internal-headers-and-idiomatic-cmake-use/668/2 "2020-02-28T19:44:44Z")

</div>

You can use `target_include_directories(subproj2 INTERFACE $<BUILD_INTERFACE:path/to/internal_dir>)` to make the internal header directories only visible to your build.

However, I will note, that with the example structure you have here, someone can explicitly request `internal/` anyways (`#include <myproject/subproj2/internal/details.h>`). What I’d do is move `internal` to be like this:

```auto
./internal/include/myproject/subproj1
./internal/include/myproject/subproj2

```

You can then add this `internal` directory as a `PRIVATE` and/or `$<BUILD_INTERFACE:>` entry in `target_include_directories` as needed.
