forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnuttx_mkversion.cmake
114 lines (98 loc) · 4.04 KB
/
nuttx_mkversion.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# ##############################################################################
# cmake/nuttx_mkversion.cmake
#
# SPDX-License-Identifier: Apache-2.0
#
# Licensed to the Apache Software Foundation (ASF) under one or more contributor
# license agreements. See the NOTICE file distributed with this work for
# additional information regarding copyright ownership. The ASF licenses this
# file to you 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.
#
# ##############################################################################
set(VERSION_H ${CMAKE_BINARY_DIR}/include/nuttx/version.h)
if(EXISTS ${VERSION_H})
return()
endif()
execute_process(
COMMAND git -C ${NUTTX_DIR} describe --match "nuttx-*"
WORKING_DIRECTORY ${NUTTX_DIR}
ERROR_VARIABLE NUTTX_ERROR
OUTPUT_VARIABLE NUTTX_VERSION
RESULT_VARIABLE VERSION_STATUS
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${VERSION_STATUS} AND NOT ${VERSION_STATUS} EQUAL 0)
set(NUTTX_VERSION "0.0.0")
else()
string(REPLACE "-" ";" NUTTX_VERSION ${NUTTX_VERSION})
list(GET NUTTX_VERSION 1 NUTTX_VERSION)
endif()
string(REPLACE "." ";" NUTTX_CHECK_VERSION ${NUTTX_VERSION})
list(LENGTH NUTTX_CHECK_VERSION NUTTX_VERSION_LENGTH)
if(${NUTTX_VERSION_LENGTH} LESS 3)
execute_process(
COMMAND git -C ${NUTTX_DIR} -c "versionsort.suffix=-" tag --sort=v:refname
WORKING_DIRECTORY ${NUTTX_DIR}
OUTPUT_VARIABLE NUTTX_VERSION_LIST
RESULT_VARIABLE VERSION_STATUS)
if(${VERSION_STATUS} EQUAL 0)
string(REPLACE "\n" ";" NUTTX_VERSION_LIST ${NUTTX_VERSION_LIST})
foreach(version ${NUTTX_VERSION_LIST})
string(REGEX MATCH "nuttx-[0-9]+\.[0-9]+\.[0-9]+" NUTTX_CHECK_VERSION
${version})
if(NUTTX_CHECK_VERSION)
string(REPLACE "-" ";" NUTTX_VERSION ${NUTTX_CHECK_VERSION})
list(GET NUTTX_VERSION 1 NUTTX_VERSION)
endif()
endforeach()
endif()
endif()
execute_process(
COMMAND git -C ${NUTTX_DIR} log --oneline -1
WORKING_DIRECTORY ${NUTTX_DIR}
OUTPUT_VARIABLE NUTTX_VERSION_BUILD
RESULT_VARIABLE VERSION_STATUS)
if(${VERSION_STATUS} AND NOT ${VERSION_STATUS} EQUAL 0)
set(NUTTX_VERSION_BUILD)
else()
string(REPLACE " " ";" NUTTX_VERSION_BUILD ${NUTTX_VERSION_BUILD})
list(GET NUTTX_VERSION_BUILD 0 NUTTX_VERSION_BUILD)
execute_process(
COMMAND git -C ${NUTTX_DIR} diff-index --name-only HEAD
WORKING_DIRECTORY ${NUTTX_DIR}
OUTPUT_VARIABLE NUTTX_VERSION_BUILD_DIRTY)
if(NUTTX_VERSION_BUILD_DIRTY)
set(NUTTX_VERSION_BUILD ${NUTTX_VERSION_BUILD}-dirty)
endif()
endif()
file(WRITE ${VERSION_H} "/* version.h -- Autogenerated! Do not edit. */\n\n")
file(APPEND ${VERSION_H} "#ifndef __INCLUDE_NUTTX_VERSION_H\n")
file(APPEND ${VERSION_H} "#define __INCLUDE_NUTTX_VERSION_H\n\n")
file(APPEND ${VERSION_H} "#define CONFIG_VERSION_STRING \"${NUTTX_VERSION}\"\n")
string(REPLACE "." ";" NUTTX_VERSION ${NUTTX_VERSION})
list(GET NUTTX_VERSION 0 NUTTX_VERSION_MAJOR)
list(GET NUTTX_VERSION 1 NUTTX_VERSION_MINOR)
list(GET NUTTX_VERSION 2 NUTTX_VERSION_PATCH)
file(APPEND ${VERSION_H}
"#define CONFIG_VERSION_MAJOR ${NUTTX_VERSION_MAJOR}\n")
file(APPEND ${VERSION_H}
"#define CONFIG_VERSION_MINOR ${NUTTX_VERSION_MINOR}\n")
file(APPEND ${VERSION_H}
"#define CONFIG_VERSION_PATCH ${NUTTX_VERSION_PATCH}\n")
file(APPEND ${VERSION_H}
"#define CONFIG_VERSION_BUILD \"${NUTTX_VERSION_BUILD}\"\n\n")
file(
APPEND ${VERSION_H}
"#define CONFIG_VERSION ((CONFIG_VERSION_MAJOR << 16) | \\
(CONFIG_VERSION_MINOR << 8) | \\
(CONFIG_VERSION_PATCH))\n")
file(APPEND ${VERSION_H} "\n#endif /* __INCLUDE_NUTTX_VERSION_H */\n")