How to transmit the libusb dependency?

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

what is the output of?

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

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:

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.

Thanks a lot for your replies.
Actually I found my silly problem :sob: : trying to insert Qt5 paths and other parameters I overwrote the CMAKE_MODULE_PATH default values.
Removing that directive the package was found as expected.

Thanks