Build boost for android with hunter

Viewed 62

my troubles are the following.

A boost is integrated to my CMake with hunter:

include(cmake/HunterGate.cmake)
cmake_host_system_information(RESULT HUNTER_JOBS_NUMBER QUERY NUMBER_OF_LOGICAL_CORES)
HunterGate(
    URL "https://github.com/cpp-pm/hunter/archive/v0.24.0.tar.gz"
    SHA1 "a3d7f4372b1dcd52faa6ff4a3bd5358e1d0e5efd"
    LOCAL
)

set(Boost_USE_STATIC_LIBS        ON)
set(Boost_USE_DEBUG_LIBS        OFF)  # ignore debug libs and
set(Boost_USE_RELEASE_LIBS       ON)  # only find release libs
set(Boost_USE_MULTITHREADED      ON)
set(Boost_USE_STATIC_RUNTIME    OFF)
set(BOOST_COMPONENTS)
list(APPEND BOOST_COMPONENTS system program_options)
hunter_add_package(Boost COMPONENTS ${BOOST_COMPONENTS})
find_package(Boost CONFIG COMPONENTS ${BOOST_COMPONENTS})

I build my project on linux Ubuntu for android with the following parameters:

config-android : _android
    cd $< && cmake \
                -DCMAKE_BUILD_TYPE=RelWithDebInfo \
                -DCMAKE_SYSTEM_NAME=Android \
                -DCMAKE_TOOLCHAIN_FILE=$(NDK)/build/cmake/android.toolchain.cmake \
                -DANDROID_ABI=$(ABI) \
                -DANDROID_PLATFORM=android-$(MINSDKVERSION) \
                -DANDROID_TARGET=$(TARGET) \
                ..

If I assign $ABI=armeabi-v7a, everything is all right. As I see, the boost is built on the following configuration:

[ 75%] Performing build step for 'Boost-system'
Performing configuration checks

    - default address-model    : 32-bit [1]
    - default architecture     : arm [1]

Building the Boost C++ Libraries.

However, if assign any other interface, for example, $ABI=x86_64, I have an error:

ld: error: /home/vitali/.hunter/_Base/a3d7f43/0db57b3/73320e1/Install/lib/libboost_program_options-mt-a64.a(cmdline.o) is incompatible with elf_x86_64

I suspect the reason for that error is the hunter builds boost not for the assigned ABI. As I see, it shows the same configuration as it was for arm ABI:

[ 75%] Performing build step for 'Boost-system'
Performing configuration checks

    - default address-model    : 32-bit [1]
    - default architecture     : arm [1]

Building the Boost C++ Libraries.

My question is the following: how to make hunter to build boost for the appropriate ABI ? Thanks!

1 Answers

I've met the same problem with Hunter. It's easy to solve. Create (or add to) file cmake/Hunter/config.cmake the following lines to pass additional cmake/ndk-toolchain parameters to boost build:

if(ANDROID)
hunter_config(
    Boost
    VERSION ${HUNTER_Boost_VERSION}
    CMAKE_ARGS
    CMAKE_ANDROID_ARCH_ABI=${ANDROID_ABI}
    ANDROID_ABI=${ANDROID_ABI}
    ANDROID_PLATFORM=${ANDROID_PLATFORM}
)
else()
hunter_config(
    Boost
    VERSION ${HUNTER_Boost_VERSION}
)
endif()

Generally, you have to pass ANDROID_ABI and ANDROID_PLATFORM. Hunter runs new cmake process to build boost, ndk toolchain is passed, abi & platform are not. So, toolchain does not know how to build boost and builds it by default. As result, there are many link errors.

Related