From bccc3450179402ea0cf608171833dbc4f297056f Mon Sep 17 00:00:00 2001 From: Matteo Martincigh Date: Fri, 18 Oct 2019 14:59:19 +0100 Subject: [PATCH] Github #275 Generate versionned libraries * 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 Signed-off-by: Matteo Martincigh Change-Id: I0820094607734d283ded030e4ded0ae6f5889c86 --- Android.mk | 11 ++--------- ArmnnVersion.txt | 9 --------- CMakeLists.txt | 7 +++++++ cmake/ArmnnVersion.cmake | 20 +++++++------------- include/armnn/Version.hpp | 20 ++++++++++---------- src/armnnSerializer/CMakeLists.txt | 1 + src/armnnTfLiteParser/CMakeLists.txt | 2 ++ 7 files changed, 29 insertions(+), 41 deletions(-) delete mode 100644 ArmnnVersion.txt diff --git a/Android.mk b/Android.mk index b2a4233..81a77e2 100644 --- a/Android.mk +++ b/Android.mk @@ -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 index 82f0311..0000000 --- a/ArmnnVersion.txt +++ /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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ad2eb3..e2712dd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/cmake/ArmnnVersion.cmake b/cmake/ArmnnVersion.cmake index 239b2cc..435e6be 100644 --- a/cmake/ArmnnVersion.cmake +++ b/cmake/ArmnnVersion.cmake @@ -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}") diff --git a/include/armnn/Version.hpp b/include/armnn/Version.hpp index 150d98b..2b2aaf8 100644 --- a/include/armnn/Version.hpp +++ b/include/armnn/Version.hpp @@ -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)) diff --git a/src/armnnSerializer/CMakeLists.txt b/src/armnnSerializer/CMakeLists.txt index 225999b..ccc924e 100755 --- a/src/armnnSerializer/CMakeLists.txt +++ b/src/armnnSerializer/CMakeLists.txt @@ -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() diff --git a/src/armnnTfLiteParser/CMakeLists.txt b/src/armnnTfLiteParser/CMakeLists.txt index 17d4cf6..ae60079 100755 --- a/src/armnnTfLiteParser/CMakeLists.txt +++ b/src/armnnTfLiteParser/CMakeLists.txt @@ -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}) -- 2.7.4