Github #275 Generate versionned libraries
authorMatteo Martincigh <matteo.martincigh@arm.com>
Fri, 18 Oct 2019 13:59:19 +0000 (14:59 +0100)
committerMatteo Martincigh <matteo.martincigh@arm.com>
Fri, 18 Oct 2019 14:45:45 +0000 (15:45 +0100)
 * Improved parsing of the ArmNN's version at compile time
 * Reading the version directly from the Version.hpp file, to
   make sure not to break any build made with a different
   build system than CMake (or Ninja)
 * The version macro is set in the Version.hpp just like before,
   so setting it from the command line is no longer necessary

!android-nn-driver:2126

Signed-off-by: Guillaume Gardet <guillaume.gardet@arm.com>
Signed-off-by: Matteo Martincigh <matteo.martincigh@arm.com>
Change-Id: I0820094607734d283ded030e4ded0ae6f5889c86

Android.mk
ArmnnVersion.txt [deleted file]
CMakeLists.txt
cmake/ArmnnVersion.cmake
include/armnn/Version.hpp
src/armnnSerializer/CMakeLists.txt
src/armnnTfLiteParser/CMakeLists.txt

index b2a4233..81a77e2 100644 (file)
@@ -23,11 +23,6 @@ ARMNN_BACKEND_MAKEFILE_LOCAL_PATHS := $(wildcard $(LOCAL_PATH)/src/backends/*/ba
 ARMNN_BACKEND_MAKEFILE_PATHS := $(subst $(LOCAL_PATH),,$(ARMNN_BACKEND_MAKEFILE_LOCAL_PATHS))
 ARMNN_BACKEND_MAKEFILE_DIRS := $(subst /backend.mk,,$(ARMNN_BACKEND_MAKEFILE_PATHS))
 
-# Get ArmNN's version from file
-get_version_number = $(shell sed -n 's/.*$1  *\([0-9*]\)/\1/p' $(LOCAL_PATH)/ArmnnVersion.txt)
-ARMNN_VERSION := 20$(call get_version_number,ARMNN_MAJOR_VERSION)$(call get_version_number,ARMNN_MINOR_VERSION)$(call get_version_number,ARMNN_PATCH_VERSION)
-$(info armnn ARMNN_VERSION: $(ARMNN_VERSION))
-
 ##############
 # libarmnn.a #
 ##############
@@ -211,8 +206,7 @@ LOCAL_CFLAGS := \
         -std=$(CPP_VERSION) \
         -fexceptions \
         -Wno-unused-parameter \
-        -frtti \
-        -DARMNN_VERSION_FROM_FILE=$(ARMNN_VERSION)
+        -frtti
 
 # 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)
@@ -286,8 +280,7 @@ LOCAL_CFLAGS := \
         -std=$(CPP_VERSION) \
         -fexceptions \
         -frtti \
-        -isystem vendor/arm/android-nn-driver/boost_1_64_0 \
-        -DARMNN_VERSION_FROM_FILE=$(ARMNN_VERSION)
+        -isystem vendor/arm/android-nn-driver/boost_1_64_0
 
 # 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)
diff --git a/ArmnnVersion.txt b/ArmnnVersion.txt
deleted file mode 100644 (file)
index 82f0311..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-#
-# Copyright © 2019 Arm Ltd. All rights reserved.
-# SPDX-License-Identifier: MIT
-#
-
-# ArmNN version number components
-ARMNN_MAJOR_VERSION 19
-ARMNN_MINOR_VERSION 08
-ARMNN_PATCH_VERSION 00
index 3ad2eb3..e2712dd 100644 (file)
@@ -96,6 +96,7 @@ if(BUILD_CAFFE_PARSER)
 
     target_link_libraries(armnnCaffeParser armnn)
     target_link_libraries(armnnCaffeParser ${PROTOBUF_LIBRARIES})
+    set_target_properties(armnnCaffeParser PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION})
 
 endif()
 
@@ -120,6 +121,7 @@ if(BUILD_ONNX_PARSER)
 
     # Protobuf
     target_link_libraries(armnnOnnxParser ${PROTOBUF_LIBRARIES})
+    set_target_properties(armnnOnnxParser PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION})
 endif()
 
 if(BUILD_TF_PARSER)
@@ -143,6 +145,7 @@ if(BUILD_TF_PARSER)
 
     # Protobuf (use the specific version tensorflow wants)
     target_link_libraries(armnnTfParser ${PROTOBUF_LIBRARIES})
+    set_target_properties(armnnTfParser PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION})
 endif()
 
 if(BUILD_ARMNN_QUANTIZER AND ARMNNREF)
@@ -201,6 +204,8 @@ if(BUILD_ARMNN_QUANTIZER AND ARMNNREF)
         target_link_libraries(ArmnnQuantizer pthread)
     endif()
 
+    set_target_properties(ArmnnQuantizer PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION})
+
 endif()
 
 
@@ -545,6 +550,8 @@ if(PROFILING_BACKEND_STREAMLINE)
     target_link_libraries(armnn pthread)
 endif()
 
+set_target_properties(armnn PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION})
+
 if(BUILD_UNIT_TESTS)
     set(unittest_sources)
     list(APPEND unittest_sources
index 239b2cc..435e6be 100644 (file)
@@ -4,22 +4,16 @@
 #
 
 # Read the ArmNN version components from file
-file(READ ${CMAKE_CURRENT_LIST_DIR}/../ArmnnVersion.txt armnnVersion)
+file(READ ${CMAKE_CURRENT_LIST_DIR}/../include/armnn/Version.hpp armnnVersion)
 
 # Parse the ArmNN version components
-string(REGEX MATCH "ARMNN_MAJOR_VERSION ([0-9]*)" _ ${armnnVersion})
+string(REGEX MATCH "#define ARMNN_MAJOR_VERSION ([0-9]*)" _ ${armnnVersion})
 set(ARMNN_MAJOR_VERSION ${CMAKE_MATCH_1})
-string(REGEX MATCH "ARMNN_MINOR_VERSION ([0-9]*)" _ ${armnnVersion})
+string(REGEX MATCH "#define ARMNN_MINOR_VERSION ([0-9]*)" _ ${armnnVersion})
 set(ARMNN_MINOR_VERSION ${CMAKE_MATCH_1})
-string(REGEX MATCH "ARMNN_PATCH_VERSION ([0-9]*)" _ ${armnnVersion})
-set(ARMNN_PATCH_VERSION ${CMAKE_MATCH_1})
 
-# Put together the ArmNN version (YYYYMMPP)
-set(ARMNN_VERSION "20${ARMNN_MAJOR_VERSION}${ARMNN_MINOR_VERSION}${ARMNN_PATCH_VERSION}")
+# Define LIB version
+set(GENERIC_LIB_VERSION "${ARMNN_MAJOR_VERSION}.${ARMNN_MINOR_VERSION}")
 
-# Pass the ArmNN version to the build
-if(${CMAKE_VERSION} VERSION_LESS "3.12.0")
-    add_definitions(-DARMNN_VERSION_FROM_FILE=${ARMNN_VERSION})
-else()
-    add_compile_definitions(ARMNN_VERSION_FROM_FILE=${ARMNN_VERSION})
-endif()
+# Define LIB soversion
+set(GENERIC_LIB_SOVERSION "${ARMNN_MAJOR_VERSION}")
index 150d98b..2b2aaf8 100644 (file)
@@ -5,20 +5,20 @@
 
 #pragma once
 
-#if !defined(ARMNN_VERSION_FROM_FILE)
-#error "A valid version of ArmNN must be provided at compile time"
-#endif
-
+// Macro utils
 #define STRINGIFY_VALUE(s) STRINGIFY_MACRO(s)
 #define STRINGIFY_MACRO(s) #s
+#define CONCAT_VALUE(a, b, c) CONCAT_MACRO(a, b, c)
+#define CONCAT_MACRO(a, b, c) a ## b ## c
+
+// ArmNN version components
+#define ARMNN_MAJOR_VERSION 19
+#define ARMNN_MINOR_VERSION 08
+#define ARMNN_PATCH_VERSION 00
 
-// YYYYMMPP
+// ARMNN_VERSION: "YYYYMMPP"
 // where:
 //   YYYY = 4-digit year number
 //   MM   = 2-digit month number
 //   PP   = 2-digit patch number
-// Defined in ArmnnVersion.txt
-#define ARMNN_VERSION STRINGIFY_VALUE(ARMNN_VERSION_FROM_FILE)
-
-// Check that the provided ArmNN version is valid
-static_assert(sizeof(ARMNN_VERSION) == 9, "Invalid ArmNN version, a valid version should have exactly 8 digits");
+#define ARMNN_VERSION "20" STRINGIFY_VALUE(CONCAT_VALUE(ARMNN_MAJOR_VERSION, ARMNN_MINOR_VERSION, ARMNN_PATCH_VERSION))
index 225999b..ccc924e 100755 (executable)
@@ -43,4 +43,5 @@ if(BUILD_ARMNN_SERIALIZER)
 
     install(TARGETS armnnSerializer
             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
+    set_target_properties(armnnSerializer PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
 endif()
index 17d4cf6..ae60079 100755 (executable)
@@ -21,6 +21,8 @@ if(BUILD_TF_LITE_PARSER)
     target_link_libraries(armnnTfLiteParser ${Boost_FILESYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY})
     target_link_libraries(armnnTfLiteParser armnn ${FLATBUFFERS_LIBRARY})
 
+    set_target_properties(armnnTfLiteParser PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} )
+
     install(TARGETS armnnTfLiteParser
             LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
             RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})