Skip to content

Commit fc25036

Browse files
committed
version: creating ncs_version.h with input from VERSION.
This commit generates a ncs_version.h which can be included in source code. version.h is generated from version.h.in with data from VERSION. Signed-off-by: Torsten Rasmussen <Torsten.Rasmussen@nordicsemi.no>
1 parent 36ee1c5 commit fc25036

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
set(NRF_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "NCS root directory")
99

1010
include(cmake/extensions.cmake)
11+
include(cmake/version.cmake)
1112
include(cmake/multi_image.cmake)
1213
include(cmake/reports.cmake)
1314

CODEOWNERS

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
# Root folder
88
/VERSION @carlescufi @tejlmand
9+
/ncs_version.h.in @carlescufi @tejlmand
910
/CODEOWNERS @carlescufi
1011
/LICENSE @carlescufi
1112
/README.rst @carlescufi

cmake/version.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
math(EXPR NCS_VERSION_CODE "(${NCS_VERSION_MAJOR} << 16) + (${NCS_VERSION_MINOR} << 8) + (${NCS_VERSION_PATCH})")
2+
3+
# to_hex is made available by ${ZEPHYR_BASE}/cmake/hex.cmake
4+
to_hex(${NCS_VERSION_CODE} NCS_VERSION_NUMBER)
5+
6+
configure_file(${NRF_DIR}/ncs_version.h.in ${ZEPHYR_BINARY_DIR}/include/generated/ncs_version.h)

ncs_version.h.in

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef _NCS_VERSION_H_
2+
#define _NCS_VERSION_H_
3+
4+
#cmakedefine NCS_VERSION_CODE @NCS_VERSION_CODE@
5+
#define NCS_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
6+
7+
#define NCS_VERSION_NUMBER @NCS_VERSION_NUMBER@
8+
#define NCS_VERSION_MAJOR @NCS_VERSION_MAJOR@
9+
#define NCS_VERSION_MINOR @NCS_VERSION_MINOR@
10+
#define NCS_PATCHLEVEL @NCS_VERSION_PATCH@
11+
#define NCS_VERSION_STRING "@NCS_VERSION@"
12+
13+
#endif /* _NCS_VERSION_H_ */

share/ncs-package/cmake/NcsConfig.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ get_filename_component(NRF_DIR ${CMAKE_CURRENT_LIST_DIR}/${NRF_RELATIVE_DIR} ABS
1010
get_filename_component(NCS_DIR ${CMAKE_CURRENT_LIST_DIR}/${NCS_RELATIVE_DIR} ABSOLUTE)
1111

1212
file(STRINGS ${NRF_DIR}/VERSION NCS_VERSION LIMIT_COUNT 1 LENGTH_MINIMUM 5)
13+
string(REGEX MATCH "([^\.]*)\.([^\.]*)\.([^-]*)[-]?(.*)" OUT_VAR ${NCS_VERSION})
14+
15+
set(NCS_VERSION_MAJOR ${CMAKE_MATCH_1})
16+
set(NCS_VERSION_MINOR ${CMAKE_MATCH_2})
17+
set(NCS_VERSION_PATCH ${CMAKE_MATCH_3})
18+
set(NCS_VERSION_EXTRA ${CMAKE_MATCH_4})
1319

1420
if(NOT NO_BOILERPLATE)
1521
if(NCS_TOOLCHAIN_VERSION)

0 commit comments

Comments
 (0)