I have a crossplatform library with cmake based build script. Since cmake support for android is available now (https://developer.android.com/studio/projects/add-native-code.html), I plan to move ndk-build makefiles to the trash.
I've tested find_package(ZLIB REQUIRED)
and it working well, because zlib headers and library itself is available for all ABI's in NDK sysroot.
So, I can add any custom argument to cmake cmdline per flavor or build type:
buildTypes {
release {
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
externalNativeBuild {
cmake {
arguments "-DMYLIB_ENABLE_PROGUARD=ON"
}
}
}
debug {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
externalNativeBuild {
cmake {
arguments "-DMYLIB_ENABLE_PROGUARD=OFF"
}
}
}
}
My issue is in ability to set CMAKE_PREFIX_PATH
per ABI to find external static/shared libs via FindPackage.
Generally, I can use find_library
and include_directories
in conjunction with ${ANDROID_ABI}
in cmake script itself, but I already have working script with multiple platform support, I don't wan't to add dirty code, because there is the clean way (find_package + CMAKE_PREFIX_PATH).
Thank you all for your time!
This is not something that we currently support. I think it should be possible though. I opened b.android.com/225884 to track it.
if you are just after ABI you can do things like
if(${ANDROID_ABI} STREQUAL "x86_64")
# ABI xx
endif()
This works very well and does not feel like a hack. I use it for building OpenSSL (complete usage here: https://github.com/schwabe/platform_external_openssl/blob/icsopenvpn/openssl.cmake)
If you need really flavours... I came up with this super ugly hack for flavours:
cmake
# Super hacky way to determine if flavour is normal
# cmake is called with the DCMAKE_LIBRARY_OUTPUT_DIRECTORY that includes the flavour (and archtecture)
#-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/arne/software/icsopenvpn/main/build/intermediates/cmake/normal/debug/obj/arm64-v8a
if (${CMAKE_LIBRARY_OUTPUT_DIRECTORY} MATCHES "build/intermediates/cmake/.*normal.*/")
# Flavour specific
endif()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With