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

Closed
opened 2022-11-16 04:28:25 -06:00 by stsichler · 2 comments
stsichler commented 2022-11-16 04:28:25 -06:00 (Migrated from github.com)

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.
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. ```
stsichler commented 2022-11-16 17:19:11 -06:00 (Migrated from github.com)

Reason found:
src/CMakeLists.txt uses CMAKE_INSTALL_INCLUDEDIR for definition of target include directories of hidapi_include before it is defined by GNUInstallDirs:
github.com/libusb/hidapi@2b70208fea/src/CMakeLists.txt (L77)

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.

Reason found: `src/CMakeLists.txt` uses `CMAKE_INSTALL_INCLUDEDIR` for definition of target include directories of `hidapi_include` before it is defined by `GNUInstallDirs`: https://github.com/libusb/hidapi/blob/2b70208feabeb4cb524dff58c450af63544790bc/src/CMakeLists.txt#L77 See this [patch](https://github.com/libusb/hidapi/files/10026378/patch.txt) 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 commented 2022-11-21 18:43:26 -06:00 (Migrated from github.com)

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.

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.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-libusb/hidapi#483
No description provided.