IVGCVSW-3656 Make the reference backend optional

 * Made the build of the reference backend depend on a new ARMCOMPUTEREF
   macro
 * Made the relevant targets dependent on the ref backend
 * Moved Cl and Neon static registry initializers to separate files
 * Wrapped some of the unit tests into proper ifdefs where necessary

Change-Id: I7f2c42699682630233a4c4b6aed2f005083de189
Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
diff --git a/src/backends/backendsCommon/common.mk b/src/backends/backendsCommon/common.mk
index 0ac7cfe..d7fe9b1 100644
--- a/src/backends/backendsCommon/common.mk
+++ b/src/backends/backendsCommon/common.mk
@@ -33,5 +33,9 @@
     test/CommonTestUtils.cpp \
     test/JsonPrinterTestImpl.cpp \
     test/LayerTests.cpp \
-    test/TensorCopyUtils.cpp \
+    test/TensorCopyUtils.cpp
+
+ifeq ($(ARMNN_COMPUTE_REF_ENABLED),1)
+COMMON_TEST_SOURCES += \
     test/WorkloadDataValidation.cpp
+endif # ARMNN_COMPUTE_REF_ENABLED == 1
diff --git a/src/backends/backendsCommon/test/CMakeLists.txt b/src/backends/backendsCommon/test/CMakeLists.txt
index 684b27f..d6f8a6f 100644
--- a/src/backends/backendsCommon/test/CMakeLists.txt
+++ b/src/backends/backendsCommon/test/CMakeLists.txt
@@ -37,7 +37,6 @@
     MockBackend.cpp
     MockBackend.hpp
     MockBackendId.hpp
-    OptimizedNetworkTests.cpp
     OptimizeSubgraphViewTests.cpp
     OptimizationViewsTests.cpp
     PermuteTestImpl.hpp
@@ -56,11 +55,17 @@
     StridedSliceTestImpl.hpp
     TensorCopyUtils.cpp
     TensorCopyUtils.hpp
-    WorkloadDataValidation.cpp
     WorkloadFactoryHelper.hpp
     WorkloadTestUtils.hpp
 )
 
+if (ARMCOMPUTEREF)
+    list(APPEND armnnBackendsCommonUnitTests_sources
+        OptimizedNetworkTests.cpp
+        WorkloadDataValidation.cpp
+        )
+endif()
+
 add_library(armnnBackendsCommonUnitTests OBJECT ${armnnBackendsCommonUnitTests_sources})
 target_include_directories(armnnBackendsCommonUnitTests PRIVATE ${PROJECT_SOURCE_DIR}/src/armnn)
 target_include_directories(armnnBackendsCommonUnitTests PRIVATE ${PROJECT_SOURCE_DIR}/src/armnnUtils)
diff --git a/src/backends/backendsCommon/test/DynamicBackendTests.cpp b/src/backends/backendsCommon/test/DynamicBackendTests.cpp
index e42a08a..17a99f8 100644
--- a/src/backends/backendsCommon/test/DynamicBackendTests.cpp
+++ b/src/backends/backendsCommon/test/DynamicBackendTests.cpp
@@ -61,6 +61,12 @@
 ARMNN_SIMPLE_TEST_CASE(RuntimeInvalidDynamicBackends, RuntimeInvalidDynamicBackendsTestImpl);
 ARMNN_SIMPLE_TEST_CASE(RuntimeInvalidOverridePath, RuntimeInvalidOverridePathTestImpl);
 
+#if defined(ARMCOMPUTEREF_ENABLED)
+
+// This test unit needs the reference backend, it's not available if the reference backend is not built
+
 ARMNN_SIMPLE_TEST_CASE(CreateReferenceDynamicBackend, CreateReferenceDynamicBackendTestImpl);
 
+#endif
+
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/backends/backendsCommon/test/DynamicBackendTests.hpp b/src/backends/backendsCommon/test/DynamicBackendTests.hpp
index e225124..6c093fc 100644
--- a/src/backends/backendsCommon/test/DynamicBackendTests.hpp
+++ b/src/backends/backendsCommon/test/DynamicBackendTests.hpp
@@ -1344,6 +1344,10 @@
     BOOST_TEST(supportedBackendIds.empty());
 }
 
+#if defined(ARMCOMPUTEREF_ENABLED)
+
+// This test unit needs the reference backend, it's not available if the reference backend is not built
+
 void CreateReferenceDynamicBackendTestImpl()
 {
     using namespace armnn;
@@ -1427,3 +1431,5 @@
     BOOST_TEST((workload != nullptr));
     BOOST_TEST(workload.get() == boost::polymorphic_downcast<RefConvolution2dWorkload*>(workload.get()));
 }
+
+#endif
diff --git a/src/backends/backendsCommon/test/LayerTests.cpp b/src/backends/backendsCommon/test/LayerTests.cpp
index 2201499..561e526 100644
--- a/src/backends/backendsCommon/test/LayerTests.cpp
+++ b/src/backends/backendsCommon/test/LayerTests.cpp
@@ -20,8 +20,6 @@
 #include <backendsCommon/IBackendInternal.hpp>
 #include <backendsCommon/WorkloadFactory.hpp>
 
-#include <reference/workloads/RefWorkloads.hpp>
-
 #include <algorithm>
 #include <boost/cast.hpp>
 
@@ -2088,6 +2086,10 @@
     return CopyViaSplitterTestImpl<armnn::DataType::QuantisedSymm16>(workloadFactory, memoryManager, 1.0f, 0);
 }
 
+#if defined(ARMCOMPUTEREF_ENABLED)
+
+// The LSTM test units are run only for the reference backend at the moment
+
 void LstmUtilsZeroVectorTest()
 {
     armnn::TensorInfo inputDesc({4}, armnn::DataType::Float32);
@@ -2234,6 +2236,7 @@
             vecSize, batchSize, expectedOutput);
 }
 
+#endif
 
 LayerTestResult<float, 2> LstmLayerFloat32WithCifgWithPeepholeNoProjectionTest(
     armnn::IWorkloadFactory& workloadFactory,
diff --git a/src/backends/cl/CMakeLists.txt b/src/backends/cl/CMakeLists.txt
index 36db107..ad4a15f 100644
--- a/src/backends/cl/CMakeLists.txt
+++ b/src/backends/cl/CMakeLists.txt
@@ -14,6 +14,7 @@
         ClContextControl.hpp
         ClLayerSupport.cpp
         ClLayerSupport.hpp
+        ClRegistryInitializer.cpp
         ClTensorHandle.hpp
         ClTensorHandleFactory.cpp
         ClTensorHandleFactory.hpp
diff --git a/src/backends/cl/ClBackend.cpp b/src/backends/cl/ClBackend.cpp
index 123d063..95ffbc4 100644
--- a/src/backends/cl/ClBackend.cpp
+++ b/src/backends/cl/ClBackend.cpp
@@ -25,21 +25,6 @@
 namespace armnn
 {
 
-namespace
-{
-
-static BackendRegistry::StaticRegistryInitializer g_RegisterHelper
-{
-    BackendRegistryInstance(),
-    ClBackend::GetIdStatic(),
-    []()
-    {
-        return IBackendInternalUniquePtr(new ClBackend);
-    }
-};
-
-}
-
 const BackendId& ClBackend::GetIdStatic()
 {
     static const BackendId s_Id{ClBackendId()};
diff --git a/src/backends/cl/ClRegistryInitializer.cpp b/src/backends/cl/ClRegistryInitializer.cpp
new file mode 100644
index 0000000..4d6f5f4
--- /dev/null
+++ b/src/backends/cl/ClRegistryInitializer.cpp
@@ -0,0 +1,25 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "ClBackend.hpp"
+
+#include <backendsCommon/BackendRegistry.hpp>
+
+namespace
+{
+
+using namespace armnn;
+
+static BackendRegistry::StaticRegistryInitializer g_RegisterHelper
+{
+    BackendRegistryInstance(),
+    ClBackend::GetIdStatic(),
+    []()
+    {
+        return IBackendInternalUniquePtr(new ClBackend);
+    }
+};
+
+} // Anonymous namespace
diff --git a/src/backends/cl/backend.mk b/src/backends/cl/backend.mk
index 98da871..1042004 100644
--- a/src/backends/cl/backend.mk
+++ b/src/backends/cl/backend.mk
@@ -7,7 +7,7 @@
 # in the Android build and it is picked up by the Android.mk
 # file in the root of ArmNN
 
-# The variable to enable/disable the CL backend (ARMNN_COMPUTE_CL_ENABLED) is declared in android-nn-driver/Android.mk
+# The variable to enable/disable the CL backend (ARMNN_COMPUTE_CL_ENABLED is declared in android-nn-driver/Android.mk)
 ifeq ($(ARMNN_COMPUTE_CL_ENABLED),1)
 
 # ARMNN_COMPUTE_CL_ENABLED == 1
@@ -18,6 +18,7 @@
         ClBackendContext.cpp \
         ClContextControl.cpp \
         ClLayerSupport.cpp \
+        ClRegistryInitializer.cpp \
         ClTensorHandleFactory.cpp \
         ClWorkloadFactory.cpp \
         OpenClTimer.cpp \
@@ -74,7 +75,7 @@
 # in the Android unit test build (armnn-tests) and it is picked
 # up by the Android.mk file in the root of ArmNN
 
-# The variable to enable/disable the CL backend (ARMNN_COMPUTE_CL_ENABLED) is declared in android-nn-driver/Android.mk
+# The variable to enable/disable the CL backend (ARMNN_COMPUTE_CL_ENABLED is declared in android-nn-driver/Android.mk)
 ifeq ($(ARMNN_COMPUTE_CL_ENABLED),1)
 
 # ARMNN_COMPUTE_CL_ENABLED == 1
@@ -86,11 +87,16 @@
         test/ClJsonPrinterTests.cpp \
         test/ClLayerSupportTests.cpp \
         test/ClLayerTests.cpp \
-        test/ClMemCopyTests.cpp \
         test/ClOptimizedNetworkTests.cpp \
         test/ClRuntimeTests.cpp \
         test/Fp16SupportTest.cpp \
         test/OpenClTimerTest.cpp
+
+ifeq ($(ARMNN_COMPUTE_REF_ENABLED),1)
+BACKEND_TEST_SOURCES += \
+        test/ClMemCopyTests.cpp
+endif # ARMNN_COMPUTE_REF_ENABLED == 1
+
 else
 
 # ARMNN_COMPUTE_CL_ENABLED == 0
diff --git a/src/backends/cl/test/CMakeLists.txt b/src/backends/cl/test/CMakeLists.txt
index 206cf5a..4ec5051 100644
--- a/src/backends/cl/test/CMakeLists.txt
+++ b/src/backends/cl/test/CMakeLists.txt
@@ -10,7 +10,6 @@
     ClJsonPrinterTests.cpp
     ClLayerSupportTests.cpp
     ClLayerTests.cpp
-    ClMemCopyTests.cpp
     ClOptimizedNetworkTests.cpp
     ClRuntimeTests.cpp
     ClWorkloadFactoryHelper.hpp
@@ -18,6 +17,12 @@
     OpenClTimerTest.cpp
 )
 
+if (ARMCOMPUTEREF)
+    list(APPEND armnnClBackendUnitTests_sources
+        ClMemCopyTests.cpp
+        )
+endif()
+
 add_library(armnnClBackendUnitTests OBJECT ${armnnClBackendUnitTests_sources})
 target_include_directories(armnnClBackendUnitTests PRIVATE ${PROJECT_SOURCE_DIR}/src/armnn)
 target_include_directories(armnnClBackendUnitTests PRIVATE ${PROJECT_SOURCE_DIR}/src/armnnUtils)
diff --git a/src/backends/cl/test/ClCreateWorkloadTests.cpp b/src/backends/cl/test/ClCreateWorkloadTests.cpp
index bb36504..ff9d23a 100644
--- a/src/backends/cl/test/ClCreateWorkloadTests.cpp
+++ b/src/backends/cl/test/ClCreateWorkloadTests.cpp
@@ -686,6 +686,10 @@
     BOOST_TEST(validDataPointers);
 }
 
+#if defined(ARMCOMPUTEREF_ENABLED)
+
+// This test unit needs the reference backend, it's not available if the reference backend is not built
+
 BOOST_AUTO_TEST_CASE(CreateMemCopyWorkloadsCl)
 {
     ClWorkloadFactory factory =
@@ -694,6 +698,8 @@
     CreateMemCopyWorkloads<IClTensorHandle>(factory);
 }
 
+#endif
+
 template <typename L2NormalizationWorkloadType, typename armnn::DataType DataType>
 static void ClL2NormalizationWorkloadTest(DataLayout dataLayout)
 {
diff --git a/src/backends/cl/test/ClLayerTests.cpp b/src/backends/cl/test/ClLayerTests.cpp
index 8a5435b..092aa61 100644
--- a/src/backends/cl/test/ClLayerTests.cpp
+++ b/src/backends/cl/test/ClLayerTests.cpp
@@ -13,7 +13,6 @@
 #include <cl/ClLayerSupport.hpp>
 #include <cl/ClWorkloadFactory.hpp>
 #include <cl/workloads/ClWorkloadUtils.hpp>
-#include <reference/RefWorkloadFactory.hpp>
 #include <backendsCommon/test/ActivationFixture.hpp>
 #include <backendsCommon/test/LayerTests.hpp>
 #include <backendsCommon/test/PermuteTestImpl.hpp>
@@ -463,10 +462,6 @@
 ARMNN_AUTO_TEST_CASE(Simple4dSoftmax, Simple4dSoftmaxTest, 1.0f)
 ARMNN_AUTO_TEST_CASE(Simple4dSoftmaxUint8, Simple4dSoftmaxUint8Test, 1.0f)
 
-ARMNN_COMPARE_REF_AUTO_TEST_CASE(CompareSoftmaxBeta1WithReference, CompareSoftmaxTest, 1.0f)
-ARMNN_COMPARE_REF_AUTO_TEST_CASE(CompareSoftmaxBeta2WithReference, CompareSoftmaxTest, 2.0f)
-ARMNN_COMPARE_REF_AUTO_TEST_CASE(CompareSoftmaxUint8, CompareSoftmaxUint8Test, 1.0f)
-
 // Space To Batch Nd
 ARMNN_AUTO_TEST_CASE(SpaceToBatchNdSimpleFloat32, SpaceToBatchNdSimpleFloat32Test)
 ARMNN_AUTO_TEST_CASE(SpaceToBatchNdMultiChannelsFloat32, SpaceToBatchNdMultiChannelsFloat32Test)
@@ -773,9 +768,18 @@
                      MultiChannelTransposeConvolution2dTest<DataType::QuantisedAsymm8, DataType::Signed32>,
                      DataLayout::NHWC)
 
+#if defined(ARMCOMPUTEREF_ENABLED)
+
+// The ARMNN_COMPARE_REF_AUTO_TEST_CASE and the ARMNN_COMPARE_REF_FIXTURE_TEST_CASE test units are not available
+// if the reference backend is not built
+
 // ============================================================================
 // COMPARE tests
 
+ARMNN_COMPARE_REF_AUTO_TEST_CASE(CompareSoftmaxBeta1WithReference, CompareSoftmaxTest, 1.0f)
+ARMNN_COMPARE_REF_AUTO_TEST_CASE(CompareSoftmaxBeta2WithReference, CompareSoftmaxTest, 2.0f)
+ARMNN_COMPARE_REF_AUTO_TEST_CASE(CompareSoftmaxUint8, CompareSoftmaxUint8Test, 1.0f)
+
 ARMNN_COMPARE_REF_AUTO_TEST_CASE(CompareConv2dWithReference, CompareConvolution2dTest)
 
 ARMNN_COMPARE_REF_AUTO_TEST_CASE(CompareDepthwiseConv2dWithReferenceFloat32,
@@ -851,4 +855,6 @@
 ARMNN_COMPARE_REF_FIXTURE_TEST_CASE(CompareSquareActivationWithReference, ActivationFixture,
                                     CompareActivationTest, ActivationFunction::Square, 5u)
 
+#endif
+
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/backends/dynamic/reference/CMakeLists.txt b/src/backends/dynamic/reference/CMakeLists.txt
index e9a94af..6c040ec 100644
--- a/src/backends/dynamic/reference/CMakeLists.txt
+++ b/src/backends/dynamic/reference/CMakeLists.txt
@@ -14,7 +14,8 @@
 
 # Source files of the backend, taken directly from the source tree
 file(GLOB RefBackendBaseFiles ${RefBackendPath}/*.cpp)
-set(RefBackendFiles ${RefBackendBaseFiles})
+file(GLOB RefBackendWorloadFiles ${RefBackendPath}/workloads/*.cpp)
+set(RefBackendFiles ${RefBackendBaseFiles} ${RefBackendWorloadFiles})
 
 # Remove the file that contains the static backend registration
 list(REMOVE_ITEM RefBackendFiles ${RefBackendPath}/RefRegistryInitializer.cpp)
diff --git a/src/backends/neon/CMakeLists.txt b/src/backends/neon/CMakeLists.txt
index 7464a2e..f99f1ac 100644
--- a/src/backends/neon/CMakeLists.txt
+++ b/src/backends/neon/CMakeLists.txt
@@ -12,13 +12,14 @@
         NeonInterceptorScheduler.cpp
         NeonLayerSupport.cpp
         NeonLayerSupport.hpp
-        NeonWorkloadFactory.cpp
-        NeonWorkloadFactory.hpp
+        NeonRegistryInitializer.cpp
         NeonTensorHandle.hpp
         NeonTensorHandleFactory.cpp
         NeonTensorHandleFactory.hpp
         NeonTimer.hpp
         NeonTimer.cpp
+        NeonWorkloadFactory.cpp
+        NeonWorkloadFactory.hpp
     )
 
     add_subdirectory(workloads)
diff --git a/src/backends/neon/NeonBackend.cpp b/src/backends/neon/NeonBackend.cpp
index 5df231b..60f8ba6 100644
--- a/src/backends/neon/NeonBackend.cpp
+++ b/src/backends/neon/NeonBackend.cpp
@@ -25,21 +25,6 @@
 namespace armnn
 {
 
-namespace
-{
-
-static BackendRegistry::StaticRegistryInitializer g_RegisterHelper
-{
-    BackendRegistryInstance(),
-    NeonBackend::GetIdStatic(),
-    []()
-    {
-        return IBackendInternalUniquePtr(new NeonBackend);
-    }
-};
-
-}
-
 const BackendId& NeonBackend::GetIdStatic()
 {
     static const BackendId s_Id{NeonBackendId()};
diff --git a/src/backends/neon/NeonRegistryInitializer.cpp b/src/backends/neon/NeonRegistryInitializer.cpp
new file mode 100644
index 0000000..c74acae
--- /dev/null
+++ b/src/backends/neon/NeonRegistryInitializer.cpp
@@ -0,0 +1,25 @@
+//
+// Copyright © 2017 Arm Ltd. All rights reserved.
+// SPDX-License-Identifier: MIT
+//
+
+#include "NeonBackend.hpp"
+
+#include <backendsCommon/BackendRegistry.hpp>
+
+namespace
+{
+
+using namespace armnn;
+
+static BackendRegistry::StaticRegistryInitializer g_RegisterHelper
+{
+    BackendRegistryInstance(),
+    NeonBackend::GetIdStatic(),
+    []()
+    {
+        return IBackendInternalUniquePtr(new NeonBackend);
+    }
+};
+
+} // Anonymous namespace
diff --git a/src/backends/neon/backend.mk b/src/backends/neon/backend.mk
index 9ceb843..bf7e25d 100644
--- a/src/backends/neon/backend.mk
+++ b/src/backends/neon/backend.mk
@@ -7,7 +7,7 @@
 # in the Android build and it is picked up by the Android.mk
 # file in the root of ArmNN
 
-# The variable to enable/disable the NEON backend (ARMNN_COMPUTE_NEON_ENABLED) is declared in android-nn-driver/Android.mk
+# The variable to enable/disable the NEON backend (ARMNN_COMPUTE_NEON_ENABLED is declared in android-nn-driver/Android.mk)
 ifeq ($(ARMNN_COMPUTE_NEON_ENABLED),1)
 
 # ARMNN_COMPUTE_NEON_ENABLED == 1
@@ -17,6 +17,7 @@
         NeonBackend.cpp \
         NeonInterceptorScheduler.cpp \
         NeonLayerSupport.cpp \
+        NeonRegistryInitializer.cpp \
         NeonTensorHandleFactory.cpp \
         NeonTimer.cpp \
         NeonWorkloadFactory.cpp \
@@ -71,7 +72,7 @@
 # in the Android unit test build (armnn-tests) and it is picked
 # up by the Android.mk file in the root of ArmNN
 
-# The variable to enable/disable the NEON backend (ARMNN_COMPUTE_NEON_ENABLED) is declared in android-nn-driver/Android.mk
+# The variable to enable/disable the NEON backend (ARMNN_COMPUTE_NEON_ENABLED is declared in android-nn-driver/Android.mk)
 ifeq ($(ARMNN_COMPUTE_NEON_ENABLED),1)
 
 # ARMNN_COMPUTE_NEON_ENABLED == 1
@@ -83,11 +84,15 @@
         test/NeonJsonPrinterTests.cpp \
         test/NeonLayerSupportTests.cpp \
         test/NeonLayerTests.cpp \
-        test/NeonMemCopyTests.cpp \
         test/NeonOptimizedNetworkTests.cpp \
         test/NeonRuntimeTests.cpp \
         test/NeonTimerTest.cpp
 
+ifeq ($(ARMNN_COMPUTE_REF_ENABLED),1)
+BACKEND_TEST_SOURCES += \
+        test/NeonMemCopyTests.cpp
+endif # ARMNN_COMPUTE_REF_ENABLED == 1
+
 else
 
 # ARMNN_COMPUTE_NEON_ENABLED == 0
diff --git a/src/backends/neon/test/CMakeLists.txt b/src/backends/neon/test/CMakeLists.txt
index 19512f9..87929fb 100644
--- a/src/backends/neon/test/CMakeLists.txt
+++ b/src/backends/neon/test/CMakeLists.txt
@@ -9,13 +9,18 @@
     NeonJsonPrinterTests.cpp
     NeonLayerSupportTests.cpp
     NeonLayerTests.cpp
-    NeonMemCopyTests.cpp
     NeonOptimizedNetworkTests.cpp
     NeonRuntimeTests.cpp
     NeonTimerTest.cpp
     NeonWorkloadFactoryHelper.hpp
 )
 
+if (ARMCOMPUTEREF)
+    list(APPEND armnnNeonBackendUnitTests_sources
+        NeonMemCopyTests.cpp
+        )
+endif()
+
 add_library(armnnNeonBackendUnitTests OBJECT ${armnnNeonBackendUnitTests_sources})
 target_include_directories(armnnNeonBackendUnitTests PRIVATE ${PROJECT_SOURCE_DIR}/src/armnn)
 target_include_directories(armnnNeonBackendUnitTests PRIVATE ${PROJECT_SOURCE_DIR}/src/armnnUtils)
diff --git a/src/backends/neon/test/NeonCreateWorkloadTests.cpp b/src/backends/neon/test/NeonCreateWorkloadTests.cpp
index 056bfb2..6317ac2 100644
--- a/src/backends/neon/test/NeonCreateWorkloadTests.cpp
+++ b/src/backends/neon/test/NeonCreateWorkloadTests.cpp
@@ -710,6 +710,10 @@
     BOOST_TEST(validDataPointers);
 }
 
+#if defined(ARMCOMPUTEREF_ENABLED)
+
+// This test unit needs the reference backend, it's not available if the reference backend is not built
+
 BOOST_AUTO_TEST_CASE(CreateMemCopyWorkloadsNeon)
 {
     NeonWorkloadFactory factory =
@@ -717,6 +721,8 @@
     CreateMemCopyWorkloads<IAclTensorHandle>(factory);
 }
 
+#endif
+
 template <typename L2NormalizationWorkloadType, typename armnn::DataType DataType>
 static void NeonCreateL2NormalizationWorkloadTest(DataLayout dataLayout)
 {
diff --git a/src/backends/neon/test/NeonEndToEndTests.cpp b/src/backends/neon/test/NeonEndToEndTests.cpp
index 9f94151..bee5b7e 100644
--- a/src/backends/neon/test/NeonEndToEndTests.cpp
+++ b/src/backends/neon/test/NeonEndToEndTests.cpp
@@ -25,6 +25,10 @@
     BOOST_TEST(ConstantUsageFloat32Test(defaultBackends));
 }
 
+#if defined(ARMCOMPUTEREF_ENABLED)
+
+// This test unit needs the reference backend, it's not available if the reference backend is not built
+
 BOOST_AUTO_TEST_CASE(FallbackToCpuRef)
 {
     using namespace armnn;
@@ -59,6 +63,8 @@
     BOOST_TEST(runtime->LoadNetwork(netId, std::move(optNet)) == Status::Success);
 }
 
+#endif
+
 BOOST_AUTO_TEST_CASE(NeonGreaterSimpleEndToEndTest)
 {
     const std::vector<uint8_t> expectedOutput({ 0, 0, 0, 0,  1, 1, 1, 1,
diff --git a/src/backends/neon/test/NeonLayerTests.cpp b/src/backends/neon/test/NeonLayerTests.cpp
index e795174..27f1dd2 100644
--- a/src/backends/neon/test/NeonLayerTests.cpp
+++ b/src/backends/neon/test/NeonLayerTests.cpp
@@ -848,6 +848,11 @@
                      MultiChannelTransposeConvolution2dTest<DataType::QuantisedAsymm8, DataType::Signed32>,
                      DataLayout::NHWC)
 
+#if defined(ARMCOMPUTEREF_ENABLED)
+
+// The ARMNN_COMPARE_REF_AUTO_TEST_CASE and the ARMNN_COMPARE_REF_FIXTURE_TEST_CASE test units are not available
+// if the reference backend is not built
+
 // ============================================================================
 // COMPARE tests
 
@@ -934,4 +939,7 @@
 
 ARMNN_COMPARE_REF_FIXTURE_TEST_CASE(CompareSquareActivationWithReference, ActivationFixture,
                                     CompareActivationTest, ActivationFunction::Square, 5u)
+
+#endif
+
 BOOST_AUTO_TEST_SUITE_END()
diff --git a/src/backends/reference/CMakeLists.txt b/src/backends/reference/CMakeLists.txt
index 6852ab0..ff25378 100644
--- a/src/backends/reference/CMakeLists.txt
+++ b/src/backends/reference/CMakeLists.txt
@@ -3,30 +3,39 @@
 # SPDX-License-Identifier: MIT
 #
 
-list(APPEND armnnRefBackend_sources
-    RefBackend.cpp
-    RefBackend.hpp
-    RefBackendId.hpp
-    RefTensorHandle.hpp
-    RefTensorHandle.cpp
-    RefLayerSupport.cpp
-    RefLayerSupport.hpp
-    RefMemoryManager.hpp
-    RefMemoryManager.cpp
-    RefRegistryInitializer.cpp
-    RefWorkloadFactory.cpp
-    RefWorkloadFactory.hpp
-    RefTensorHandleFactory.hpp
-    RefTensorHandleFactory.cpp
-)
+if(ARMCOMPUTEREF)
+    list(APPEND armnnRefBackend_sources
+        RefBackend.cpp
+        RefBackend.hpp
+        RefBackendId.hpp
+        RefTensorHandle.hpp
+        RefTensorHandle.cpp
+        RefLayerSupport.cpp
+        RefLayerSupport.hpp
+        RefMemoryManager.hpp
+        RefMemoryManager.cpp
+        RefRegistryInitializer.cpp
+        RefWorkloadFactory.cpp
+        RefWorkloadFactory.hpp
+        RefTensorHandleFactory.cpp
+        RefTensorHandleFactory.hpp
+    )
+
+    add_subdirectory(workloads)
+
+    if(BUILD_UNIT_TESTS)
+        add_subdirectory(test)
+    endif()
+
+else()
+    list(APPEND armnnRefBackend_sources
+        RefBackendId.hpp
+        RefLayerSupport.cpp
+        RefLayerSupport.hpp
+    )
+endif()
 
 add_library(armnnRefBackend OBJECT ${armnnRefBackend_sources})
 target_include_directories(armnnRefBackend PRIVATE ${PROJECT_SOURCE_DIR}/src/armnn)
 target_include_directories(armnnRefBackend PRIVATE ${PROJECT_SOURCE_DIR}/src/armnnUtils)
 target_include_directories(armnnRefBackend PRIVATE ${PROJECT_SOURCE_DIR}/src/backends)
-
-add_subdirectory(workloads)
-
-if(BUILD_UNIT_TESTS)
-    add_subdirectory(test)
-endif()
diff --git a/src/backends/reference/backend.cmake b/src/backends/reference/backend.cmake
index 5ae088a..e88968d 100644
--- a/src/backends/reference/backend.cmake
+++ b/src/backends/reference/backend.cmake
@@ -4,5 +4,11 @@
 #
 
 add_subdirectory(${PROJECT_SOURCE_DIR}/src/backends/reference)
-list(APPEND armnnLibraries armnnRefBackend armnnRefBackendWorkloads)
-list(APPEND armnnUnitTestLibraries armnnRefBackendUnitTests)
+list(APPEND armnnLibraries armnnRefBackend)
+
+if(ARMCOMPUTEREF)
+    list(APPEND armnnLibraries armnnRefBackendWorkloads)
+    list(APPEND armnnUnitTestLibraries armnnRefBackendUnitTests)
+else()
+    message("Reference backend is disabled")
+endif()
diff --git a/src/backends/reference/backend.mk b/src/backends/reference/backend.mk
index a8df565..13251b7 100644
--- a/src/backends/reference/backend.mk
+++ b/src/backends/reference/backend.mk
@@ -7,6 +7,12 @@
 # in the Android build and it is picked up by the Android.mk
 # file in the root of ArmNN
 
+# The variable to enable/disable the reference backend (ARMNN_COMPUTE_REF_ENABLED is declared in android-nn-driver/Android.mk)
+ifeq ($(ARMNN_COMPUTE_REF_ENABLED),1)
+
+# ARMNN_COMPUTE_REF_ENABLED == 1
+# Include the source files for the reference backend
+
 BACKEND_SOURCES := \
         RefBackend.cpp \
         RefLayerSupport.cpp \
@@ -78,11 +84,25 @@
         workloads/Softmax.cpp \
         workloads/Splitter.cpp \
         workloads/TransposeConvolution2d.cpp
+else
+
+# ARMNN_COMPUTE_REF_ENABLED == 0
+# No source file will be compiled for the reference backend
+
+BACKEND_SOURCES :=
+
+endif
 
 # BACKEND_TEST_SOURCES contains the list of files to be included
 # in the Android unit test build (armnn-tests) and it is picked
 # up by the Android.mk file in the root of ArmNN
 
+# The variable to enable/disable the CL backend (ARMNN_COMPUTE_REF_ENABLED is declared in android-nn-driver/Android.mk)
+ifeq ($(ARMNN_COMPUTE_REF_ENABLED),1)
+
+# ARMNN_COMPUTE_REF_ENABLED == 1
+# Include the source files for the CL backend tests
+
 BACKEND_TEST_SOURCES := \
         test/RefCreateWorkloadTests.cpp \
         test/RefDetectionPostProcessTests.cpp \
@@ -93,3 +113,11 @@
         test/RefMemoryManagerTests.cpp \
         test/RefOptimizedNetworkTests.cpp \
         test/RefRuntimeTests.cpp
+else
+
+# ARMNN_COMPUTE_REF_ENABLED == 0
+# No source file will be compiled for the reference backend tests
+
+BACKEND_TEST_SOURCES :=
+
+endif