Skip to content

Commit 3cb979d

Browse files
committed
vendor old get_lammps_version
1 parent c0b71f0 commit 3cb979d

2 files changed

Lines changed: 52 additions & 3 deletions

File tree

source/lmp/builtin.cmake

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,31 @@
55
# assume LAMMPS CMake file has been executed, so these target/variables exist:
66
# lammps LAMMPS_SOURCE_DIR get_lammps_version
77

8-
get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h LAMMPS_VERSION_NUMBER)
8+
# Since May 15, 2025, the output of get_lammps_version is changed.
9+
# We vendor the old get_lammps_version
10+
# https://github.com/lammps/lammps/commit/b3e7121535863df3db487cd3e6a68c080bf2a6b4#diff-1214db0d1c015a50103f61f8ff7896053dec7ebc1edb930d6ef8bb07282f52abR75
11+
function(_get_lammps_version version_header variable)
12+
file(STRINGS ${version_header} line REGEX LAMMPS_VERSION)
13+
set(MONTHS x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
14+
string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\1" day "${line}")
15+
string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\2" month "${line}")
16+
string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\3" year "${line}")
17+
string(STRIP ${day} day)
18+
string(STRIP ${month} month)
19+
string(STRIP ${year} year)
20+
list(FIND MONTHS "${month}" month)
21+
string(LENGTH ${day} day_length)
22+
string(LENGTH ${month} month_length)
23+
if(day_length EQUAL 1)
24+
set(day "0${day}")
25+
endif()
26+
if(month_length EQUAL 1)
27+
set(month "0${month}")
28+
endif()
29+
set(${variable} "${year}${month}${day}" PARENT_SCOPE)
30+
endfunction()
31+
32+
_get_lammps_version(${LAMMPS_SOURCE_DIR}/version.h LAMMPS_VERSION_NUMBER)
933

1034
configure_file("${CMAKE_CURRENT_LIST_DIR}/deepmd_version.h.in"
1135
"${CMAKE_CURRENT_BINARY_DIR}/deepmd_version.h" @ONLY)

source/lmp/plugin/CMakeLists.txt

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,33 @@ if(DEFINED LAMMPS_SOURCE_ROOT OR DEFINED LAMMPS_VERSION)
3838

3939
# get_lammps_version
4040
# https://github.com/lammps/lammps/blob/c2a12f97c5f665852fb38fdd4922f7dd2e77a0a1/cmake/Modules/LAMMPSUtils.cmake#L27-L46
41-
include(${LAMMPS_SOURCE_ROOT}/cmake/Modules/LAMMPSUtils.cmake)
42-
get_lammps_version(${LAMMPS_HEADER_DIR}/version.h LAMMPS_VERSION_NUMBER)
41+
# include(${LAMMPS_SOURCE_ROOT}/cmake/Modules/LAMMPSUtils.cmake)
42+
# Since May 15, 2025, the output of get_lammps_version is changed.
43+
# We vendor the old get_lammps_version
44+
# https://github.com/lammps/lammps/commit/b3e7121535863df3db487cd3e6a68c080bf2a6b4#diff-1214db0d1c015a50103f61f8ff7896053dec7ebc1edb930d6ef8bb07282f52abR75
45+
46+
function(_get_lammps_version version_header variable)
47+
file(STRINGS ${version_header} line REGEX LAMMPS_VERSION)
48+
set(MONTHS x Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
49+
string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\1" day "${line}")
50+
string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\2" month "${line}")
51+
string(REGEX REPLACE "#define LAMMPS_VERSION \"([0-9]+) ([A-Za-z]+) ([0-9]+)\"" "\\3" year "${line}")
52+
string(STRIP ${day} day)
53+
string(STRIP ${month} month)
54+
string(STRIP ${year} year)
55+
list(FIND MONTHS "${month}" month)
56+
string(LENGTH ${day} day_length)
57+
string(LENGTH ${month} month_length)
58+
if(day_length EQUAL 1)
59+
set(day "0${day}")
60+
endif()
61+
if(month_length EQUAL 1)
62+
set(month "0${month}")
63+
endif()
64+
set(${variable} "${year}${month}${day}" PARENT_SCOPE)
65+
endfunction()
66+
67+
_get_lammps_version_old(${LAMMPS_HEADER_DIR}/version.h LAMMPS_VERSION_NUMBER)
4368
set(LAMMPS_VERSION_NUMBER
4469
${LAMMPS_VERSION_NUMBER}
4570
PARENT_SCOPE)

0 commit comments

Comments
 (0)