Update libusb to v1.0.22 (#695)

* Will not download libusb if it found.
* Checking CMAKE_LIBRARY_PATH before setting as STLINK_LIBRARY_PATH.
pull/697/head
Slyshyk Oleksiy 2018-03-28 10:49:14 +03:00 zatwierdzone przez Jerry Jacobs
rodzic 334fde7648
commit 389fda2443
2 zmienionych plików z 67 dodań i 27 usunięć

Wyświetl plik

@ -5,7 +5,17 @@ set(PROJECT_DESCRIPTION "Open source version of the STMicroelectronics Stlink To
set(STLINK_UDEV_RULES_DIR "/etc/udev/rules.d" CACHE PATH "Udev rules directory")
set(STLINK_MODPROBED_DIR "/etc/modprobe.d" CACHE PATH "modprobe.d directory")
set(LIB_INSTALL_DIR "lib" CACHE PATH "Main library directory")
set(STLINK_LIBRARY_PATH "${LIB_INSTALL_DIR}/${CMAKE_LIBRARY_PATH}" CACHE PATH "Target lib directory")
if(IS_DIRECTORY CMAKE_LIBRARY_PATH)
else()
set(CMAKE_LIBRARY_PATH "lib")
endif()
if (WIN32)
set(STLINK_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} CACHE PATH "Target lib directory")
else()
set(STLINK_LIBRARY_PATH "${LIB_INSTALL_DIR}/${CMAKE_LIBRARY_PATH}" CACHE PATH "Target lib directory")
endif(WIN32)
option(STLINK_GENERATE_MANPAGES "Generate manpages with pandoc" OFF)
@ -16,7 +26,9 @@ endif ()
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake/modules")
include(cmake/Version.cmake)
include(cmake/CFlags.cmake)
if(NOT MSVC)
include(cmake/CFlags.cmake)
endif()
###
# Dependencies
@ -120,6 +132,7 @@ else()
target_link_libraries(${STLINK_LIB_SHARED} ${LIBUSB_LIBRARY})
endif()
install(TARGETS ${STLINK_LIB_SHARED}
DESTINATION ${STLINK_LIBRARY_PATH}
)

Wyświetl plik

@ -6,27 +6,6 @@
# LIBUSB_LIBRARY - The libraries needed to use libusb
# LIBUSB_DEFINITIONS - Compiler switches required for using libusb
if(WIN32 OR CMAKE_VS_PLATFORM_NAME OR MINGW OR MSYS)
find_package(7Zip REQUIRED)
set(LIBUSB_WIN_VERSION 1.0.21)
set(LIBUSB_WIN_ARCHIVE libusb-${LIBUSB_WIN_VERSION}.7z)
set(LIBUSB_WIN_ARCHIVE_PATH ${CMAKE_BINARY_DIR}/${LIBUSB_WIN_ARCHIVE})
set(LIBUSB_WIN_OUTPUT_FOLDER ${CMAKE_BINARY_DIR}/3thparty/libusb-${LIBUSB_WIN_VERSION})
if(EXISTS ${LIBUSB_WIN_ARCHIVE_PATH})
message(STATUS "libusb archive already in build folder")
else()
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}
)
endif()
file(MAKE_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER})
execute_process(COMMAND ${ZIP_EXECUTABLE} x -y ${LIBUSB_WIN_ARCHIVE_PATH} -o${LIBUSB_WIN_OUTPUT_FOLDER})
endif()
# FreeBSD
if (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
FIND_PATH(LIBUSB_INCLUDE_DIR NAMES libusb.h
@ -39,7 +18,6 @@ else ()
/usr
/usr/local
/opt
${LIBUSB_WIN_OUTPUT_FOLDER}/include
PATH_SUFFIXES libusb-1.0
)
endif()
@ -48,7 +26,7 @@ if (APPLE)
set(LIBUSB_NAME libusb-1.0.a)
elseif(MSYS OR MINGW)
set(LIBUSB_NAME usb-1.0)
elseif(WIN32 OR CMAKE_VS_PLATFORM_NAME)
elseif(MSVC)
set(LIBUSB_NAME libusb-1.0.lib)
elseif(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
set(LIBUSB_NAME usb)
@ -64,10 +42,10 @@ if (MSYS OR MINGW)
find_library(LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW32/static)
endif ()
elseif(CMAKE_VS_PLATFORM_NAME)
elseif(MSVC)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
find_library(LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MS64/dll)
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MS64/dll)
else ()
find_library(LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MS32/dll)
@ -84,3 +62,52 @@ include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Libusb DEFAULT_MSG LIBUSB_LIBRARY LIBUSB_INCLUDE_DIR)
mark_as_advanced(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARY)
if(NOT LIBUSB_FOUND)
if(WIN32 OR MSVC OR MINGW OR MSYS)
find_package(7Zip REQUIRED)
set(LIBUSB_WIN_VERSION 1.0.22)
set(LIBUSB_WIN_ARCHIVE libusb-${LIBUSB_WIN_VERSION}.7z)
set(LIBUSB_WIN_ARCHIVE_PATH ${CMAKE_BINARY_DIR}/${LIBUSB_WIN_ARCHIVE})
set(LIBUSB_WIN_OUTPUT_FOLDER ${CMAKE_BINARY_DIR}/3thparty/libusb-${LIBUSB_WIN_VERSION})
if(EXISTS ${LIBUSB_WIN_ARCHIVE_PATH})
message(STATUS "libusb archive already in build folder")
else()
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}
)
endif()
file(MAKE_DIRECTORY ${LIBUSB_WIN_OUTPUT_FOLDER})
execute_process(COMMAND ${ZIP_EXECUTABLE} x -y ${LIBUSB_WIN_ARCHIVE_PATH} -o${LIBUSB_WIN_OUTPUT_FOLDER})
FIND_PATH(LIBUSB_INCLUDE_DIR NAMES libusb.h
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/include
PATH_SUFFIXES libusb-1.0
)
if (MSYS OR MINGW)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
find_library(LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW64/static)
else ()
find_library(LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MinGW32/static)
endif ()
elseif(MSVC)
if (CMAKE_SIZEOF_VOID_P EQUAL 8)
find_library(LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MS64/dll)
else ()
find_library(LIBUSB_LIBRARY NAMES ${LIBUSB_NAME}
HINTS ${LIBUSB_WIN_OUTPUT_FOLDER}/MS32/dll)
endif ()
endif ()
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Libusb DEFAULT_MSG LIBUSB_LIBRARY LIBUSB_INCLUDE_DIR)
endif()
else()
message(STATUS "found USB")
endif()