Skip to content

Commit 560695d

Browse files
committed
build: move commit_id and build_info to common
As we will need these outside of OcreCore Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
1 parent 87a9379 commit 560695d

6 files changed

Lines changed: 66 additions & 45 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Thumbs.db
5454
# Generated by VS
5555
settings.json
5656

57-
src/ocre/commit_id.h
57+
src/common/include/ocre/commit_id.h
5858

5959
**/.DS_Store
6060

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ include (src/samples/demo/demo_containers.cmake)
1919
add_subdirectory(src/uthash)
2020

2121
# core
22+
add_subdirectory(src/common)
2223
add_subdirectory(src/ocre)
2324
add_subdirectory(src/runtime)
2425

src/common/CMakeLists.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# @copyright Copyright (c) contributors to Project Ocre,
2+
# which has been established as Project Ocre a Series of LF Projects, LLC
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
# Check if we are in a git repository
7+
execute_process(
8+
COMMAND git rev-parse --git-dir
9+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
10+
OUTPUT_VARIABLE GIT_DIR
11+
OUTPUT_STRIP_TRAILING_WHITESPACE
12+
ERROR_QUIET
13+
)
14+
15+
if(GIT_DIR)
16+
message(STATUS "Detected git repository. Automatic commit ID tracking is enabled.")
17+
18+
# Generate commit ID header file in source dir if we are in a git repository
19+
add_custom_command(
20+
OUTPUT include/ocre/commit_id.h
21+
COMMAND sh -c "mkdir -p ${CMAKE_CURRENT_BINARY_DIR}/include/ocre"
22+
COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > ${CMAKE_CURRENT_BINARY_DIR}/include/ocre/commit_id.h"
23+
COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> ${CMAKE_CURRENT_BINARY_DIR}/include/ocre/commit_id.h"
24+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
25+
VERBATIM
26+
DEPENDS always_rebuild
27+
)
28+
endif()
29+
30+
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ocre)
31+
32+
# Generate build info header file in binary dir for every build
33+
add_custom_command(
34+
OUTPUT include/ocre/build_info.h
35+
COMMAND sh -c "echo \"#define OCRE_BUILD_HOST_INFO \\\"$ENV{USER} @ $(uname -a)\\\"\" > include/ocre/build_info.h"
36+
COMMAND sh -c "echo \"#define OCRE_BUILD_DATE \\\"$(date +'%Y-%m-%d %H:%M:%S %Z')\\\"\" >> include/ocre/build_info.h"
37+
VERBATIM
38+
DEPENDS always_rebuild
39+
)
40+
41+
# dummy command used to make the custom commands be re-run on every build (not just configure)
42+
add_custom_command(
43+
OUTPUT always_rebuild
44+
COMMAND cmake -E echo
45+
)
46+
47+
add_library(OcreCommon INTERFACE)
48+
49+
# if we are not in a git repository, just fail automatically if we are missing commit_id.h
50+
target_sources(OcreCommon
51+
PRIVATE
52+
include/ocre/build_info.h
53+
include/ocre/commit_id.h
54+
)
55+
56+
target_include_directories(OcreCommon
57+
INTERFACE
58+
include
59+
${CMAKE_CURRENT_BINARY_DIR}/include
60+
)

src/ocre/CMakeLists.txt

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,49 +3,8 @@
33
#
44
# SPDX-License-Identifier: Apache-2.0
55

6-
# Check if we are in a git repository
7-
execute_process(
8-
COMMAND git rev-parse --git-dir
9-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
10-
OUTPUT_VARIABLE GIT_DIR
11-
OUTPUT_STRIP_TRAILING_WHITESPACE
12-
ERROR_QUIET
13-
)
14-
15-
if(GIT_DIR)
16-
message(STATUS "Detected git repository. Automatic commit ID tracking is enabled.")
17-
18-
# Generate commit ID header file in source dir if we are in a git repository
19-
add_custom_command(
20-
OUTPUT commit_id.h
21-
COMMAND sh -c "echo '/* Auto-generated file. DO NOT EDIT */' > commit_id.h"
22-
COMMAND sh -c "echo \"#define GIT_COMMIT_ID \\\"$(git describe --always --abbrev=0 --dirty)\\\"\" >> commit_id.h"
23-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
24-
VERBATIM
25-
DEPENDS always_rebuild
26-
)
27-
endif()
28-
29-
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/include/ocre)
30-
31-
# Generate build info header file in binary dir for every build
32-
add_custom_command(
33-
OUTPUT include/ocre/build_info.h
34-
COMMAND sh -c "echo \"#define OCRE_BUILD_HOST_INFO \\\"$ENV{USER} @ $(uname -a)\\\"\"" > include/ocre/build_info.h
35-
COMMAND sh -c "echo \"#define OCRE_BUILD_DATE \\\"$(date +'%Y-%m-%d %H:%M:%S %Z')\\\"\"" >> include/ocre/build_info.h
36-
VERBATIM
37-
DEPENDS always_rebuild
38-
)
39-
40-
# dummy command used to make the custom commands be re-run on every build (not just configure)
41-
add_custom_command(
42-
OUTPUT always_rebuild
43-
COMMAND cmake -E echo
44-
)
45-
466
add_library(OcreCore)
477

48-
# if we are not in a git repository, just fail automatically if we are missing commit_id.h
498
target_sources(OcreCore
509
PRIVATE
5110
container.c
@@ -54,8 +13,6 @@ target_sources(OcreCore
5413
util/rm_rf.c
5514
util/string_array.c
5615
util/unique_random_id.c
57-
commit_id.h
58-
include/ocre/build_info.h
5916
)
6017

6118
target_link_libraries(OcreCore
@@ -64,6 +21,7 @@ target_link_libraries(OcreCore
6421
OcrePlatform
6522
OcreRuntime
6623
OcreRuntimeWamr
24+
OcreCommon
6725
)
6826

6927
target_include_directories(OcreCore

src/ocre/ocre.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
#include <ocre/platform/log.h>
2121
#include <ocre/build_info.h>
2222
#include <ocre/runtime/wamr/wasip1.h>
23+
#include <ocre/commit_id.h>
2324

2425
#include "context.h"
2526
#include "util/rm_rf.h"
2627

27-
#include "commit_id.h"
2828
#include "version.h"
2929

3030
LOG_MODULE_REGISTER(ocre, CONFIG_OCRE_LOG_LEVEL);

zephyr/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,12 @@ set(CMAKE_CXX_STANDARD 17)
1818
include (wamr.cmake)
1919

2020
add_subdirectory(../src/uthash "uthash")
21+
add_subdirectory(../src/common "ocre-common")
2122
add_subdirectory(../src/ocre "ocre-core")
2223
add_subdirectory(../src/runtime "ocre-runtime")
2324
add_subdirectory(../src/runtime/wamr-wasip1 "ocre-runtime-wamr-wasip1")
2425
add_subdirectory(../src/platform/zephyr "ocre-zephyr")
26+
2527
if(CONFIG_OCRE_SHELL)
2628
message(STATUS "Shell is enabled")
2729
add_subdirectory(../src/shell "ocre-shell")

0 commit comments

Comments
 (0)