如何设置LIBUSB_INCLUDE_DIR [英] How to set LIBUSB_INCLUDE_DIR

查看:1653
本文介绍了如何设置LIBUSB_INCLUDE_DIR的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图交叉编译libftdi for arm。当我运行Cmake我得到:

I'm trying to cross-compile libftdi for arm. When I run Cmake I get:

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
LIBUSB_INCLUDE_DIR (ADVANCED)

我知道LIBUSB_INCLUDE_DIR应该在FindwinB1.cmake中设置,在libftdi根目录中找到。但是,我没有线索如何使FindUSB1.cmake找到libusb,我已经编译并放入/ opt / lib。这是默认文件:

I understand that LIBUSB_INCLUDE_DIR ought to be set in FindUSB1.cmake found in the libftdi root directory. However, I have no clue on how to make FindUSB1.cmake find libusb that I have compiled and put into /opt/lib. This is the default file:

# - 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, <montel@kde.org>
#
# 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-1.0)
  ENDIF(NOT WIN32)

  FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
    PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS})

  FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb-1.0
    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)

在/ opt / lib中有一个目录pkconfig。在这个目录中有一个libusb-1.0.pc文件,我猜想可能与这个问题有关。那么我应该如何让Cmake找到/opt/lib/libsub-1.0?

In /opt/lib there is a directory pkconfig. In this directory there is a libusb-1.0.pc file that I guess might have something to do with the problem. So how should I get Cmake to find /opt/lib/libsub-1.0?

推荐答案

不幸的是,默认的find脚本不是非常强大。如果库不位于其中一个默认目录通过 find_library 搜索,您必须依赖 pkg-config 告诉您图书馆的位置。

Unfortunately, the default find script is not very powerful. If the library is not located in one of the default directories searched by find_library, you have to rely on pkg-config to tell you where the library is located.

(没有那么不可能)事件,该库没有注册 pkg-config 要么,你没有选择,只是设置 PC_LIBUSB_LIBDIR PC_LIBUSB_INCLUDEDIR 变量之前调用查找脚本。这可以从命令行(使用 -D 参数)或者从包含的CMake脚本中(使用 set )。

In the (not so unlikely) event that the library is not registered with pkg-config either, you have no choice but setting the PC_LIBUSB_LIBDIR and PC_LIBUSB_INCLUDEDIR variables manually before calling the find script. This can be done either from the command line (using the -D parameter) or from within the enclosing CMake script (using set).

如果您可以自由地更改查找脚本,请考虑向查找调用添加其他 HINTS ,以使它们更灵活。例如,使用环境变量作为提示是一个非常流行的机制,也适用于非Unix平台。

If you are at liberty to make changes to the find script, consider adding additional HINTS to the find calls to make them more flexible. For instance, using an environment variable as a hint is a quite popular mechanism that also works well for non-Unix platforms.

FIND_PATH(LIBUSB_INCLUDE_DIR libusb.h
    HINTS $ENV{LIBUSB_ROOT}
    PATHS ${PC_LIBUSB_INCLUDEDIR} ${PC_LIBUSB_INCLUDE_DIRS}
    PATH_SUFFIXES include)

FIND_LIBRARY(LIBUSB_LIBRARIES NAMES usb-1.0
    HINTS $ENV{LIBUSB_ROOT}
    PATHS ${PC_LIBUSB_LIBDIR} ${PC_LIBUSB_LIBRARY_DIRS}
    PATH_SUFFIXES lib)

这篇关于如何设置LIBUSB_INCLUDE_DIR的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆