Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linux/CMake: INTERFACE_INCLUDE_DIRECTORIES property of target hidapi::hidapi not correctly set in libhidapi.cmake (v0.12.0) #483

Closed
stsichler opened this issue Nov 16, 2022 · 2 comments
Labels
bug Something isn't working CMake Related to CMake build system

Comments

@stsichler
Copy link
Contributor

stsichler commented Nov 16, 2022

I have built hidapi (0.12.0) from source and installed it into a local directory (/home/xxxx/.lib/hidapi-0.12.0/x86_64-linux-gnu) using following commands:

git clone https://github.com/libusb/hidapi.git --branch hidapi-0.12.0 --depth 1 -c advice.detachedHead=false .lib/hidapi-0.12.0/src
cmake -S .lib/hidapi-0.12.0/src -B .lib/hidapi-0.12.0/x86_64-linux-gnu/.build -DCMAKE_INSTALL_PREFIX=.lib/hidapi-0.12.0/x86_64-linux-gnu -DBUILD_SHARED_LIBS=OFF
cmake --build .lib/hidapi-0.12.0/x86_64-linux-gnu/.build --config Release
cmake --install .lib/hidapi-0.12.0/x86_64-linux-gnu/.build

hidapi properly installes into the correct location, but the resulting contents of the generated libhidapi.cmake file includes these lines:

set_target_properties(hidapi::include PROPERTIES
  INTERFACE_INCLUDE_DIRECTORIES "/hidapi"
)

Note that installation prefix is missing here from the INTERFACE_INCLUDE_DIRECTORIES path.
In consequence, CMake outputs the following error when I try to consume the hidapi::hidapi target from another project:

CMake Error in CMakeLists.txt:
  Imported target "hidapi::hidapi" includes non-existent path

    "/hidapi"

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.
@Youw Youw added CMake Related to CMake build system bug Something isn't working labels Nov 16, 2022
@stsichler
Copy link
Contributor Author

stsichler commented Nov 16, 2022

Reason found:
src/CMakeLists.txt uses CMAKE_INSTALL_INCLUDEDIR for definition of target include directories of hidapi_include before it is defined by GNUInstallDirs:

"$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}/hidapi>"

See this patch moving GNUInstallDirs to an earlier position solving the problem.

Btw. Note that this problem only occurs at the first cmake configure call, because the CMAKE_INSTALL_INCLUDEDIR will be written into the cmake cache.

@Youw
Copy link
Member

Youw commented Nov 22, 2022

Interesting fact: CMAKE_INSTALL_INCLUDEDIR is empty only during the initial CMake run.
That's probably why I didn't catch it myself - I usually run cmake many times while I test anything locally.
Definitely need a good CI check for that.

Youw pushed a commit that referenced this issue Nov 22, 2022
@Youw Youw closed this as completed Nov 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working CMake Related to CMake build system
Projects
None yet
Development

No branches or pull requests

2 participants