Can I specify cmake arguments on an ABI in gradle?

I have a cross-platform library with a layout based on a cmake script. Since cmake support for Android is now available ( https://developer.android.com/studio/projects/add-native-code.html ), I plan to move the ndk-build make files to the trash.
I tested find_package(ZLIB REQUIRED) and it works well because the zlib headers and the library itself are available for all ABIs in the sysroot NDK. Thus, I can add any custom argument to cmake cmdline for each 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 problem is the ability to set CMAKE_PREFIX_PATH for each ABI to search for external static / shared libraries through FindPackage.

As a rule, I can use find_library and include_directories in combination with ${ANDROID_ABI} in the cmake script itself, but I already have a working script with support for several platforms, I do not want to add dirty code, because there is a clean path (find_package + CMAKE_PREFIX_PATH) .

Thank you all for your time!

+6
source share
2 answers

This is not what we currently support. I think it's possible. I opened b.android.com/225884 to track it.

+5
source

if you are only after an abi, you can do things like

 if(${ANDROID_ABI} STREQUAL "x86_64") # ABI xx endif() 

This works very well and doesn't look like a hack. I use it to create OpenSSL (full use here: https://github.com/schwabe/ics-openvpn/blob/master/main/src/main/cpp/openssl.cmake )

If you really like the scents ... I came up with this super ugly taste hack:

 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() 
+1
source

Source: https://habr.com/ru/post/1011507/


All Articles