Skip to content

Commit

Permalink
CMake: Dont use pkg-config to find libusb on Mac OSX, rewrite to CMak…
Browse files Browse the repository at this point in the history
…e find module (tested on homebrew only)
  • Loading branch information
xor-gate committed May 5, 2016
1 parent e653ca6 commit d15a253
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
8 changes: 5 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ cmake_minimum_required(VERSION 2.8.7)
include(CheckCCompilerFlag)
find_package(PkgConfig)

pkg_check_modules(libusb REQUIRED libusb-1.0)
set(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH};${CMAKE_SOURCE_DIR}/cmake/modules")

find_package(LibUSB REQUIRED)
pkg_check_modules(gtk gtk+-3.0)

function(add_cflag_if_supported flag)
Expand Down Expand Up @@ -57,14 +59,14 @@ set(CFILES src/stlink-common.c
src/uglylogging.c
)

include_directories(${libusb_INCLUDE_DIRS})
include_directories(${LIBUSB_INCLUDE_DIR})
include_directories(src)
include_directories(mingw)

add_library(${PROJECT_NAME} STATIC
${HFILES} # header files for ide projects generated by cmake
${CFILES})
target_link_libraries(${PROJECT_NAME} ${libusb_LDFLAGS})
target_link_libraries(${PROJECT_NAME} ${LIBUSB_LIBRARIES})

add_executable(st-flash flash/main.c)
target_link_libraries(st-flash ${PROJECT_NAME})
Expand Down
27 changes: 27 additions & 0 deletions cmake/modules/FindLibUSB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# FindLibUSB.cmake - Try to find the Hiredis library
# Once done this will define
#
# LIBUSB_FOUND - System has libusb
# LIBUSB_INCLUDE_DIR - The libusb include directory
# LIBUSB_LIBRARIES - The libraries needed to use libusb
# LIBUSB_DEFINITIONS - Compiler switches required for using libusb

FIND_PATH(LIBUSB_INCLUDE_DIR NAMES libusb.h
HINTS
/usr
/usr/local
/opt
PATH_SUFFIXES libusb-1.0
)

FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb-1.0
HINTS
/usr
/usr/local
/opt
)

INCLUDE(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Libusb DEFAULT_MSG LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIR)

MARK_AS_ADVANCED(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES)

0 comments on commit d15a253

Please sign in to comment.