设置CMAKE_PREFIX_PATH不能使用Android工具链 [英] set CMAKE_PREFIX_PATH not working with Android Toolchain
问题描述
我使用Android CMake工具链将CMake C和C ++游戏移植到Android。
项目的库依赖项存储在 PROJECTDIR / android_dependencies
中,我已将以下代码添加到CMake
设置(CMAKE_PREFIX_PATH$ {PROJECT_SOURCE_DIR} / android_dependencies / $ {ANDROID_ABI})
但是我的项目还是说它找不到像OpenAL
如果我将库复制到 $ NDK / platforms / android-9 / usr / lib
并包含文件到 $ NDK / platforms / android-9 / usr / include
项目正确编译。
几乎所有工具链都设置了变量 CMAKE_SYSROOT 变量。除了其他的东西,这个变量可以为路径添加额外的根,由 find _ *
CMake命令使用。
某些工具链可能会设置变量 CMAKE_FIND_ROOT_PATH_MODE _ *
,它们在搜索时调整 CMAKE_SYSROOT
的行为。
例如,设置变量 CMAKE_FIND_ROOT_PATH_MODE_LIBRARY 到只有
使 find_library
仅搜索仅有根的路径,因此一个找不到位于主机上的库。 (此规则有例外,请参见 find_library 的文档 cake> c> BOTH
(或只是清除它们)。但是一般来说这可能会破坏工具链(所以其他 find_library
调用会在主机上找到东西,而他们根本找不到任何东西)。
首选方法是在构建包本身之前遵循工具链策略并将所有包的预先安装到sysroot中。
I am porting a CMake C and C++ game to Android using the Android CMake Toolchain.
The library dependencies for the project are stored in PROJECTDIR/android_dependencies
and I have added the following code to the CMake file to use them (I checked that the directories and files exist).
set(CMAKE_PREFIX_PATH "${PROJECT_SOURCE_DIR}/android_dependencies/${ANDROID_ABI}")
But my project still says it could not find the dependencies like OpenAL (all the libraries are copied).
If I copy the libraries to $NDK/platforms/android-9/usr/lib
and include files to $NDK/platforms/android-9/usr/include
the project compiles correctly.
What could I be doing wrong ?
I am using Ubuntu 16.04 64-bit
Almost all toolchains set variable CMAKE_SYSROOT variable. This variable, aside other things, may add additional "root" to paths, used by find_*
CMake commands. But by default also "non-rooted" paths are searched too.
Some toolchains may set variable(s) CMAKE_FIND_ROOT_PATH_MODE_*
, which adjust behavior of CMAKE_SYSROOT
when search things.
E.g., setting variable CMAKE_FIND_ROOT_PATH_MODE_LIBRARY to ONLY
makes find_library
to search only "rooted" paths, so one cannot find libraries located on the host. (There are exceptions from this rule, see documentation for find_library for more details).
Script CMakeLists.txt
is able to change value of CMAKE_FIND_ROOT_PATH_MODE_*
variables, and set them to BOTH
(or just clear them). But generally this may break toolchain (so other find_library
calls will find something on host while they are intended to not find anything at all).
Preferred way is to follow toolchain strategy and install all package's prerequesites into sysroot before building the package itself.
这篇关于设置CMAKE_PREFIX_PATH不能使用Android工具链的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!