KUDU-3474: Add zlib as dependency of libunwind for ARM

On ARM, libunwind includes support for compressed
.debug_info sections if zlib is available during
compilation. This means that libunwind can require zlib
at link time, but only for ARM architecture.

This modifies the build to add a zlib dependency for
libunwind if the architecture is ARM. It also reorders
the thirdparty build so that zlib is built before
libunwind. This is not strictly necessary, but it means
that libunwind would consistently have support for
compressed .debug_info sections on ARM. This does not
impact x86_64.

Testing:
 - Ran an ARM build on Ubuntu 20.04

Change-Id: Iee87b908a5771c2bd7c1a653504a1449d0792280
Reviewed-on: http://gerrit.cloudera.org:8080/19846
Reviewed-by: Alexey Serbin <alexey@apache.org>
Tested-by: Alexey Serbin <alexey@apache.org>
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 91bd2fe..cf476d6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -984,11 +984,17 @@
 ##
 ## Doesn't build on OSX.
 if (NOT APPLE)
+  set(LIBUNWIND_DEPS)
+  # On ARM, libunwind takes a dependency on zlib
+  if("${ARCH_NAME}" MATCHES "aarch64")
+    set(LIBUNWIND_DEPS zlib)
+  endif()
   find_package(LibUnwind REQUIRED)
   include_directories(SYSTEM ${UNWIND_INCLUDE_DIR})
   ADD_THIRDPARTY_LIB(unwind
     STATIC_LIB "${UNWIND_STATIC_LIB}"
-    SHARED_LIB "${UNWIND_SHARED_LIB}")
+    SHARED_LIB "${UNWIND_SHARED_LIB}"
+    DEPS "${LIBUNWIND_DEPS}")
   list(APPEND KUDU_BASE_LIBS unwind)
 endif()
 
diff --git a/thirdparty/build-thirdparty.sh b/thirdparty/build-thirdparty.sh
index b53e151..937beed 100755
--- a/thirdparty/build-thirdparty.sh
+++ b/thirdparty/build-thirdparty.sh
@@ -313,14 +313,15 @@
 EXTRA_CFLAGS="-g $EXTRA_CFLAGS"
 EXTRA_CXXFLAGS="-g $EXTRA_CXXFLAGS"
 
-if [ -n "$OS_LINUX" ] && [ -n "$F_UNINSTRUMENTED" -o -n "$F_LIBUNWIND" ]; then
-  build_libunwind
-fi
-
 if [ -n "$F_UNINSTRUMENTED" -o -n "$F_ZLIB" ]; then
   build_zlib
 fi
 
+# Put this after zlib to allow ARM builds to pick up compressed .debug_info support
+if [ -n "$OS_LINUX" ] && [ -n "$F_UNINSTRUMENTED" -o -n "$F_LIBUNWIND" ]; then
+  build_libunwind
+fi
+
 if [ -n "$F_UNINSTRUMENTED" -o -n "$F_LZ4" ]; then
   build_lz4
 fi