From 89a3169e7d78b6aff609aa88760af2fd5c61cf7c Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Mon, 16 Feb 2009 14:54:34 +0100 Subject: [PATCH] Added FindUSB cmake macro --- CMakeLists.txt | 4 ++++ FindUSB.cmake | 38 ++++++++++++++++++++++++++++++++++++++ ftdipp/CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 FindUSB.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index dd05d4b..40b4ceb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ set(MAJOR_VERSION 0) set(MINOR_VERSION 15) set(PATCH_VERSION 0) set(VERSION_STRING ${MAJOR_VERSION}.${MINOR_VERSION}.${PATCH_VERSION}) +SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}") # CMake if("${CMAKE_BUILD_TYPE}" STREQUAL "") @@ -18,6 +19,9 @@ if(${CMAKE_BUILD_TYPE} STREQUAL Debug) add_definitions(-DDEBUG) endif(${CMAKE_BUILD_TYPE} STREQUAL Debug) +FIND_PACKAGE(USB REQUIRED) +INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIR}) + # Set components set(CPACK_COMPONENTS_ALL sharedlibs staticlibs headers) set(CPACK_COMPONENT_SHAREDLIBS_DISPLAY_NAME "Shared libraries") diff --git a/FindUSB.cmake b/FindUSB.cmake new file mode 100644 index 0000000..566cdd8 --- /dev/null +++ b/FindUSB.cmake @@ -0,0 +1,38 @@ +# - Try to find the freetype library +# Once done this defines +# +# LIBUSB_FOUND - system has libusb +# LIBUSB_INCLUDE_DIR - the libusb include directory +# LIBUSB_LIBRARIES - Link these to use libusb + +# Copyright (c) 2006, 2008 Laurent Montel, +# +# Redistribution and use is allowed according to the terms of the BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + + +if (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) + + # in cache already + set(LIBUSB_FOUND TRUE) + +else (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) + IF (NOT WIN32) + # use pkg-config to get the directories and then use these values + # in the FIND_PATH() and FIND_LIBRARY() calls + find_package(PkgConfig) + pkg_check_modules(PC_LIBUSB libusb) + ENDIF(NOT WIN32) + + FIND_PATH(LIBUSB_INCLUDE_DIR usb.h + PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS}) + + FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb + PATHS ${PC_LIBUSB_LIBDIR} ${PC_LIBUSB_LIBRARY_DIRS}) + + include(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBUSB DEFAULT_MSG LIBUSB_LIBRARIES LIBUSB_INCLUDE_DIR) + + MARK_AS_ADVANCED(LIBUSB_INCLUDE_DIR LIBUSB_LIBRARIES) + +endif (LIBUSB_INCLUDE_DIR AND LIBUSB_LIBRARIES) diff --git a/ftdipp/CMakeLists.txt b/ftdipp/CMakeLists.txt index 2759208..411abdb 100644 --- a/ftdipp/CMakeLists.txt +++ b/ftdipp/CMakeLists.txt @@ -21,7 +21,7 @@ message(STATUS "Building libftdi++") add_library(ftdi_cpp SHARED ${cpp_sources}) # Dependencies -target_link_libraries(ftdi_cpp ftdi usb ${BOOST_LIBRARIES}) +target_link_libraries(ftdi_cpp ftdi ${LIBUSB_LIBRARIES} ${BOOST_LIBRARIES}) # Install if(${UNIX}) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6f1c40b..7965999 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,7 +10,7 @@ set(c_headers ftdi.h) add_library(ftdi SHARED ${c_sources}) # Dependencies -target_link_libraries(ftdi usb) +target_link_libraries(ftdi ${LIBUSB_LIBRARIES}) # Install if(${UNIX}) -- 1.7.1