Skip to content

Commit

Permalink
Added back the original MINGW branch on findlibusb (but removed MSV…
Browse files Browse the repository at this point in the history
…C sub-branch)
  • Loading branch information
a-michelis committed Dec 7, 2024
1 parent 7bfd3a0 commit 04b8d0b
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions cmake/modules/Findlibusb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,64 @@ elseif (MSVC) # Native Windows MSVC
set(LIBUSB_LIBRARY ${LIBUSB_NAME})
mark_as_advanced(LIBUSB_FOUND LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY)
endif()
elseif (WIN32 OR (MINGW AND EXISTS "/etc/debian_version")) # Windows OR cross-build with MinGW-toolchain on Debian
# MinGW: 64-bit or 32-bit?
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "=== Building for Windows (x86-64) ===")
set(ARCH 64)
else ()
message(STATUS "=== Building for Windows (i686) ===")
set(ARCH 32)
endif()

if (NOT LIBUSB_FOUND)
# Preparations for installing libusb library
set(LIBUSB_WIN_VERSION 1.0.27) # set libusb version
set(LIBUSB_WIN_ARCHIVE_PATH ${CMAKE_SOURCE_DIR}/3rdparty/libusb-${LIBUSB_WIN_VERSION}.7z)
set(LIBUSB_WIN_OUTPUT_FOLDER ${CMAKE_SOURCE_DIR}/3rdparty/libusb-${LIBUSB_WIN_VERSION})

# Get libusb package
if (EXISTS ${LIBUSB_WIN_ARCHIVE_PATH}) # ... should the package be already there
message(STATUS "libusb archive already in build folder")
else () # ... download the package
message(STATUS "downloading libusb ${LIBUSB_WIN_VERSION}")
file(DOWNLOAD
https://sourceforge.net/projects/libusb/files/libusb-1.0/libusb-${LIBUSB_WIN_VERSION}/libusb-${LIBUSB_WIN_VERSION}.7z/download
${LIBUSB_WIN_ARCHIVE_PATH} EXPECTED_MD5 c72153fc5a32f3b942427b0671897a1a
)
endif()

file(MAKE_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER})

# Extract libusb package with cmake
execute_process(
COMMAND ${CMAKE_COMMAND} -E tar xv ${LIBUSB_WIN_ARCHIVE_PATH}
WORKING_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER}
)

# libusb header file
FIND_PATH(LIBUSB_INCLUDE_DIR
NAMES libusb.h
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/include
PATH_SUFFIXES libusb-1.0
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)


# libusb library (static)
set(LIBUSB_NAME libusb-1.0)
find_library(LIBUSB_LIBRARY
NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW${ARCH}/static
NO_DEFAULT_PATH
NO_CMAKE_FIND_ROOT_PATH
)
endif()

FIND_PACKAGE_HANDLE_STANDARD_ARGS(libusb DEFAULT_MSG LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY)
mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY)
message(STATUS "Missing libusb library has been installed")
else () # all other OS (unix-based)
# libusb header file
FIND_PATH(LIBUSB_INCLUDE_DIR
Expand Down

0 comments on commit 04b8d0b

Please sign in to comment.