From c6d1db4b36a3f45b55bd850589f4eefd191d4d35 Mon Sep 17 00:00:00 2001 From: James Zern Date: Tue, 1 Aug 2017 18:33:50 -0700 Subject: [PATCH] fix Android standalone toolchain build add a check for cpu-features.h and rework some of the ifdef's around android + neon. for android builds with cpu-features enabled the *_neon.c files will still need to be flagged correctly (with e.g., .c.neon in Android.mk) to properly build them. BUG=webp:353 Change-Id: I905ce305af0a204e560b915d8665093a3edaceb9 --- Android.mk | 1 + CMakeLists.txt | 1 + build.gradle | 1 + configure.ac | 10 +++++++--- src/dsp/dsp.h | 12 +++++++----- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/Android.mk b/Android.mk index c17f9e66..f15823e1 100644 --- a/Android.mk +++ b/Android.mk @@ -25,6 +25,7 @@ ifneq ($(findstring armeabi-v7a, $(TARGET_ARCH_ABI)),) # specifically. NEON := c.neon USE_CPUFEATURES := yes + WEBP_CFLAGS += -DHAVE_CPU_FEATURES_H else NEON := c endif diff --git a/CMakeLists.txt b/CMakeLists.txt index 93c9c56d..b8039971 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,7 @@ if(ANDROID) set(WEBP_DEP_INCLUDE_DIRS ${WEBP_DEP_INCLUDE_DIRS} ${ANDROID_NDK}/sources/android/cpufeatures ) + add_definitions(-DHAVE_CPU_FEATURES_H) endif() ################################################################################ diff --git a/build.gradle b/build.gradle index 646ecad3..05765d38 100644 --- a/build.gradle +++ b/build.gradle @@ -84,6 +84,7 @@ model { // Check for NEON usage. if (getTargetPlatform() == "arm") { NEON = "c.neon" + cCompiler.define "HAVE_CPU_FEATURES_H" } else { NEON = "c" } diff --git a/configure.ac b/configure.ac index bb3e3114..8f435f1f 100644 --- a/configure.ac +++ b/configure.ac @@ -244,9 +244,13 @@ AS_IF([test "x$enable_neon" != "xno"], [ NEON_FLAGS=""], [AC_DEFINE(WEBP_HAVE_NEON_RTCD, [1], [Set to 1 if runtime detection of NEON is enabled])])]) - ;; - esac - AC_SUBST([NEON_FLAGS])]) + + case "$host_os" in + *android*) AC_CHECK_HEADERS([cpu-features.h]) ;; + esac + ;; + esac + AC_SUBST([NEON_FLAGS])]) dnl === CLEAR_LIBVARS([var_pfx]) dnl === Clears _{INCLUDES,LIBS}. diff --git a/src/dsp/dsp.h b/src/dsp/dsp.h index 7bc22729..6163b9c4 100644 --- a/src/dsp/dsp.h +++ b/src/dsp/dsp.h @@ -71,18 +71,20 @@ extern "C" { #define WEBP_USE_AVX2 #endif -#if defined(__ANDROID__) && defined(__ARM_ARCH_7A__) -#define WEBP_ANDROID_NEON // Android targets that might support NEON -#endif - // The intrinsics currently cause compiler errors with arm-nacl-gcc and the // inline assembly would need to be modified for use with Native Client. -#if (defined(__ARM_NEON__) || defined(WEBP_ANDROID_NEON) || \ +#if (defined(__ARM_NEON__) || \ defined(__aarch64__) || defined(WEBP_HAVE_NEON)) && \ !defined(__native_client__) #define WEBP_USE_NEON #endif +#if !defined(WEBP_USE_NEON) && defined(__ANDROID__) && \ + defined(__ARM_ARCH_7A__) && defined(HAVE_CPU_FEATURES_H) +#define WEBP_ANDROID_NEON // Android targets that may have NEON +#define WEBP_USE_NEON +#endif + #if defined(_MSC_VER) && _MSC_VER >= 1700 && defined(_M_ARM) #define WEBP_USE_NEON #define WEBP_USE_INTRINSICS