# How to transmit the libusb dependency?

**URL:** <https://discourse.cmake.org/t/how-to-transmit-the-libusb-dependency/10100>\
**Category:** Code\
**Tags:** os:windows\
**Created:** [February 15, 2024, 9:54am UTC](https://discourse.cmake.org/t/how-to-transmit-the-libusb-dependency/10100 "2024-02-15T09:54:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Stefano\_M](https://discourse.cmake.org/user_avatar/discourse.cmake.org/stefano_m/32/4312_2.png) [@Stefano\_M](https://discourse.cmake.org/u/Stefano_M)\
**Post date:** [February 15, 2024, 9:54am UTC](https://discourse.cmake.org/t/how-to-transmit-the-libusb-dependency/10100/1 "2024-02-15T09:54:15Z")

</div>

Hi all,  
I’m writing two c++ projects, both controlled by CMakeLists files: a library and an application.  
VisualStudio 2019 as environment.

## Library libUpgrade

It includes libusb library installed by vcpkg tool, so in CMakeLists file I included the following directives:

> find\_package(PkgConfig REQUIRED)  
> pkg\_check\_modules(libusb REQUIRED IMPORTED\_TARGET libusb-1.0)  
> target\_link\_libraries(${CMAKE\_PROJECT\_NAME} PRIVATE PkgConfig::libusb)

The VisualStudio project is correclty generated without errors and the library is compiled.

Same project generates _libUpgradeConfig.cmake_ file inside the ./install/cmake folder by the configure\_package\_config\_file() command.  
This file I guess should transmit the libusb dependency to the upper projects.

## Application

The application includes the library in the follwing mode:

> find\_package(libUpgrade REQUIRED)

This one looks for the libusb package by the …/include/cmake/libUpgradeConfig.cmake file but, in this project, the libusb package is not found:

> – Found PkgConfig: C:/Users/stefano.mora/Source/Repos/vcpkg/installed/x64-windows/tools/pkgconf/pkgconf.exe (found version “2.1.0”)  
> – Checking for module ‘libusb-1.0’  
> – Package ‘libusb-1.0’, required by ‘virtual:world’, not found  
> CMake Error at C:/Program Files/CMake/share/cmake-3.28/Modules/FindPkgConfig.cmake:619 (message):  
> The following required packages were not found:
> 
> - libusb-1.0
> 
> Call Stack (most recent call first):  
> C:/Program Files/CMake/share/cmake-3.28/Modules/FindPkgConfig.cmake:841 (\_pkg\_check\_modules\_internal)  
> C:/Users/stefano.mora/Source/Repos/dbTechnologies/libUpgrade/install/cmake/libUpgradeConfig.cmake:44 (pkg\_check\_modules)  
> C:/Users/stefano.mora/Source/Repos/vcpkg/scripts/buildsystems/vcpkg.cmake:859 (\_find\_package)  
> CMakeLists.txt:55 (find\_package)

I guess the libUpgradeConfig.cmake file is lacking of something.  
The libUpgradeConfig model file is the following:

> set(LIBUPGRADE\_VERSION @CMAKE\_PROJECT\_VERSION@)  
> @PACKAGE\_INIT@
> 
> set\_and\_check(libUpgrade\_INCLUDE\_DIRS @ PACKAGE\_INCLUDE\_INSTALL\_DIR@ )
> 
> check\_required\_components(libUpgrade)  
> include(${CMAKE\_CURRENT\_LIST\_DIR}/libUpgradeTargets.cmake)
> 
> set\_target\_properties(libUpgrade PROPERTIES  
> MAP\_IMPORTED\_CONFIG\_MINSIZEREL Debug  
> MAP\_IMPORTED\_CONFIG\_RELWITHDEBINFO Debug  
> )
> 
> include(CMakeFindDependencyMacro)  
> find\_dependency(PkgConfig)  
> pkg\_check\_modules(libusb REQUIRED IMPORTED\_TARGET libusb-1.0)

Thanks,  
regards

---

<div class="post-metadata">

**Author:** ![ClausKlein](https://discourse.cmake.org/user_avatar/discourse.cmake.org/clausklein/32/352_2.png) [@ClausKlein](https://discourse.cmake.org/u/ClausKlein)\
**Post date:** [February 15, 2024, 4:29pm UTC](https://discourse.cmake.org/t/how-to-transmit-the-libusb-dependency/10100/2 "2024-02-15T16:29:58Z")

</div>

what is the output of?

```auto
pkg-config --list-all
pkg-config --print-variables --debug libusb
pkg-config --libs --cflags libusb

```

---

<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:** [February 18, 2024, 3:21am UTC](https://discourse.cmake.org/t/how-to-transmit-the-libusb-dependency/10100/3 "2024-02-18T03:21:54Z")

</div>

The term here is “relocatability”. Your install doesn’t presume to know where `libusb` will be on the consuming machine; therefore your project is “relocatable”. However, there are some niceties possible with non-relocatable packages (note that the build tree is _always_ non-relocatable). The way I handle this in CMake is [here](https://gitlab.kitware.com/vtk/vtk/-/blob/fb63d3781b1fa8c7d29307a9865f8663766c12ad/CMake/vtk-config.cmake.in#L152):

```cmake
include("${CMAKE_CURRENT_LIST_DIR}/vtk-find-package-helpers.cmake" OPTIONAL)

```

The build tree always has this file and it is installed only if a non-relocatable build is requested. This file contains a bunch of `_DIR` settings for VTK’s own dependencies as they existed during VTK’s build. This (usually) resolves any problems using VTK’s dependencies transitively. The downside is that the dependencies can’t move.

---

<div class="post-metadata">

**Author:** ![Stefano\_M](https://discourse.cmake.org/user_avatar/discourse.cmake.org/stefano_m/32/4312_2.png) [@Stefano\_M](https://discourse.cmake.org/u/Stefano_M)\
**Post date:** [February 18, 2024, 4:01pm UTC](https://discourse.cmake.org/t/how-to-transmit-the-libusb-dependency/10100/4 "2024-02-18T16:01:13Z")

</div>

Thanks a lot for your replies.  
Actually I found my silly problem 😭 : trying to insert Qt5 paths and other parameters I overwrote the [`CMAKE_MODULE_PATH`](https://cmake.org/cmake/help/latest/variable/CMAKE_MODULE_PATH.html#variable:CMAKE_MODULE_PATH) default values.  
Removing that directive the package was found as expected.

Thanks
