Skip to content

Commit

Permalink
[onert-micro] Introduce git_version.h generation (#13558)
Browse files Browse the repository at this point in the history
This commit introduces git_version.h generation with commit hash define.

ONE-DCO-1.0-Signed-off-by: Vyacheslav Bazhenov <[email protected]>
  • Loading branch information
SlavikMIPT authored Aug 6, 2024
1 parent 04604cc commit 1a558ac
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 11 deletions.
57 changes: 46 additions & 11 deletions onert-micro/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,52 @@ endif ()
set(OM_CIRCLE_SCHEMA onert_micro_circle_schema)
set(OM_TRAININFO_SCHEMA onert_micro_traininfo_schema)


# Generate git_version.h
set(OM_GIT_VERSION_FILENAME "git_version.h")
set(OM_GIT_VERSION_TEMPLATE_FILENAME "git_version.h.in")

# Add command to generate git version header
add_custom_command(
OUTPUT
${CMAKE_CURRENT_BINARY_DIR}/gen/${OM_GIT_VERSION_FILENAME}
ALL
COMMAND
${CMAKE_COMMAND}
-D IN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${OM_GIT_VERSION_TEMPLATE_FILENAME}
-D OUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/gen/${OM_GIT_VERSION_FILENAME}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CheckGit.cmake
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
)

file(WRITE ${CMAKE_BINARY_DIR}/${OM_GIT_VERSION_FILENAME})

add_custom_target(
generate_version_header
ALL
COMMAND
${CMAKE_COMMAND}
-D IN_FILE=${CMAKE_CURRENT_SOURCE_DIR}/${OM_GIT_VERSION_TEMPLATE_FILENAME}
-D OUT_FILE=${CMAKE_CURRENT_BINARY_DIR}/gen/${OM_GIT_VERSION_FILENAME}
-P ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CheckGit.cmake
WORKING_DIRECTORY
${CMAKE_SOURCE_DIR}
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/gen/${OM_GIT_VERSION_FILENAME}
)


if (NOT_BUILD_EXTERNALS)
message(STATUS "USE LOCAL EXTERNAL")

set(ONERT_MICRO_EXTERNAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/externals")
set(Flatbuffers_DIR "${ONERT_MICRO_EXTERNAL_DIR}")
set(FlatBuffersSource_DIR "${Flatbuffers_DIR}")
set (EXT_OVERLAY_DIR "${ONERT_MICRO_EXTERNAL_DIR}")
set(EXT_OVERLAY_DIR "${ONERT_MICRO_EXTERNAL_DIR}")
set(GENERATED_INCLUDE_DIR "${ONERT_MICRO_EXTERNAL_DIR}/gen")

add_subdirectory(externals)
else()
else ()
message(STATUS "DOWNLOAD AND BUILD EXTERNALS")

nnas_find_package(FlatBuffers EXACT 2.0 QUIET)
Expand Down Expand Up @@ -70,22 +105,22 @@ else()
set(Flatbuffers_DIR "${CMAKE_CURRENT_BINARY_DIR}/../../overlay/lib/cmake/flatbuffers")
set(EXT_OVERLAY_DIR "${CMAKE_CURRENT_BINARY_DIR}/../../overlay")
set(GENERATED_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/gen")
endif()
endif ()

# Choosing Kernel: reference mcu, optimized cmsisnn
if (NOT KERNELS)
message(STATUS "KERNEL variable is not defined, default reference mcu kernels will be used")
set(OM_PAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/onert-micro/include/pal/mcu")
elseif("${KERNELS}" STREQUAL "mcu")
elseif ("${KERNELS}" STREQUAL "mcu")
message(STATUS "ONERT_MICRO will use reference mcu kernels")
set(OM_PAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/onert-micro/include/pal/mcu")
elseif("${KERNELS}" STREQUAL "cmsisnn")
elseif ("${KERNELS}" STREQUAL "cmsisnn")
message(STATUS "ONERT_MICRO will use optimized cmsisnn kernels")
set(OM_PAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/onert-micro/include/pal/cmsisnn")
else()
else ()
message(STATUS "Build onert-micro: FAILED (Non-existent kernel variable. Choose one of the following options: mcu, cmsisnn)")
return()
endif()
endif ()

set(CMAKE_ARM_OPTIONS
-DTARGET_CPU=${TARGET_CPU}
Expand All @@ -109,7 +144,7 @@ set(CMAKE_ARM_OPTIONS

if (NOT_BUILD_EXTERNALS)
list(APPEND CMAKE_ARM_OPTIONS "-DNOT_BUILD_EXTERNALS=ON")
else()
else ()
list(APPEND CMAKE_ARM_OPTIONS "-DNOT_BUILD_EXTERNALS=OFF")
endif ()

Expand All @@ -128,18 +163,18 @@ if (DIS_QUANT)
message(STATUS "ONERT-MICRO will not use part for QUANTIZED models")
add_definitions(-DDIS_QUANT)
list(APPEND CMAKE_ARM_OPTIONS "-DDIS_QUANT=ON")
endif()
endif ()

if (DIS_FLOAT)
message(STATUS "ONERT-MICRO will not use part for FLOAT models")
add_definitions(-DDIS_FLOAT)
list(APPEND CMAKE_ARM_OPTIONS "-DDIS_FLOAT=ON")
endif()
endif ()

if (DIS_DYN_SHAPES)
message(STATUS "ONERT-MICRO will not use dynamic shapes")
add_definitions(-DDIS_DYN_SHAPES)
endif()
endif ()

set(MICRO_ARM_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/standalone_arm")
file(MAKE_DIRECTORY "${MICRO_ARM_BUILD_DIR}")
Expand Down
19 changes: 19 additions & 0 deletions onert-micro/cmake/CheckGit.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
set(GIT_HASH "unknown")

find_package(Git QUIET)
if (GIT_FOUND)
execute_process(
COMMAND git log -1 --pretty=format:%h
OUTPUT_VARIABLE GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
endif ()

message(STATUS "Git hash is ${GIT_HASH}")

configure_file(
${IN_FILE}
${OUT_FILE}
@ONLY
)
19 changes: 19 additions & 0 deletions onert-micro/git_version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2024 Samsung Electronics Co., Ltd. All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef GIT_VERSION_H
#define GIT_VERSION_H
#define GIT_HASH "@GIT_HASH@"
#endif // GIT_VERSION_H

0 comments on commit 1a558ac

Please sign in to comment.