Cpp file can find libary header file but header file can't using Cmake

Viewed 59

FYI Im very new with cmake.

I have the following Structure in my project:

main.cpp
CMakeLists.txt
writer_pool/
- writer_pool.cpp
- writer_pool.h
- CMakeLists.txt

Both writer_pool.cpp and writer_pool.h have #include "json/json.h" from the JsonCpp package (https://github.com/open-source-parsers/jsoncpp). Except the issue is that the include statement only works in the writer_pool.cpp file and not writer_pool.h (gives json/json.h: No such file or directory). I.e. if I remove #include "json/json.h" from writer_pool.h the project compiles fine.

My CMakeLists.txt is:

cmake_minimum_required (VERSION 3.18)

project(pipeline)

add_subdirectory(writer_pool)

add_executable(${PROJECT_NAME} main.cpp)

find_package(jsoncpp REQUIRED)

target_link_directories(${PROJECT_NAME}
        PUBLIC
        writer_pool

        )

target_link_libraries(${PROJECT_NAME}
        PUBLIC
        writer_pool
        )

target_link_libraries(objects ${JSON_LIBRARIES})
target_include_directories(objects PUBLIC ${JSON_INCLUDE_DIRS})
target_compile_options(objects PUBLIC ${JSON_CFLAGS_OTHER})

and my writer_pool/CMakeLists.txt is:

add_library(objects objects.cpp)

I am completely stuck on how to get #include "json/json.h" in writer_pool.h and to actually compile...any help would be greatly appreciated!

0 Answers
Related