aemu: stop requiring lz4, Googletest, and perfetto-tracing-only

- Test for LZ4_VERSION_RELEASE.  That'll allow one less dependency
for those who don't need it. Nobody seems to use
CompressingStream/DecompressingStream in vulkan-cereal yet?

- Modify third-party/CMakeLists.txt for lz4, Googletest
and perfetto-tracing-only.  These should be optional dependencies
for those who want it.  In addition, we shouldn't depend on
vulkan-cereal to provide the dependencies, since vulkan-cereal
depends on hardware/google/aemu.

- This adds the optional USE_PERFETTO_TRACING flag, which can be
added if the "perfetto-tracing-only" library has been built.

   * In the next few months, perfetto itself should provide
     a C api (https://bit.ly/perfetto-c)(buganizer: 184929776).

BUG=239639751
TEST=compile

Change-Id: I0f23ef32557efd038df153429b78ae6d61aee62b
diff --git a/base/Android.bp b/base/Android.bp
index 25d7fb5..4ffebe7 100644
--- a/base/Android.bp
+++ b/base/Android.bp
@@ -42,8 +42,6 @@
         "Tracing.cpp",
         "Thread_pthread.cpp",
     ],
-    whole_static_libs: ["perfetto-tracing-only"],
-    static_libs: ["gfxstream_lz4"],
     export_header_lib_headers: ["gfxstream_renderdoc_headers"]
 }
 
diff --git a/base/CompressingStream.cpp b/base/CompressingStream.cpp
index e7d0403..39684ad 100644
--- a/base/CompressingStream.cpp
+++ b/base/CompressingStream.cpp
@@ -15,7 +15,10 @@
 #include "aemu/base/files/CompressingStream.h"
 
 #include "aemu/base/files/StreamSerializing.h"
+
+#if LZ4_VERSION_RELEASE
 #include "lz4.h"
+#endif
 
 #include <errno.h>
 
@@ -23,11 +26,17 @@
 namespace base {
 
 CompressingStream::CompressingStream(Stream& output)
-    : mOutput(output), mLzStream(LZ4_createStream()) {}
+    : mOutput(output) {
+#if LZ4_VERSION_RELEASE
+    mLzStream = reinterpret_cast<void *>(LZ4_createStream());
+#endif
+}
 
 CompressingStream::~CompressingStream() {
     saveBuffer(&mOutput, mBuffer);
+#if LZ4_VERSION_RELEASE
     LZ4_freeStream((LZ4_stream_t*)mLzStream);
+#endif
 }
 
 ssize_t CompressingStream::read(void*, size_t) {
@@ -38,13 +47,21 @@
     if (!size) {
         return 0;
     }
-    const auto outSize = LZ4_compressBound(size);
+
+    size_t outSize = 0;
+#ifdef LZ4_VERSION_RELEASE
+    outSize = LZ4_compressBound(size);
+#endif
     auto oldSize = mBuffer.size();
     mBuffer.resize_noinit(mBuffer.size() + outSize);
     const auto outBuffer = mBuffer.data() + oldSize;
-    const int written = LZ4_compress_fast_continue((LZ4_stream_t*)mLzStream,
-                                                   (const char*)buffer,
-                                                   outBuffer, size, outSize, 1);
+    int written = 0;
+#ifdef LZ4_VERSION_RELEASE
+    written = LZ4_compress_fast_continue((LZ4_stream_t*)mLzStream,
+                                         (const char*)buffer,
+                                         outBuffer, size, outSize, 1);
+#endif
+
     if (!written) {
         return -EIO;
     }
diff --git a/base/DecompressingStream.cpp b/base/DecompressingStream.cpp
index 8cc3806..8bff7b7 100644
--- a/base/DecompressingStream.cpp
+++ b/base/DecompressingStream.cpp
@@ -15,7 +15,10 @@
 #include "aemu/base/files/DecompressingStream.h"
 
 #include "aemu/base/files/StreamSerializing.h"
+
+#if LZ4_VERSION_RELEASE
 #include "lz4.h"
+#endif
 
 #include <errno.h>
 #include <cassert>
@@ -23,13 +26,17 @@
 namespace android {
 namespace base {
 
-DecompressingStream::DecompressingStream(Stream& input)
-    : mLzStream(LZ4_createStreamDecode()) {
+DecompressingStream::DecompressingStream(Stream& input) {
+#if LZ4_VERSION_RELEASE
+    mLzStream = reinterpret_cast<void *>(LZ4_createStreamDecode());
+#endif
     loadBuffer(&input, &mBuffer);
 }
 
 DecompressingStream::~DecompressingStream() {
+#if LZ4_VERSION_RELEASE
     LZ4_freeStreamDecode((LZ4_streamDecode_t*)mLzStream);
+#endif
 }
 
 ssize_t DecompressingStream::read(void* buffer, size_t size) {
@@ -38,9 +45,12 @@
     if (!size) {
         return 0;
     }
-    const int read = LZ4_decompress_fast_continue(
-            (LZ4_streamDecode_t*)mLzStream, mBuffer.data() + mBufferPos,
-            (char*)buffer, size);
+    int read = 0;
+#ifdef LZ4_VERSION_RELEASE
+    read = LZ4_decompress_fast_continue(
+           (LZ4_streamDecode_t*)mLzStream, mBuffer.data() + mBufferPos,
+           (char*)buffer, size);
+#endif
     if (!read) {
         return -EIO;
     }
diff --git a/base/Tracing.cpp b/base/Tracing.cpp
index e659d97..7f372bc 100644
--- a/base/Tracing.cpp
+++ b/base/Tracing.cpp
@@ -14,7 +14,9 @@
 // limitations under the License.
 #include "aemu/base/Tracing.h"
 
+#ifdef USE_PERFETTO_TRACING
 #include "perfetto-tracing-only.h"
+#endif
 
 #include <string>
 #include <vector>
@@ -27,23 +29,33 @@
 const bool* tracingDisabledPtr = nullptr;
 
 void initializeTracing() {
+#ifdef USE_PERFETTO_TRACING
     virtualdeviceperfetto::initialize(&tracingDisabledPtr);
+#endif
 }
 
 void enableTracing() {
+#ifdef USE_PERFETTO_TRACING
     if (virtualdeviceperfetto::queryTraceConfig().tracingDisabled) {
         virtualdeviceperfetto::enableTracing();
     }
+#endif
 }
 
 void disableTracing() {
+#ifdef USE_PERFETTO_TRACING
     if (!virtualdeviceperfetto::queryTraceConfig().tracingDisabled) {
         virtualdeviceperfetto::disableTracing();
     }
+#endif
 }
 
 bool shouldEnableTracing() {
+#ifdef USE_PERFETTO_TRACING
     return !(virtualdeviceperfetto::queryTraceConfig().tracingDisabled);
+#else
+    return false;
+#endif
 }
 
 #ifdef __cplusplus
@@ -56,31 +68,43 @@
 
 __attribute__((always_inline)) void beginTrace(const char* name) {
     if (CC_LIKELY(*tracingDisabledPtr)) return;
+#ifdef USE_PERFETTO_TRACING
     virtualdeviceperfetto::beginTrace(name);
+#endif
 }
 
 __attribute__((always_inline)) void endTrace() {
     if (CC_LIKELY(*tracingDisabledPtr)) return;
+#ifdef USE_PERFETTO_TRACING
     virtualdeviceperfetto::endTrace();
+#endif
 }
 
 __attribute__((always_inline)) void traceCounter(const char* name, int64_t value) {
     if (CC_LIKELY(*tracingDisabledPtr)) return;
+#ifdef USE_PERFETTO_TRACING
     virtualdeviceperfetto::traceCounter(name, value);
+#endif
 }
 
 ScopedTrace::ScopedTrace(const char* name) {
     if (CC_LIKELY(*tracingDisabledPtr)) return;
+#ifdef USE_PERFETTO_TRACING
     virtualdeviceperfetto::beginTrace(name);
+#endif
 }
 
 ScopedTrace::~ScopedTrace() {
     if (CC_LIKELY(*tracingDisabledPtr)) return;
+#ifdef USE_PERFETTO_TRACING
     virtualdeviceperfetto::endTrace();
+#endif
 }
 
 void setGuestTime(uint64_t t) {
+#ifdef USE_PERFETTO_TRACING
     virtualdeviceperfetto::setGuestTime(t);
+#endif
 }
 
 } // namespace base
diff --git a/third-party/CMakeLists.txt b/third-party/CMakeLists.txt
index e912020..3e3dd90 100644
--- a/third-party/CMakeLists.txt
+++ b/third-party/CMakeLists.txt
@@ -1,24 +1,18 @@
 # Build only support in Android
 
-# TODO(joshuaduong): Should copy/move these third-party dependencies from vulkan-cereal to here.
-set(VULKAN_CEREAL_PATH ${PROJECT_SOURCE_DIR}/../../../device/generic/vulkan-cereal)
 if(NOT TARGET lz4)
-    if(EXISTS ${VULKAN_CEREAL_PATH})
-        add_subdirectory(${VULKAN_CEREAL_PATH}/third-party/lz4 lz4)
-    endif()
+    #TODO(joshuaduong) -- add lz4 for those who need it
+    message(STATUS "This message does nothing")
 endif()
 
 if(NOT TARGET perfetto-tracing-only)
-    if(EXISTS ${VULKAN_CEREAL_PATH})
-        add_subdirectory(${VULKAN_CEREAL_PATH}/third-party/perfetto-tracing-only
-                         perfetto-tracing-only)
-    endif()
+    #TODO(joshuaduong) -- add perfetto-tracing-only for those who need it
+    message(STATUS "This message is a placeholder")
 endif()
 
 if(NOT TARGET gtest)
-    if(EXISTS ${VULKAN_CEREAL_PATH})
-        SET(INSTALL_GTEST OFF)
-        add_subdirectory(${VULKAN_CEREAL_PATH}/third-party/googletest
-                         googletest)
-    endif()
+    SET(INSTALL_GTEST OFF)
+    #TODO(joshuaduong) -- add ENABLE_TESTS option and use Googletest for those
+    # need it.
+    message(STATUS "This message is just a stand-in")
 endif()