Finding Boost using CMake
Let me start by saying getting CMake to find Boost can be difficult because the automagic in FindBoost.cmake
will bite you and KitWare the makers of CMake have some of the worst documentation of any popular project I've ever encountered. You'll have to walk through the source of FindBoost.cmake
to debug it if it fails.
Cross-compiled Boost
The directory you installed cross-compiled boost looks like this assuming 1.62.0
boost-arm-build/include
boost-arm-build/include/boost-1_62
boost-arm-build/lib
The call to CMake from Project-Build directory
cmake \
-DBoost_NO_SYSTEM_PATHS=TRUE \
-DBoost_ADDITIONAL_VERSIONS="1.62" \
-DCMAKE_TOOLCHAIN_FILE=../android.toolchain \
-DBOOST_ROOT="../boost-arm-build" \
../Project/
-DBoost_ADDITIONAL_VERSIONS
- CMake looks for Boost using a hardcoded list of strings, if your CMake is older than the Boost version you're building it won't know where to look in the include directory so you'll need to pass it along. Although the version is actually 1.62.0, boost put the includes in boost-1_62 so I use 1.62 instead. In FindBoost.cmake
you'll find each version is added twice, as in "1.62.0" "1.62" for this very reason.
You should also inspect the file names of the libraries you built, for my example let's look at system
:
libboost_system-gcc-mt-1_62.a
libboost_system-gcc-mt-1_62.so # Symbolic link to libboost_system-gcc-mt-1_62.so.1.62.0
libboost_system-gcc-mt-1_62.so.1.62.0
libboost_system-gcc-mt-d-1_62.a
libboost_system-gcc-mt-d-1_62.so # Symbolic link to libboost_system-gcc-mt-d-1_62.so.1.62.0
libboost_system-gcc-mt-d-1_62.so.1.62.0
gcc
- the compiler usedmt
- multithreadedd
- debug1_62
- the version of boost, obviously
If you see libboost_system.a instead it means you failed to build boost with --with-layout=versioned
and should probably check out my SO Answer on building boost using the NDK. If you see clang
instead of gcc
it's great you've built boost with clang, but you'll probably need to inform CMake that clang exists using the Boost_COMPILER flag.
-DBoost_COMPILER="-clang"
android.toolchain file
set(CMAKE_SYSTEM_NAME Android)
set(CROSS_COMPILER_DIR /opt/ndk-R13-standalone)
set(CMAKE_C_COMPILER ${CROSS_COMPILER_DIR}/bin/arm-linux-androideabi-gcc)
set(CMAKE_CXX_COMPILER ${CROSS_COMPILER_DIR}/bin/arm-linux-androideabi-g++)
set(ANDROID_NATIVE_API_LEVEL android-19)
set(ANDROID_ABI armeabi-v7a)
set(ANDROID_STL gnustl_static)
set(CMAKE_SYSROOT ${CROSS_COMPILER_DIR}/sysroot)
set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT})
# search for programs in the build host directories
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)