Skip to content

Commit c624e76

Browse files
authored
[CMake] Add a pcl_find_libusb.cmake (#4653)
1 parent 2d14ee9 commit c624e76

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ endif()
313313
# libusb
314314
option(WITH_LIBUSB "Build USB RGBD-Camera drivers" TRUE)
315315
if(WITH_LIBUSB)
316-
find_package(libusb)
316+
include("${PCL_SOURCE_DIR}/cmake/pcl_find_libusb.cmake")
317317
endif()
318318

319319
# Dependencies for different grabbers

cmake/Modules/Findlibusb.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ find_package_handle_standard_args(libusb DEFAULT_MSG libusb_LIBRARIES libusb_INC
6666

6767
mark_as_advanced(libusb_INCLUDE_DIRS libusb_LIBRARIES)
6868

69-
if(LIBUSB_FOUND)
69+
if(libusb_FOUND)
7070
add_library(libusb::libusb UNKNOWN IMPORTED)
7171
set_target_properties(libusb::libusb PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${libusb_INCLUDE_DIR}")
7272
set_target_properties(libusb::libusb PROPERTIES IMPORTED_LOCATION "${libusb_LIBRARIES}")

cmake/pcl_find_libusb.cmake

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#
2+
#pcl_find_libusb is used due to VCPKG making impossible to use local findXX modules.
3+
# and VCPKG findlibusb doesn't create the libusb targets.
4+
5+
# Find and set libusb
6+
find_package(libusb)
7+
8+
if(TARGET libusb::libusb)
9+
#libusb target is found by the find_package script.
10+
#VCPKG skip PCLs findlibusb and sets its own variables which is handled below.
11+
return()
12+
endif()
13+
14+
#Handle VCPKG definitions
15+
include(FindPackageHandleStandardArgs)
16+
find_package_handle_standard_args(libusb DEFAULT_MSG LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIRS)
17+
18+
mark_as_advanced(LIBUSB_INCLUDE_DIRS LIBUSB_LIBRARIES)
19+
20+
if(libusb_FOUND)
21+
add_library(libusb::libusb UNKNOWN IMPORTED)
22+
if(${LIBUSB_INCLUDE_DIRS})
23+
set_target_properties(libusb::libusb PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBUSB_INCLUDE_DIRS}")
24+
endif()
25+
if(EXISTS "${LIBUSB_LIBRARY}")
26+
set_target_properties(libusb::libusb PROPERTIES IMPORTED_LOCATION ${LIBUSB_LIBRARY})
27+
endif()
28+
if(EXISTS "${LIBUSB_LIBRARY_DEBUG}")
29+
set_target_properties(libusb::libusb PROPERTIES IMPORTED_LOCATION_DEBUG ${LIBUSB_LIBRARY_DEBUG})
30+
endif()
31+
if(EXISTS "${LIBUSB_LIBRARY_RELEASE}")
32+
set_target_properties(libusb::libusb PROPERTIES IMPORTED_LOCATION_RELEASE ${LIBUSB_LIBRARY_RELEASE})
33+
endif()
34+
endif()

0 commit comments

Comments
 (0)