Skip to content

Commit ef9a37d

Browse files
authored
AMREX_RELEASE_NUMBER (#2448)
Add a new macro `AMREX_RELEASE_NUMBER`. It is a six digits number. The first two are for the year, and the next two are for the month. The last two are usually 00, unless a patch other than the monthly release is released. If the AMReX source is a git version that's not the release version, the last release number will be used. For git version obtained with git --describe, we define something like #define AMREX_GIT_VERSION "21.10-65-gfbb2edc95551-dirty" #define AMREX_RELEASE_NUMBER 211000 For git version obtained from the CHANGES file, we define something like #define AMREX_GIT_VERSION "21.10" #define AMREX_RELEASE_NUMBER 211000 or #define AMREX_GIT_VERSION "21.10.1" #define AMREX_RELEASE_NUMBER 2110001 or #define AMREX_GIT_VERSION "21.10.11" #define AMREX_RELEASE_NUMBER 211011
1 parent 1d50bfc commit ef9a37d

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

Tools/CMake/AMReXConfig.cmake.in

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ set(AMReX_BUILD_TYPE @CMAKE_BUILD_TYPE@)
3838
#
3939
set(AMReX_GIT_VERSION \"@AMREX_GIT_VERSION@\")
4040

41+
#
42+
# Release number
43+
#
44+
set(AMReX_RELEASE_NUMBER @AMREX_RELEASE_NUMBER@)
45+
4146
#
4247
# AMReX CMake modules PATH
4348
#

Tools/CMake/AMReXSetDefines.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ include(AMReXGenerateConfigHeader) # provides add_amrex_defines
1717
# Git version
1818
add_amrex_define( "AMREX_GIT_VERSION=\"${AMREX_GIT_VERSION}\"" NO_LEGACY )
1919

20+
# Release number
21+
add_amrex_define( "AMREX_RELEASE_NUMBER=${AMREX_RELEASE_NUMBER}" NO_LEGACY )
22+
2023
# XSDK mode
2124
add_amrex_define( AMREX_XSDK NO_LEGACY IF USE_XSDK_DEFAULTS )
2225

Tools/CMake/AMReXUtils.cmake

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# FUNCTION: get_amrex_version
44
#
55
# Retrieves AMReX version info and sets internal cache variables
6-
# AMREX_GIT_VERSION and AMREX_PKG_VERSION
6+
# AMREX_GIT_VERSION, AMREX_RELEASE_NUMBER, and AMREX_PKG_VERSION
77
#
88
#
99
function (get_amrex_version)
@@ -30,7 +30,11 @@ function (get_amrex_version)
3030
list(GET ALL_VERSIONS 0 _tmp)
3131
string(REPLACE "#" "" _tmp "${_tmp}")
3232
string(STRIP "${_tmp}" _tmp )
33-
set(_tmp "${_tmp}.0")
33+
string(SUBSTRING "{_tmp}" 5 -1 _tmp2)
34+
if (NOT _tmp2) # don't want to add `.0` if it is already something like 21.10.2
35+
set(_tmp "${_tmp}.0")
36+
endif ()
37+
unset(_tmp2)
3438
endif ()
3539

3640
set( AMREX_GIT_VERSION "${_tmp}" CACHE INTERNAL "" )
@@ -48,6 +52,27 @@ function (get_amrex_version)
4852
set( AMREX_PKG_VERSION "${_pkg_version}" CACHE INTERNAL "" )
4953
unset(_pkg_version)
5054

55+
if (AMREX_GIT_VERSION)
56+
string(FIND "${AMREX_GIT_VERSION}" "-" _idx)
57+
string(SUBSTRING "${AMREX_GIT_VERSION}" 0 "${_idx}" _rel_number )
58+
string(REPLACE "." "" _rel_number "${_rel_number}")
59+
string(SUBSTRING "${_rel_number}" 0 4 _rel_yymm)
60+
string(SUBSTRING "${_rel_number}" 4 2 _rel_patch)
61+
string(LENGTH "${_rel_patch}" _rel_patch_len)
62+
if (_rel_patch_len EQUAL 0)
63+
string(PREPEND _rel_patch "00")
64+
elseif (_rel_patch_len EQUAL 1)
65+
string(PREPEND _rel_patch "00")
66+
endif ()
67+
string(CONCAT _rel_number "${_rel_yymm}" "${_rel_patch}")
68+
unset(_rel_yymm)
69+
unset(_rel_patch)
70+
unset(_rel_patch_len)
71+
endif ()
72+
73+
set( AMREX_RELEASE_NUMBER "${_rel_number}" CACHE INTERNAL "" )
74+
unset(_rel_number)
75+
5176
endfunction ()
5277

5378

Tools/CMake/AMReX_Config.H.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef AMREX_CONFIG_H_
22
#define AMREX_CONFIG_H_
33
#cmakedefine AMREX_GIT_VERSION @AMREX_GIT_VERSION@
4+
#cmakedefine AMREX_RELEASE_NUMBER @AMREX_RELEASE_NUMBER@
45
#cmakedefine AMREX_XSDK
56
#cmakedefine AMREX_DEBUG
67
#cmakedefine AMREX_PROFILING

Tools/GNUMake/Make.defs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,31 @@ ifndef AMREX_GIT_VERSION
387387
endif
388388
DEFINES += -DAMREX_GIT_VERSION=\"$(AMREX_GIT_VERSION)\"
389389

390+
ifeq ($(findstring ., $(AMREX_GIT_VERSION)), .)
391+
amrex_release_string := $(AMREX_GIT_VERSION)
392+
else
393+
# AMREX_GIT_VERSION obtained from a shallow clone does not have the release version
394+
amrex_release_string := $(shell grep -o -m 1 -E "[0-9]{2}\.[0-9]{2}(\.[0-9]+)?" $(AMREX_HOME)/CHANGES)
395+
endif
396+
amrex_release_words := $(subst ., ,$(firstword $(subst -, ,$(amrex_release_string))))
397+
amrex_release_numwords := $(words $(amrex_release_words))
398+
ifneq ($(amrex_release_numwords),2)
399+
ifneq ($(amrex_release_numwords),3)
400+
amrex_release_numwords := 3
401+
amrex_release_words := 00 00 00
402+
endif
403+
endif
404+
amrex_release_yy := $(word 1, $(amrex_release_words))
405+
amrex_release_mm := $(word 2, $(amrex_release_words))
406+
ifeq ($(amrex_release_numwords),2)
407+
AMREX_RELEASE_NUMBER := $(amrex_release_yy)$(amrex_release_mm)00
408+
else
409+
amrex_release_patch := $(shell printf '%02d' $(word 3, $(amrex_release_words)) | cut -c-2)
410+
AMREX_RELEASE_NUMBER := $(amrex_release_yy)$(amrex_release_mm)$(amrex_release_patch)
411+
endif
412+
DEFINES += -DAMREX_RELEASE_NUMBER=$(AMREX_RELEASE_NUMBER)
413+
414+
390415
FORTLINK = UNDERSCORE
391416

392417
FORT_CPP = cpp -E -traditional-cpp -P

0 commit comments

Comments
 (0)