# \[FetchContent\] How to include header files of a third-party project whose target does not provide them

**URL:** https://discourse.cmake.org/t/fetchcontent-how-to-include-header-files-of-a-third-party-project-whose-target-does-not-provide-them/9734
**Category:** Usage
**Created:** [December 29, 2023, 11:24am UTC](https://discourse.cmake.org/t/fetchcontent-how-to-include-header-files-of-a-third-party-project-whose-target-does-not-provide-them/9734 "2023-12-29T11:24:12Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![eulersson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eulersson/32/4126_2.png) [@eulersson](https://discourse.cmake.org/u/eulersson)
#### Post date: [December 29, 2023, 11:24am UTC](https://discourse.cmake.org/t/fetchcontent-how-to-include-header-files-of-a-third-party-project-whose-target-does-not-provide-them/9734/1 "2023-12-29T11:24:12Z")

</div>

Hello, I am trying to install a third-party library [cJSON](https://github.com/DaveGamble/cJSON) with CMake’s FetchContent and I managed to do it but I find it strange that the header files are not included in the cjson target. Usually the developer would use target\_include\_directories on his/her exported target so consumers don’t have to worry about header files, am I right?

I am not an expert with CMake so apologies if my question is stupid.

Here’s an excerpt of my project’s CMakeLists.txt:

```auto
project(myproject)
include(FetchContent)
FetchContent_Declare(
  cJSON
  GIT_REPOSITORY https://github.com/DaveGamble/cJSON
  GIT_TAG cb8693b058ba302f4829ec6d03f609ac6f848546 # v1.7.16
)
set(ENABLE_CJSON_TEST OFF CACHE BOOL "cJSON: Build with unit testing" FORCE)
FetchContent_MakeAvailable(cJSON)

// The three lines below would be replaced by a single one `target_link_libraries(${PROJECT_NAME} PUBLIC cjson)`
// if the cJSON project would include the header files as part of the target cjson?
configure_file(${cJSON_SOURCE_DIR}/cJSON.h ${CMAKE_BINARY_DIR}/include/cJSON/cJSON.h)
target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_BINARY_DIR}/include)
target_link_libraries(${PROJECT_NAME} PUBLIC cjson)

```

I am wondering if there’s a way that I can compile against cjson without hacking a build-time ${CMAKE\_BINARY\_DIR}/include/cJSON/cJSON.h file.

Thank you!

---

<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: [December 29, 2023, 2:55pm UTC](https://discourse.cmake.org/t/fetchcontent-how-to-include-header-files-of-a-third-party-project-whose-target-does-not-provide-them/9734/2 "2023-12-29T14:55:36Z")

</div>

See this answer:

> [@Ninja and ExternalProject\_Add](https://discourse.cmake.org/t/ninja-and-externalproject-add/9590/2):
>
> Mixing ExternalProject with “normal” targets is not well supported. I would suggest using FetchContent or using find\_package and using a superbuild to drive the builds using ExternalProject for each.

---

<div class="post-metadata">

### Author: ![eulersson](https://discourse.cmake.org/user_avatar/discourse.cmake.org/eulersson/32/4126_2.png) [@eulersson](https://discourse.cmake.org/u/eulersson)
#### Post date: [December 30, 2023, 11:26am UTC](https://discourse.cmake.org/t/fetchcontent-how-to-include-header-files-of-a-third-party-project-whose-target-does-not-provide-them/9734/3 "2023-12-30T11:26:32Z")

</div>

Thank you! Do you have any example of a super build setup? I believe that you mean running the installation process into a temporary folder and then compiling your project against all the assets in that folder? Can it be done within CMake?

---

<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: [December 30, 2023, 7:34pm UTC](https://discourse.cmake.org/t/fetchcontent-how-to-include-header-files-of-a-third-party-project-whose-target-does-not-provide-them/9734/4 "2023-12-30T19:34:45Z")

</div>

Here’s such a project: [https://gitlab.kitware.com/paraview/common-superbuild/](https://gitlab.kitware.com/paraview/common-superbuild/)

There’s excess stuff here for other use cases, but you generally just `ExternalProject_Add` with the instructions for each project and make sure their `DEPENDS` align.
