使用find_package()交叉编译 [英] cmake using find_package() cross compiling
问题描述
我将CMake与使用yocto构建的自定义工具链一起使用。不过我有一个问题,工具链的目标计算机有sysroot,而构建计算机有sysroot。
I am using CMake with a custom toolchain that I built using yocto. I have a problem though, the toolchain has sysroot for the target machine and one for the build machine.
CMake只会在构建系统sysroot中查找库。
CMake keeps finding the libraries in the build system sysroot only.
例如我正在使用:
find_package(libxml2)
但是它始终会在构建系统sysroot中而不是目标sysroot中找到libxml2。我该如何告诉它只查看目标sysroot?
But it always keeps finding libxml2 in the build system sysroot instead of the target sysroot. How can I tell it to only look in the target sysroot?
推荐答案
我怎么知道仅查看目标系统根目录?
How can I tell it to look in the target sysroot only?
有一系列CMake变量 CMAKE_FIND_ROOT_PATH_MODE _ *
,可针对不同的CMake命令调整搜索策略:
There is a family of CMake variables CMAKE_FIND_ROOT_PATH_MODE_*
, which adjusts search strategy for different CMake commands:
-
BOTH 值意味着搜索 target 和 host (构建)路径。当未设置变量时,这也是默认行为。
BOTH value means that both target and host (build) paths are searched. This is also a default behavior, when a variable is not set.
ONLY 值表示仅 target
ONLY value means that only target is searched.
Never 值表示只搜索主机。
变量列表:
-
CMAKE_FIND_ROOT_PATH_MODE_LIBRARY 影响
find_library()
调用
CMAKE_FIND_ROOT_PATH_MODE_INCLUDE 对 find_path()
和 find_file()
调用
CMAKE_FIND_ROOT_PATH_MODE_PACKAGE 影响 CONFIG find_package() >模式(搜索 * Config.cmake
文件时)。
CMAKE_FIND_ROOT_PATH_MODE_PACKAGE affects on find_package()
in CONFIG mode (when *Config.cmake
file is searched).
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM 会影响 find_program()
CMAKE_FIND_ROOT_PATH_MODE_PROGRAM affects on find_program()
call.
通常,具体的 find_package()
调用可能会受到所有这些变量的影响。在搜索库的情况下,通常只设置其中三个即可:
Generally, concrete find_package()
call may be affected by all of these variables. In case of searching libraries, it is usually suffificient to set only 3 of them:
# Search libraries only under *target* paths.
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)
$ b
变量 CMAKE_FIND_ROOT_PATH_MODE _ *
通常在工具链文件中设置。
Variables CMAKE_FIND_ROOT_PATH_MODE_*
are normally set in toolchain files.
这篇关于使用find_package()交叉编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!