Boost-for-Android icon indicating copy to clipboard operation
Boost-for-Android copied to clipboard

cmake

Open mgood7123 opened this issue 4 years ago • 4 comments

will this support CMake in the future?

mgood7123 avatar Jul 02 '20 13:07 mgood7123

You can call the build script with a CMake COMMAND block, but seeing as to how Boost proper doesn't have a functioning CMake build chain I doubt this project will.

Kagetsuki avatar Jul 04 '20 02:07 Kagetsuki

You can call the build script with a CMake COMMAND block, but seeing as to how Boost proper doesn't have a functioning CMake build chain I doubt this project will.

maybe something like this https://github.com/moritz-wundke/Boost-for-Android/issues/199

in that this will be an alternative to the ndk-build approach, since a lot of projects use CMake, and as far as i know, you cannot include ndk-build projects from CMake

mgood7123 avatar Jul 04 '20 07:07 mgood7123

You can include ndk-build projects in CMake. There's even a toolchain file you can use at <NDK>/build/cmake/android.toolchain.cmake. Just remember you need to run a full separate CMake build for each architecture. What I do personally is split up all my dependencies into vendor/<platform> folders and add an option variable for the architecture, then I just switch the link/header/etc. paths based on that.

As for the NDK location, if you want to use side-by-side NDK you can get the location of the current default NDK by calling Gradle from CMake with something like the following build.gradle:

buildscript {
    repositories {
        google()
        mavenCentral()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

def platforms = ['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64']
def sdk_level = 29
if (project.hasProperty('ANDROID_SDK_LEVEL')) {
	sdk_level = project.property('ANDROID_SDK_LEVEL').toString() 
}
def min_sdk_version = 21
if (project.hasProperty('ANDROID_MIN_SDK_VERSION')) {
	min_sdk_version = project.property('ANDROID_MIN_SDK_VERSION').toString() 
}
def android_vendor_path = "./vendor"
if (project.hasProperty('ANDROID_VENDOR_PATH')) {
	android_vendor_path = project.property('ANDROID_VENDOR_PATH').toString() 
}

apply plugin: 'com.android.application'

android {
    compileSdkVersion sdk_level
    defaultConfig {
        minSdkVersion min_sdk_version
        targetSdkVersion sdk_level
        ndk {
            abiFilters = platforms
        }
		compileOptions {
			targetCompatibility 1.8
			sourceCompatibility 1.8
		}
    }

	task getNDKPath() {
		println(android.ndkDirectory)
	}
}

and these lines in CMake:

# Set target SDK level
set(ANDROID_TARGET_API "29")

# Obtain the NDK path from the side-by-side NDK detected by Gradle
execute_process(
	COMMAND "gradle" "-q" "getNDKPath"
	OUTPUT_VARIABLE ANDROID_NDK_HOME
)
string(REGEX REPLACE "\n$" "" ANDROID_NDK_HOME "${ANDROID_NDK_HOME}")

That will give you the NDK path in a CMake variable ANDROID_NDK_HOME.

If you're separating out the libraries/headers/etc with a platform prefix then you don't need the trailing library architecture information (the default build style for boost-for-android). I actually just submitted a patch to allow for "system" naming https://github.com/moritz-wundke/Boost-for-Android/pull/195 . If you use this you can cut down your CMake file significantly. The build command I have looks something like this:

# Set the minor version for Boost for Android (1.XX)
set(ANDROID_BOOST_MINOR_VERSION 73)

# Boost
add_custom_command(
	OUTPUT
		${CMAKE_BINARY_DIR}/android/platform/armeabi-v7a/lib/libboost_system.a
		${CMAKE_BINARY_DIR}/android/platform/armeabi-v7a/lib/libboost_filesystem.a
		${CMAKE_BINARY_DIR}/android/platform/arm64-v8a/lib/libboost_system.a
		${CMAKE_BINARY_DIR}/android/platform/arm64-v8a/lib/libboost_filesystem.a
		${CMAKE_BINARY_DIR}/android/platform/x86/lib/libboost_system.a
		${CMAKE_BINARY_DIR}/android/platform/x86/lib/libboost_filesystem.a
		${CMAKE_BINARY_DIR}/android/platform/x86_64/lib/libboost_system.a
		${CMAKE_BINARY_DIR}/android/platform/x86_64/lib/libboost_filesystem.a

		${CMAKE_BINARY_DIR}/android/platform/armeabi-v7a/include/boost
		${CMAKE_BINARY_DIR}/android/platform/arm64-v8a/include/boost
		${CMAKE_BINARY_DIR}/android/platform/x86/include/boost
		${CMAKE_BINARY_DIR}/android/platform/x86_64/include/boost

	WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/interfaces/android/vendor/Boost-for-Android
	COMMAND sh ./build-android.sh ${ANDROID_NDK_HOME} --layout=system --boost=1.${ANDROID_BOOST_MINOR_VERSION}.0 --prefix=${CMAKE_BINARY_DIR}/android/platform/
)
add_custom_target(android-prebuild-Boost
	DEPENDS
		${CMAKE_BINARY_DIR}/android/platform/armeabi-v7a/lib/libboost_system.a
		${CMAKE_BINARY_DIR}/android/platform/armeabi-v7a/lib/libboost_filesystem.a
		${CMAKE_BINARY_DIR}/android/platform/arm64-v8a/lib/libboost_system.a
		${CMAKE_BINARY_DIR}/android/platform/arm64-v8a/lib/libboost_filesystem.a
		${CMAKE_BINARY_DIR}/android/platform/x86/lib/libboost_system.a
		${CMAKE_BINARY_DIR}/android/platform/x86/lib/libboost_filesystem.a
		${CMAKE_BINARY_DIR}/android/platform/x86_64/lib/libboost_system.a
		${CMAKE_BINARY_DIR}/android/platform/x86_64/lib/libboost_filesystem.a
)

Keep in mind there's a few things in here specific to my project and I'm only checking for a few libraries that I need, but hopefully you can use this as reference.

Kagetsuki avatar Jul 05 '20 07:07 Kagetsuki

Oh ok

On Sun, 5 Jul 2020, 5:45 pm 影月 零, [email protected] wrote:

You can include ndk-build projects in CMake. There's even a toolchain file you can use at <NDK>/build/cmake/android.toolchain.cmake. Just remember you need to run a full separate CMake build for each architecture. What I do personally is split up all my dependencies into vendor/ folders and add an option variable for the architecture, then I just switch the link/header/etc. paths based on that.

As for the NDK location, if you want to use side-by-side NDK you can get the location of the current default NDK by calling Gradle from CMake with something like the following build.gradle:

buildscript { repositories { google() mavenCentral() jcenter() }

dependencies {
    classpath 'com.android.tools.build:gradle:3.5.0'
}

}

def platforms = ['armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'] def sdk_level = 29 if (project.hasProperty('ANDROID_SDK_LEVEL')) { sdk_level = project.property('ANDROID_SDK_LEVEL').toString() } def min_sdk_version = 21 if (project.hasProperty('ANDROID_MIN_SDK_VERSION')) { min_sdk_version = project.property('ANDROID_MIN_SDK_VERSION').toString() } def android_vendor_path = "./vendor" if (project.hasProperty('ANDROID_VENDOR_PATH')) { android_vendor_path = project.property('ANDROID_VENDOR_PATH').toString() }

apply plugin: 'com.android.application'

android { compileSdkVersion sdk_level defaultConfig { minSdkVersion min_sdk_version targetSdkVersion sdk_level ndk { abiFilters = platforms } compileOptions { targetCompatibility 1.8 sourceCompatibility 1.8 } }

task getNDKPath() { println(android.ndkDirectory) } }

and these lines in CMake:

Set target SDK level

set(ANDROID_TARGET_API "29")

Obtain the NDK path from the side-by-side NDK detected by Gradle

execute_process( COMMAND "gradle" "-q" "getNDKPath" OUTPUT_VARIABLE ANDROID_NDK_HOME ) string(REGEX REPLACE "\n$" "" ANDROID_NDK_HOME "${ANDROID_NDK_HOME}")

That will give you the NDK path in a CMake variable ANDROID_NDK_HOME.

If you're separating out the libraries/headers/etc with a platform prefix then you don't need the trailing library architecture information (the default build style for boost-for-android). I actually just submitted a patch to allow for "system" naming #195 https://github.com/moritz-wundke/Boost-for-Android/pull/195 . If you use this you can cut down your CMake file significantly. The build command I have looks something like this:

Set the minor version for Boost for Android (1.XX)

set(ANDROID_BOOST_MINOR_VERSION 73)

Boost

add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/android/platform/armeabi-v7a/lib/libboost_system.a ${CMAKE_BINARY_DIR}/android/platform/armeabi-v7a/lib/libboost_filesystem.a ${CMAKE_BINARY_DIR}/android/platform/arm64-v8a/lib/libboost_system.a ${CMAKE_BINARY_DIR}/android/platform/arm64-v8a/lib/libboost_filesystem.a ${CMAKE_BINARY_DIR}/android/platform/x86/lib/libboost_system.a ${CMAKE_BINARY_DIR}/android/platform/x86/lib/libboost_filesystem.a ${CMAKE_BINARY_DIR}/android/platform/x86_64/lib/libboost_system.a ${CMAKE_BINARY_DIR}/android/platform/x86_64/lib/libboost_filesystem.a

  ${CMAKE_BINARY_DIR}/android/platform/armeabi-v7a/include/boost
  ${CMAKE_BINARY_DIR}/android/platform/arm64-v8a/include/boost
  ${CMAKE_BINARY_DIR}/android/platform/x86/include/boost
  ${CMAKE_BINARY_DIR}/android/platform/x86_64/include/boost

WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/interfaces/android/vendor/Boost-for-Android COMMAND sh ./build-android.sh ${ANDROID_NDK_HOME} --layout=system --boost=1.${ANDROID_BOOST_MINOR_VERSION}.0 --prefix=${CMAKE_BINARY_DIR}/android/platform/ ) add_custom_target(android-prebuild-Boost DEPENDS ${CMAKE_BINARY_DIR}/android/platform/armeabi-v7a/lib/libboost_system.a ${CMAKE_BINARY_DIR}/android/platform/armeabi-v7a/lib/libboost_filesystem.a ${CMAKE_BINARY_DIR}/android/platform/arm64-v8a/lib/libboost_system.a ${CMAKE_BINARY_DIR}/android/platform/arm64-v8a/lib/libboost_filesystem.a ${CMAKE_BINARY_DIR}/android/platform/x86/lib/libboost_system.a ${CMAKE_BINARY_DIR}/android/platform/x86/lib/libboost_filesystem.a ${CMAKE_BINARY_DIR}/android/platform/x86_64/lib/libboost_system.a ${CMAKE_BINARY_DIR}/android/platform/x86_64/lib/libboost_filesystem.a )

Keep in mind there's a few things in here specific to my project and I'm only checking for a few libraries that I need, but hopefully you can use this as reference.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/moritz-wundke/Boost-for-Android/issues/200#issuecomment-653854100, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGLITH3V7BOSK4GKMRYT4LLR2AVSJANCNFSM4OO5HQHA .

mgood7123 avatar Jul 06 '20 04:07 mgood7123