Skip to content

Commit

Permalink
version: creating ncs_version.h with input from VERSION.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tejlmand committed Oct 12, 2020
1 parent 36ee1c5 commit fc25036
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
set(NRF_DIR ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "NCS root directory")

include(cmake/extensions.cmake)
include(cmake/version.cmake)
include(cmake/multi_image.cmake)
include(cmake/reports.cmake)

Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

# Root folder
/VERSION @carlescufi @tejlmand
/ncs_version.h.in @carlescufi @tejlmand
/CODEOWNERS @carlescufi
/LICENSE @carlescufi
/README.rst @carlescufi
Expand Down
6 changes: 6 additions & 0 deletions cmake/version.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
math(EXPR NCS_VERSION_CODE "(${NCS_VERSION_MAJOR} << 16) + (${NCS_VERSION_MINOR} << 8) + (${NCS_VERSION_PATCH})")

# to_hex is made available by ${ZEPHYR_BASE}/cmake/hex.cmake
to_hex(${NCS_VERSION_CODE} NCS_VERSION_NUMBER)

configure_file(${NRF_DIR}/ncs_version.h.in ${ZEPHYR_BINARY_DIR}/include/generated/ncs_version.h)
13 changes: 13 additions & 0 deletions ncs_version.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _NCS_VERSION_H_
#define _NCS_VERSION_H_

#cmakedefine NCS_VERSION_CODE @NCS_VERSION_CODE@
#define NCS_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))

#define NCS_VERSION_NUMBER @NCS_VERSION_NUMBER@
#define NCS_VERSION_MAJOR @NCS_VERSION_MAJOR@
#define NCS_VERSION_MINOR @NCS_VERSION_MINOR@
#define NCS_PATCHLEVEL @NCS_VERSION_PATCH@
#define NCS_VERSION_STRING "@NCS_VERSION@"

#endif /* _NCS_VERSION_H_ */
6 changes: 6 additions & 0 deletions share/ncs-package/cmake/NcsConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ get_filename_component(NRF_DIR ${CMAKE_CURRENT_LIST_DIR}/${NRF_RELATIVE_DIR} ABS
get_filename_component(NCS_DIR ${CMAKE_CURRENT_LIST_DIR}/${NCS_RELATIVE_DIR} ABSOLUTE)

file(STRINGS ${NRF_DIR}/VERSION NCS_VERSION LIMIT_COUNT 1 LENGTH_MINIMUM 5)
string(REGEX MATCH "([^\.]*)\.([^\.]*)\.([^-]*)[-]?(.*)" OUT_VAR ${NCS_VERSION})

set(NCS_VERSION_MAJOR ${CMAKE_MATCH_1})
set(NCS_VERSION_MINOR ${CMAKE_MATCH_2})
set(NCS_VERSION_PATCH ${CMAKE_MATCH_3})
set(NCS_VERSION_EXTRA ${CMAKE_MATCH_4})

if(NOT NO_BOILERPLATE)
if(NCS_TOOLCHAIN_VERSION)
Expand Down

0 comments on commit fc25036

Please sign in to comment.