How to get package X header files if find_package(X) only sets X_LIBRARIES but not X_INCLUDE_DIRS?

I am trying to understand how to use imported libraries in my project. I have read this documentation, but the concept and jargon are not clear to me. Let’s take a real-world example I’m dealing with now; my project builds a library, and my source files that make up that library must be compiled with headers from imported library X. Cmake’s find_package(X) sets X_LIBRARIES to contain IMPORTED targets in the form of X::foo, but does not set X_INCLUDE_DIRS. How should my project CMakeLists.txt specify where the target library gets package X header files, if I only have ${X_LIBRARIES} and not ${X_INCLUDE_DIRS}? The CMakefile currently looks like this:

# My library source files
set(src x.c y.c z.c)

# Static library

# Sources for my library include headers from X. But how do I specify this, if find_package(X) only give ${X_LIBRARIES} and not ${X_INCLUDE_DIR}???
target_include_directories(myLibrary PUBLIC ${X_INCLUDE_DIR})

How can I compile the library sources if I only have IMPORTED targets in ${X_LIBRARIES}?


The package should just provide the include directories as usage requirements on the imported targets. There’s zero requirement to have any include directory variable available.

1 Like