Header-only library

I have an h-o library named utils. I’m trying to include this library in my project. This is my folder structure:

+ my_proj
| + source
| | + ext
| | | + utils
| | | | + include
| | | | | + utils
| | | | | | patterns.hxx
| | | | | | other utils headers...
| | | | CMakeLists.txt
| | CMakeLists.txt
| | main.cxx
| | other sources...
| CMakeLists.txt

my_proj/CMakeLists.txt:

...
add_subdirectory("./source/")
...

my_proj/source/CMakeLists.txt:

...
add_executable(exe_name sources...)
...
add_subdirectory("./ext/utils")
target_link_libraries(exe_name utils)
...

my_prog/source/ext/utils/CMakeLists.txt:

cmake_minimum_required(VERSION 3.14 FATAL_ERROR)

project("utils"
    VERSION 0.0.1
    LANGUAGES CXX
)

set(UTILS_LIB_NAME "utils")

add_library(${UTILS_LIB_NAME} INTERFACE)

include(GNUInstallDirs)

target_include_directories(
    ${UTILS_LIB_NAME}
    INTERFACE 
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include/utils>
        $<INSTALL_INTERFACE:include/utils>
)

target_compile_features(
    ${UTILS_LIB_NAME} 
    INTERFACE 
        cxx_std_17
)

install(
    TARGETS ${UTILS_LIB_NAME} 
    EXPORT utils_Targets
    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

install(
    DIRECTORY ${PROJECT_SOURCE_DIR}/include/utils 
    DESTINATION include
)

install(
    EXPORT utils_Targets
    FILE utilsTargets.cmake 
    DESTINATION  ${CMAKE_INSTALL_LIBDIR}/cmake/utils
    NAMESPACE utils::
)

include(CMakePackageConfigHelpers)

write_basic_package_version_file(
    "utilsConfigVersion.cmake"
    VERSION ${PROJECT_VERSION}
    COMPATIBILITY AnyNewerVersion
)

configure_package_config_file(
    "${PROJECT_SOURCE_DIR}/cmake/utilsConfig.cmake.in"
    "${PROJECT_BINARY_DIR}/utilsConfig.cmake"
    INSTALL_DESTINATION
        ${CMAKE_INSTALL_LIBDIR}/cmake/utils
)

install(
    FILES 
        ${PROJECT_BINARY_DIR}/utilsConfig.cmake
        ${CMAKE_CURRENT_BINARY_DIR}/utilsConfigVersion.cmake 
    DESTINATION 
        ${CMAKE_INSTALL_LIBDIR}/cmake/utils
)

in the main I’m trying to include a header:

// main.cxx
# include <utils/patterns.hxx>

but, compiler say me:

"unable to open the utils/patterns.xxx inclusion file "

I build my project with this commands (from the my_proj directory):

$ mkdir build && cd build && cmake ..
$ cmake --build . --config Release

so, what’s I do wrong?

If you’re including with a directory utils/ then you should not add that directory to your include path, only the directory above:

target_include_directories(
    ${UTILS_LIB_NAME}
    INTERFACE 
        $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
        $<INSTALL_INTERFACE:include>
)