# find\_package for Interface library

**URL:** <https://discourse.cmake.org/t/find-package-for-interface-library/10972>\
**Category:** Code\
**Tags:** os:linux\
**Created:** [June 7, 2024, 9:13am UTC](https://discourse.cmake.org/t/find-package-for-interface-library/10972 "2024-06-07T09:13:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pawel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@pawel](https://discourse.cmake.org/u/pawel)\
**Post date:** [June 7, 2024, 9:13am UTC](https://discourse.cmake.org/t/find-package-for-interface-library/10972/1 "2024-06-07T09:13:43Z")

</div>

Hello,

I have written a simple package with only one header file. Currently I’m trying to fetch my library from directory and then add it using `find_package`. In addition, I’m unable to `install` directory of header file in `_deps` directory (to be honest I’m not sure it’s needed or is a good practice). Below is the tree directory of the project and then the code of the `CMakeLists’ file.

```auto
├── cmake
│ └── utilsConfig.cmake.in
├── CMakeLists.txt
└── include
    ├── headers.hpp
    └── utilities.hpp

```

code:

```auto
cmake_minimum_required(VERSION 3.25)
project(utils)

include(CMakePackageConfigHelpers)
include(GNUInstallDirs) 

add_library(utils INTERFACE)
add_library(libutils::utils ALIAS utils)

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

install(TARGETS utils
  EXPORT ${PROJECT_NAME}Targets                                                              
  INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}                                           
)                                                                                            
                                                                                                                                                                               
install(DIRECTORY include/                                                                         
  TYPE INCLUDE
)

set(configFile ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake)
set(versionFile ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake)
set(configInstallDestination ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME})

configure_package_config_file(
  ${CMAKE_CURRENT_SOURCE_DIR}/cmake/utilsConfig.cmake.in
  ${configFile}
  INSTALL_DESTINATION ${configInstallDestination}
)

write_basic_package_version_file(
  "${versionFile}"
  COMPATIBILITY SameMajorVersion
)

install(FILES
    "${configFile}"
    "${versionFile}" 
  DESTINATION
    ${configInstallDestination}
)

install(EXPORT ${PROJECT_NAME}Targets
  NAMESPACE libutils::
  DESTINATION ${configInstallDestination}
)

```

Here is the directory tree of project in which I’m trying to `find_package`:

```auto
├── CMakeLists.txt
├── test.cpp
└── thirdparty
    └── libutils

```

and code of `CMakeLists`:

```auto
cmake_minimum_required(VERSION 3.23)
project(Test)

include(FetchContent)
FetchContent_Declare(
        utils
        SOURCE_DIR "${CMAKE_SOURCE_DIR}/thirdparty/libutils/"
)

FetchContent_MakeAvailable(libutils)
find_package(utils)

add_executable(Test test.cpp)
target_link_libraries(Test PUBLIC libutils::utils)

```

I want to mention that I can `include` `utilities.hpp` in `test.cpp` thanks to `INCLUDES DESTINATION` command. But for some reason `CMake` cannot find package.

---

<div class="post-metadata">

**Author:** ![pawel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/p/ecae2f/32.png) [@pawel](https://discourse.cmake.org/u/pawel)\
**Post date:** [June 8, 2024, 12:00pm UTC](https://discourse.cmake.org/t/find-package-for-interface-library/10972/2 "2024-06-08T12:00:45Z")

</div>

I got everything mixed up. I have started reading @craig.scott’s great book and things are becoming clearer to me.

The topic can be closed or removed 🙂
