Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set CMAKE_PREFIX_PATH not working with Android Toolchain

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

like image 236
Suici Doga Avatar asked Oct 15 '16 03:10

Suici Doga


1 Answers

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.

like image 109
Tsyvarev Avatar answered Oct 14 '22 20:10

Tsyvarev