Improve reusability of code that is defined out by cmake build paths

 * Added new ARMNN_STUB_PROFILING and ARMNN_DISABLE_DYNAMIC_BACKEND
   defines to replace BUILD_BARE_METAL and BUILD_EXECUTE_NETWORK_STATIC
 * Add new CMake variables to disable sample apps and dynamic backends
 * Improve BUILD_SHARED_LIBS CMake variable
 * Add new archive output location to various libraries so that the
   static libraries appear in the same location as the shared libraries
 * Fixes for bare metal build
 * Add ARMNN_DISABLE_FILE_SYSTEM defines to missing locations

Signed-off-by: Ryan OShea <ryan.oshea3@arm.com>
Change-Id: I1db9a8f483e7134bd261294b35240cf21b150d45
diff --git a/CMakeLists.txt b/CMakeLists.txt
index edb1485..a20543b 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -56,12 +56,15 @@
 
 add_subdirectory(profiling/common/src)
 add_subdirectory(profiling/client/src)
-
-add_subdirectory(samples)
+if(ARMNN_SAMPLE_APPS_ENABLED)
+    add_subdirectory(samples)
+endif()
 add_subdirectory(src/armnnTfLiteParser)
 add_subdirectory(src/armnnSerializer)
 add_subdirectory(src/armnnDeserializer)
-add_subdirectory(src/armnnTestUtils)
+if(BUILD_UNIT_TESTS)
+    add_subdirectory(src/armnnTestUtils)
+endif()
 
 if (BUILD_TESTS)
     add_subdirectory(tests)
@@ -456,14 +459,10 @@
     add_definitions(-DARMNN_TFLITE_OPAQUE_DELEGATE)
 endif()
 
-if(BUILD_BARE_METAL OR EXECUTE_NETWORK_STATIC)
-    add_library_ex(armnn STATIC ${armnn_sources})
+if (BUILD_SHARED_LIBS)
+    add_library_ex(armnn SHARED ${armnn_sources})
 else()
-    if (BUILD_SHARED_LIBS)
-        add_library_ex(armnn SHARED ${armnn_sources})
-    else()
-        add_library(armnn ${armnn_sources})
-    endif()
+    add_library(armnn STATIC ${armnn_sources})
 endif()
 
 target_compile_definitions(armnn PRIVATE "ARMNN_COMPILING_DLL")
diff --git a/cmake/GlobalConfig.cmake b/cmake/GlobalConfig.cmake
index 3337f41..2d97899 100644
--- a/cmake/GlobalConfig.cmake
+++ b/cmake/GlobalConfig.cmake
@@ -7,6 +7,7 @@
 option(BUILD_ONNX_PARSER "Build Onnx parser" OFF)
 option(BUILD_UNIT_TESTS "Build unit tests" ON)
 option(BUILD_TESTS "Build test applications" OFF)
+option(ARMNN_SAMPLE_APPS_ENABLED "Build Sample ArmNN Applications" ON)
 option(BUILD_FOR_COVERAGE "Use no optimization and output .gcno and .gcda files" OFF)
 option(ARMCOMPUTENEON "Build with ARM Compute NEON support" OFF)
 option(ARMCOMPUTECL "Build with ARM Compute OpenCL support" OFF)
@@ -56,7 +57,11 @@
                                 BUILD_TIMELINE_DECODER=0
                                 BUILD_BASE_PIPE_SERVER=0
                                 BUILD_UNIT_TESTS=0
-                                BUILD_GATORD_MOCK=0" OFF)
+                                ARMNN_SAMPLE_APPS_ENABLED=0
+                                BUILD_SHARED_LIBS=0
+                                BUILD_GATORD_MOCK=0
+                                HEAP_PROFILING=0
+                                LEAK_CHECKING=0" OFF)
 
 if(BUILD_ARMNN_TFLITE_DELEGATE)
     message(BUILD_ARMNN_TFLITE_DELEGATE option is deprecated, it will be removed in 24.02, please use BUILD_CLASSIC_DELEGATE instead)
@@ -160,16 +165,23 @@
 
 if(EXECUTE_NETWORK_STATIC)
     add_definitions(-DARMNN_DISABLE_SOCKETS
-                    -DBUILD_SHARED_LIBS=0
-                    -DARMNN_EXECUTE_NETWORK_STATIC)
+                    -DARMNN_STUB_PROFILING
+                    -DARMNN_DISABLE_DYNAMIC_BACKENDS)
+    set(ARMNN_SAMPLE_APPS_ENABLED 0)
+    set(DISABLE_DYNAMIC_BACKENDS 1)
+    set(BUILD_SHARED_LIBS  0)
 endif()
 
 if(BUILD_BARE_METAL)
     add_definitions(-DARMNN_BUILD_BARE_METAL
-            -DARMNN_DISABLE_FILESYSTEM
-            -DARMNN_DISABLE_PROCESSES
-            -DARMNN_DISABLE_THREADS
-            -DARMNN_DISABLE_SOCKETS)
+                    -DARMNN_DISABLE_FILESYSTEM
+                    -DARMNN_DISABLE_PROCESSES
+                    -DARMNN_DISABLE_THREADS
+                    -DARMNN_DISABLE_SOCKETS
+                    -DARMNN_STUB_PROFILING
+                    -DARMNN_DISABLE_DYNAMIC_BACKENDS)
+    set(DISABLE_DYNAMIC_BACKENDS 1)
+    set(BUILD_SHARED_LIBS 0)
 endif()
 
 if (NOT BUILD_PIPE_ONLY)
@@ -452,7 +464,6 @@
     add_definitions(-DARMNN_STREAMLINE_ENABLED)
 endif()
 
-if(NOT BUILD_BARE_METAL AND NOT EXECUTE_NETWORK_STATIC)
 if(HEAP_PROFILING OR LEAK_CHECKING)
     find_path(HEAP_PROFILER_INCLUDE gperftools/heap-profiler.h
             PATHS ${GPERFTOOLS_ROOT}/include
@@ -472,8 +483,8 @@
     endif()
 else()
     # Valgrind only works with gperftools version number <= 2.4
-    CHECK_INCLUDE_FILE(valgrind/memcheck.h VALGRIND_FOUND)
-endif()
+    include(CheckIncludeFiles)
+    CHECK_INCLUDE_FILES("valgrind/memcheck.h" VALGRIND_FOUND)
 endif()
 
 if(NOT BUILD_TF_LITE_PARSER)
diff --git a/profiling/client/src/ProfilingService.cpp b/profiling/client/src/ProfilingService.cpp
index 37f0de9..8dbe12c 100644
--- a/profiling/client/src/ProfilingService.cpp
+++ b/profiling/client/src/ProfilingService.cpp
@@ -10,7 +10,7 @@
 #include <common/include/ProfilingGuid.hpp>
 #include <common/include/SocketConnectionException.hpp>
 
-#if defined(ARMNN_BUILD_BARE_METAL) || defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if defined(ARMNN_STUB_PROFILING)
 #include <common/include/IgnoreUnused.hpp>
 #endif
 
@@ -26,7 +26,7 @@
 void ProfilingService::ResetExternalProfilingOptions(const arm::pipe::ProfilingOptions& options,
                                                      bool resetProfilingService)
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     // Update the profiling options
     m_Options = options;
     m_TimelineReporting = options.m_TimelineEnabled;
@@ -41,23 +41,23 @@
 #else
     IgnoreUnused(options);
     IgnoreUnused(resetProfilingService);
-#endif // ARMNN_BUILD_BARE_METAL || ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 bool ProfilingService::IsProfilingEnabled() const
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     return m_Options.m_EnableProfiling;
 #else
     return false;
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 ProfilingState ProfilingService::ConfigureProfilingService(
         const ProfilingOptions& options,
         bool resetProfilingService)
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     ResetExternalProfilingOptions(options, resetProfilingService);
     ProfilingState currentState = m_StateMachine.GetCurrentState();
     if (options.m_EnableProfiling)
@@ -106,12 +106,12 @@
     IgnoreUnused(options);
     IgnoreUnused(resetProfilingService);
     return ProfilingState::Uninitialised;
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 void ProfilingService::Update()
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     if (!m_Options.m_EnableProfiling)
     {
         // Don't run if profiling is disabled
@@ -189,12 +189,12 @@
         throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}",
                                             static_cast<int>(currentState)));
     }
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 void ProfilingService::Disconnect()
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     ProfilingState currentState = m_StateMachine.GetCurrentState();
     switch (currentState)
     {
@@ -211,7 +211,7 @@
         throw arm::pipe::ProfilingException(fmt::format("Unknown profiling service state: {}",
                                                         static_cast<int>(currentState)));
     }
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 // Store a profiling context returned from a backend that support profiling, and register its counters
@@ -219,7 +219,7 @@
     const std::string& backendId,
     std::shared_ptr<IBackendProfilingContext> profilingContext)
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     ARM_PIPE_ASSERT(profilingContext != nullptr);
     // Register the backend counters
     m_MaxGlobalCounterId = profilingContext->RegisterCounters(m_MaxGlobalCounterId);
@@ -227,7 +227,7 @@
 #else
     IgnoreUnused(backendId);
     IgnoreUnused(profilingContext);
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 const ICounterDirectory& ProfilingService::GetCounterDirectory() const
 {
@@ -343,14 +343,14 @@
 
 void ProfilingService::Initialize()
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     m_Initialiser.InitialiseProfilingService(*this);
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 void ProfilingService::InitializeCounterValue(uint16_t counterUid)
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     // Increase the size of the counter index if necessary
     if (counterUid >= m_CounterIndex.size())
     {
@@ -365,12 +365,12 @@
     m_CounterIndex.at(counterUid) = counterValuePtr;
 #else
     IgnoreUnused(counterUid);
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 void ProfilingService::Reset()
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     // Stop the profiling service...
     Stop();
 
@@ -384,12 +384,12 @@
     // ...finally reset the profiling state machine
     m_StateMachine.Reset();
     m_BackendProfilingContexts.clear();
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 void ProfilingService::Stop()
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     {   // only lock when we are updating the inference completed variable
         std::unique_lock<std::mutex> lck(m_ServiceActiveMutex);
         m_ServiceActive = false;
@@ -411,24 +411,24 @@
 
     // ...then move to the "NotConnected" state
     m_StateMachine.TransitionToState(ProfilingState::NotConnected);
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 inline void ProfilingService::CheckCounterUid(uint16_t counterUid) const
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     if (!IsCounterRegistered(counterUid))
     {
         throw arm::pipe::InvalidArgumentException(fmt::format("Counter UID {} is not registered", counterUid));
     }
 #else
     IgnoreUnused(counterUid);
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 void ProfilingService::NotifyBackendsForTimelineReporting()
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     BackendProfilingContext::iterator it = m_BackendProfilingContexts.begin();
     while (it != m_BackendProfilingContexts.end())
     {
@@ -437,23 +437,23 @@
         // Increment the Iterator to point to next entry
         it++;
     }
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 void ProfilingService::NotifyProfilingServiceActive()
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     {   // only lock when we are updating the inference completed variable
         std::unique_lock<std::mutex> lck(m_ServiceActiveMutex);
         m_ServiceActive = true;
     }
     m_ServiceActiveConditionVariable.notify_one();
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 void ProfilingService::WaitForProfilingServiceActivation(unsigned int timeout)
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     std::unique_lock<std::mutex> lck(m_ServiceActiveMutex);
 
     auto start = std::chrono::high_resolution_clock::now();
@@ -475,14 +475,14 @@
     }
 #else
     IgnoreUnused(timeout);
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 ProfilingService::~ProfilingService()
 {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_STUB_PROFILING)
     Stop();
-#endif // ARMNN_BUILD_BARE_METAL && ARMNN_EXECUTE_NETWORK_STATIC
+#endif // ARMNN_STUB_PROFILING
 }
 
 } // namespace pipe
diff --git a/profiling/server/src/basePipeServer/CMakeLists.txt b/profiling/server/src/basePipeServer/CMakeLists.txt
index b5dc68c..ce957f6 100644
--- a/profiling/server/src/basePipeServer/CMakeLists.txt
+++ b/profiling/server/src/basePipeServer/CMakeLists.txt
@@ -37,6 +37,8 @@
        endif()
 
        set_target_properties(armnnBasePipeServer PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+       set_target_properties(armnnBasePipeServer PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+
        set_target_properties(armnnBasePipeServer PROPERTIES VERSION ${GENERIC_LIB_VERSION}
                                                             SOVERSION ${GENERIC_LIB_SOVERSION})
 
diff --git a/profiling/server/src/timelineDecoder/CMakeLists.txt b/profiling/server/src/timelineDecoder/CMakeLists.txt
index 4ac68a5..93513de 100644
--- a/profiling/server/src/timelineDecoder/CMakeLists.txt
+++ b/profiling/server/src/timelineDecoder/CMakeLists.txt
@@ -36,6 +36,8 @@
       endif()
 
       set_target_properties(timelineDecoder PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+      set_target_properties(timelineDecoder PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+
       set_target_properties(timelineDecoder PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
 
       install(TARGETS timelineDecoder
diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt
index e5ee711..e1b1a70 100644
--- a/samples/CMakeLists.txt
+++ b/samples/CMakeLists.txt
@@ -2,7 +2,7 @@
 # Copyright © 2018-2023 Arm Ltd and Contributors. All rights reserved.
 # SPDX-License-Identifier: MIT
 #
-if (NOT BUILD_BARE_METAL AND NOT EXECUTE_NETWORK_STATIC)
+if (NOT BUILD_BARE_METAL)
    if(BUILD_SAMPLE_APP AND ARMNNREF)
         add_executable(SimpleSample SimpleSample.cpp)
         target_link_libraries(SimpleSample armnn ${CMAKE_THREAD_LIBS_INIT})
diff --git a/src/armnn/Network.cpp b/src/armnn/Network.cpp
index a069585..b768ea8 100644
--- a/src/armnn/Network.cpp
+++ b/src/armnn/Network.cpp
@@ -1950,8 +1950,10 @@
         // Setup the output file path
         try
         {
+#if !defined(ARMNN_DISABLE_FILESYSTEM)
             auto result = armnnUtils::Filesystem::CreateDirectory("/ArmNNIntermediateLayerOutputs");
             ARMNN_LOG(info) << "Intermediate tensors will be written to: " << result;
+#endif
             Optimizer::Pass(optGraph, MakeOptimizations(InsertDebugToFileLayer()));
         }
         catch (const armnn::RuntimeException& e)
diff --git a/src/armnn/Runtime.cpp b/src/armnn/Runtime.cpp
index ff64e85..f71fad1 100644
--- a/src/armnn/Runtime.cpp
+++ b/src/armnn/Runtime.cpp
@@ -20,7 +20,7 @@
 #include <armnn/utility/PolymorphicDowncast.hpp>
 #include <armnn/utility/Timer.hpp>
 
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_DISABLE_DYNAMIC_BACKENDS)
 #include <backendsCommon/DynamicBackendUtils.hpp>
 #endif
 
@@ -337,7 +337,7 @@
         throw RuntimeException(
                 "It is not possible to enable timeline reporting without profiling being enabled");
     }
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_DISABLE_DYNAMIC_BACKENDS)
     // Load any available/compatible dynamic backend before the runtime
     // goes through the backend registry
     LoadDynamicBackends(options.m_DynamicBackendsPath);
@@ -357,7 +357,7 @@
             if (customAllocatorMapIterator != options.m_CustomAllocatorMap.end() &&
                 customAllocatorMapIterator->second == nullptr)
             {
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_DISABLE_DYNAMIC_BACKENDS)
                 // We need to manually clean up  the dynamic backends before throwing an exception.
                 DynamicBackendUtils::DeregisterDynamicBackends(m_DeviceSpec.GetDynamicBackends());
                 m_DeviceSpec.ClearDynamicBackends();
@@ -584,7 +584,7 @@
                       << std::endl;
         }
     }
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_DISABLE_DYNAMIC_BACKENDS)
     // Clear all dynamic backends.
     DynamicBackendUtils::DeregisterDynamicBackends(m_DeviceSpec.GetDynamicBackends());
     m_DeviceSpec.ClearDynamicBackends();
@@ -769,7 +769,7 @@
     loadedNetwork->RegisterDebugCallback(func);
 }
 
-#if !defined(ARMNN_BUILD_BARE_METAL) && !defined(ARMNN_EXECUTE_NETWORK_STATIC)
+#if !defined(ARMNN_DISABLE_DYNAMIC_BACKENDS)
 void RuntimeImpl::LoadDynamicBackends(const std::string& overrideBackendPath)
 {
     // Get the paths where to load the dynamic backends from
diff --git a/src/armnnDeserializer/CMakeLists.txt b/src/armnnDeserializer/CMakeLists.txt
index 630eb37..e772358 100755
--- a/src/armnnDeserializer/CMakeLists.txt
+++ b/src/armnnDeserializer/CMakeLists.txt
@@ -29,12 +29,17 @@
             Deserializer.hpp
             Deserializer.cpp
         )
-
+if(BUILD_SHARED_LIBS)
     add_library_ex(armnnDeserializer SHARED ${armnn_deserializer_sources})
+else()
+    add_library_ex(armnnDeserializer STATIC ${armnn_deserializer_sources})
+endif()
 
     include_directories(SYSTEM "${FLATBUFFERS_INCLUDE_PATH}")
 
     set_target_properties(armnnDeserializer PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+    set_target_properties(armnnDeserializer PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+
     target_include_directories(armnnDeserializer PRIVATE ../armnn)
     target_include_directories(armnnDeserializer PRIVATE ../armnnUtils)
     target_include_directories(armnnDeserializer PRIVATE ../../generated)
diff --git a/src/armnnSerializer/CMakeLists.txt b/src/armnnSerializer/CMakeLists.txt
index 01c51e6..20faae9 100755
--- a/src/armnnSerializer/CMakeLists.txt
+++ b/src/armnnSerializer/CMakeLists.txt
@@ -36,28 +36,30 @@
         ../armnnDeserializer/Deserializer.cpp
         )
 
-    if(BUILD_BARE_METAL OR EXECUTE_NETWORK_STATIC)
-        add_library_ex(armnnSerializer STATIC ${armnn_serializer_sources})
-    else()
+    include_directories(SYSTEM "${FLATBUFFERS_INCLUDE_PATH}")
+
+    if(BUILD_SHARED_LIBS)
         # We're going to export both a STATIC library and a SHARED library here.
         # In some instances it's easier to include the serializer directly into
         # the target executable or library rather than have yet another .so.
         add_library(armnnSerializer-static STATIC ${armnn_serializer_sources})
         add_library_ex(armnnSerializer SHARED ${armnn_serializer_sources})
-    endif()
 
-    include_directories(SYSTEM "${FLATBUFFERS_INCLUDE_PATH}")
-
-    set_target_properties(armnnSerializer PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
-    target_include_directories(armnnSerializer PRIVATE ../armnn)
-    target_include_directories(armnnSerializer PRIVATE ../armnnUtils)
-    target_include_directories(armnnSerializer PRIVATE ../../generated)
-    if (NOT BARE_METAL AND NOT EXECUTE_NETWORK_STATIC)
         target_include_directories(armnnSerializer-static PRIVATE ../armnn)
         target_include_directories(armnnSerializer-static PRIVATE ../armnnUtils)
         target_include_directories(armnnSerializer-static PRIVATE ../../generated)
+
+        set_target_properties(armnnSerializer PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+        set_target_properties(armnnSerializer-static PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+    else()
+        add_library_ex(armnnSerializer STATIC ${armnn_serializer_sources})
+        set_target_properties(armnnSerializer PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
     endif()
 
+    target_include_directories(armnnSerializer PRIVATE ../armnn)
+    target_include_directories(armnnSerializer PRIVATE ../armnnUtils)
+    target_include_directories(armnnSerializer PRIVATE ../../generated)
+
     list(APPEND armnn_serializer_sources
         ArmnnSchema_generated.h
         )
@@ -66,7 +68,7 @@
     target_include_directories(armnnSerializer SYSTEM PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
 
     target_link_libraries(armnnSerializer armnn ${FLATBUFFERS_LIBRARY})
-    if (NOT BARE_METAL AND NOT EXECUTE_NETWORK_STATIC)
+    if (BUILD_SHARED_LIBS)
         install(TARGETS armnnSerializer-static
                 EXPORT  armnn-targets
                 LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
diff --git a/src/armnnTestUtils/CMakeLists.txt b/src/armnnTestUtils/CMakeLists.txt
index a4333cf..b2f3124 100755
--- a/src/armnnTestUtils/CMakeLists.txt
+++ b/src/armnnTestUtils/CMakeLists.txt
@@ -31,23 +31,20 @@
         TestUtils.hpp
         )
 
-if(NOT BUILD_BARE_METAL AND NOT EXECUTE_NETWORK_STATIC)
 list(APPEND armnnTestUtils_sources
         UnitTests.cpp
         UnitTests.hpp
         )
-endif()
 
-
-if(BUILD_BARE_METAL)
-    add_library_ex(armnnTestUtils STATIC ${armnnTestUtils_sources})
-elseif(EXECUTE_NETWORK_STATIC)
-    add_library_ex(armnnTestUtils OBJECT ${armnnTestUtils_sources})
-else()
+if(BUILD_SHARED_LIBS)
     add_library_ex(armnnTestUtils SHARED ${armnnTestUtils_sources})
+else()
+    add_library_ex(armnnTestUtils STATIC ${armnnTestUtils_sources})
 endif()
 
 set_target_properties(armnnTestUtils PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+set_target_properties(armnnTestUtils PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+
 
 target_include_directories(armnnTestUtils
         PUBLIC
diff --git a/src/armnnTfLiteParser/CMakeLists.txt b/src/armnnTfLiteParser/CMakeLists.txt
index 6096d1b..782aa1c 100755
--- a/src/armnnTfLiteParser/CMakeLists.txt
+++ b/src/armnnTfLiteParser/CMakeLists.txt
@@ -11,14 +11,15 @@
         TfLiteParser.cpp
         )
 
-    if(EXECUTE_NETWORK_STATIC)
-        add_library_ex(armnnTfLiteParser OBJECT ${armnn_tf_lite_parser_sources})
-    else()
+    if(BUILD_SHARED_LIBS)
         add_library_ex(armnnTfLiteParser SHARED ${armnn_tf_lite_parser_sources})
+    else()
+        add_library_ex(armnnTfLiteParser STATIC ${armnn_tf_lite_parser_sources})
     endif()
 
     include_directories(SYSTEM "${FLATBUFFERS_INCLUDE_PATH}")
     set_target_properties(armnnTfLiteParser PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+    set_target_properties(armnnTfLiteParser PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
     target_include_directories(armnnTfLiteParser PRIVATE ../armnn)
     target_include_directories(armnnTfLiteParser PRIVATE ../armnnUtils)
     target_include_directories(armnnTfLiteParser SYSTEM PRIVATE "${TF_LITE_SCHEMA_INCLUDE_PATH}")
@@ -66,7 +67,6 @@
     endif()
 
     set_target_properties(armnnTfLiteParser PROPERTIES VERSION ${TFLITE_PARSER_LIB_VERSION} SOVERSION ${TFLITE_PARSER_LIB_SOVERSION} )
-
     install(TARGETS armnnTfLiteParser
             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
diff --git a/src/backends/backends.cmake b/src/backends/backends.cmake
index aca3b63..98af271 100644
--- a/src/backends/backends.cmake
+++ b/src/backends/backends.cmake
@@ -19,11 +19,12 @@
     message(STATUS "Including backend into the build: ${includeFile}")
     include(${includeFile})
 endforeach()
-
-# parse dynamic backend sub-directories
-file(GLOB dynamicBackendDirs ${PROJECT_SOURCE_DIR}/src/backends/dynamic/*)
-foreach(dynamicBackendDir ${dynamicBackendDirs})
-    if (EXISTS ${dynamicBackendDir} AND IS_DIRECTORY ${dynamicBackendDir})
-        add_subdirectory(${dynamicBackendDir})
-    endif()
-endforeach()
+if(NOT DISABLE_DYNAMIC_BACKENDS)
+    # parse dynamic backend sub-directories
+    file(GLOB dynamicBackendDirs ${PROJECT_SOURCE_DIR}/src/backends/dynamic/*)
+    foreach(dynamicBackendDir ${dynamicBackendDirs})
+        if (EXISTS ${dynamicBackendDir} AND IS_DIRECTORY ${dynamicBackendDir})
+            add_subdirectory(${dynamicBackendDir})
+        endif()
+    endforeach()
+endif()
diff --git a/src/backends/backendsCommon/CMakeLists.txt b/src/backends/backendsCommon/CMakeLists.txt
index 28ff205..977067b 100644
--- a/src/backends/backendsCommon/CMakeLists.txt
+++ b/src/backends/backendsCommon/CMakeLists.txt
@@ -3,7 +3,7 @@
 # SPDX-License-Identifier: MIT
 #
 
-if(NOT BUILD_BARE_METAL AND NOT EXECUTE_NETWORK_STATIC)
+if(NOT DISABLE_DYNAMIC_BACKENDS)
 list(APPEND armnnBackendsCommon_sources
     DynamicBackend.cpp
     DynamicBackend.hpp
diff --git a/src/backends/dynamic/reference/CMakeLists.txt b/src/backends/dynamic/reference/CMakeLists.txt
index fe87528..acf5338 100644
--- a/src/backends/dynamic/reference/CMakeLists.txt
+++ b/src/backends/dynamic/reference/CMakeLists.txt
@@ -3,7 +3,6 @@
 # SPDX-License-Identifier: MIT
 #
 
-if((NOT BUILD_BARE_METAL) AND (NOT EXECUTE_NETWORK_STATIC))
 
 # File needed to wrap the existing backend into a dynamic one
 list(APPEND armnnRefDynamicBackend_sources
@@ -32,6 +31,3 @@
 target_include_directories(Arm_CpuRef_backend PRIVATE ${PROJECT_SOURCE_DIR}/profiling/client/include)
 set_target_properties(Arm_CpuRef_backend PROPERTIES PREFIX "")
 target_link_libraries(Arm_CpuRef_backend armnn)
-
-# BUILD_BARE_METAL && EXECUTE_NETWORK_STATIC
-endif()
diff --git a/src/backends/reference/workloads/Debug.cpp b/src/backends/reference/workloads/Debug.cpp
index f4f9792..50aecc8 100644
--- a/src/backends/reference/workloads/Debug.cpp
+++ b/src/backends/reference/workloads/Debug.cpp
@@ -103,10 +103,12 @@
 {
     if (outputsToFile)
     {
+#if !defined(ARMNN_DISABLE_FILESYSTEM)
         fs::path tmpDir = fs::temp_directory_path();
         std::ofstream out(tmpDir.generic_string() + "/ArmNNIntermediateLayerOutputs/" + layerName + ".numpy");
         PrintOutput<T>(inputInfo, inputData, guid, layerName, slotIndex, out);
         out.close();
+#endif
     }
     else
     {
diff --git a/src/timelineDecoder/CMakeLists.txt b/src/timelineDecoder/CMakeLists.txt
index 3aabf5b..0f15771 100644
--- a/src/timelineDecoder/CMakeLists.txt
+++ b/src/timelineDecoder/CMakeLists.txt
@@ -22,6 +22,7 @@
     add_library_ex(timelineDecoderJson SHARED ${timelineDecoderJson_sources})
 
     set_target_properties(timelineDecoderJson PROPERTIES LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
+    set_target_properties(timelineDecoderJson PROPERTIES ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
     set_target_properties(timelineDecoderJson PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
 
     target_link_libraries(timelineDecoderJson armnn)