# Need help resolving cJSON cmake dependency

**URL:** <https://discourse.cmake.org/t/need-help-resolving-cjson-cmake-dependency/7306>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [January 22, 2023, 5:31pm UTC](https://discourse.cmake.org/t/need-help-resolving-cjson-cmake-dependency/7306 "2023-01-22T17:31:24Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chrinkus](https://discourse.cmake.org/user_avatar/discourse.cmake.org/chrinkus/32/1801_2.png) [@Chrinkus](https://discourse.cmake.org/u/Chrinkus)\
**Post date:** [January 22, 2023, 5:31pm UTC](https://discourse.cmake.org/t/need-help-resolving-cjson-cmake-dependency/7306/1 "2023-01-22T17:31:24Z")

</div>

I’ve been happily using `FetchContent` in my new projects to resolve dependencies and its been super slick. Now I need a JSON parser and cJSON has [CMake build support](https://github.com/DaveGamble/cJSON/blob/master/CMakeLists.txt) so its a win!

However the cJSON `CMakeLists.txt` file was written a while ago and does something weird with its headers. Here’s the section in particular:

```auto
file(GLOB HEADERS cJSON.h)

# ~snip~

if (NOT BUILD_SHARED_AND_STATIC_LIBS)
    add_library("${CJSON_LIB}" "${CJSON_LIBRARY_TYPE}" "${HEADERS}" "${SOURCES}")
else()
    add_library("${CJSON_LIB}" SHARED "${HEADERS}" "${SOURCES}")
    add_library("${CJSON_LIB}-static" STATIC "${HEADERS}" "${SOURCES}")
    set_target_properties("${CJSON_LIB}-static" PROPERTIES OUTPUT_NAME "${CJSON_LIB}")
    set_target_properties("${CJSON_LIB}-static" PROPERTIES PREFIX "lib")
endif()
if (NOT WIN32)
    target_link_libraries("${CJSON_LIB}" m)
endif()

```

So it seems like they’re attaching the headers to the library but not in the same way that I’ve been using. I tried adding the following line which fixed this problem in my own libs:

```auto
target_include_directories("${CJSON_LIB}" PUBLIC "${PROJECT_SOURCE_DIR}/")

```

But that results in a bunch of errors in the configure stage:

```auto
CMake Error in build-debug/_deps/cjson-src/CMakeLists.txt:
  Target "cjson" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "/home/chrinkus/Repos/advent-of-code/2015/c/build-debug/_deps/cjson-src/"

  which is prefixed in the build directory.

CMake Error in build-debug/_deps/cjson-src/CMakeLists.txt:
  Target "cjson" INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "/home/chrinkus/Repos/advent-of-code/2015/c/build-debug/_deps/cjson-src/"

  which is prefixed in the build directory.Target "cjson"
  INTERFACE_INCLUDE_DIRECTORIES property contains path:

    "/home/chrinkus/Repos/advent-of-code/2015/c/build-debug/_deps/cjson-src/"

  which is prefixed in the source directory.

```

Is there a way for me to connect to cJSON’s headers through a generated variable or should I be using `find_package`? Or something else?

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:** [January 26, 2023, 2:09pm UTC](https://discourse.cmake.org/t/need-help-resolving-cjson-cmake-dependency/7306/2 "2023-01-26T14:09:40Z")

</div>

You’ll want to wrap that up in a `$<BUILD_INTERFACE>`. The errors are saying that the install references buildtree paths (which is usually not intended).
