add CMake option to skip automatic download of large potential files

This commit is contained in:
Axel Kohlmeyer
2023-01-21 11:21:02 -05:00
parent 650caa356f
commit 6f3c8fc48e
2 changed files with 23 additions and 19 deletions

View File

@ -566,6 +566,8 @@ RegisterStyles(${LAMMPS_SOURCE_DIR})
######################################################## ########################################################
# Fetch missing external files and archives for packages # Fetch missing external files and archives for packages
######################################################## ########################################################
option(DOWNLOAD_POTENTIALS "Automatically download large potential files" ON)
mark_as_advanced(DOWNLOAD_POTENTIALS)
foreach(PKG ${STANDARD_PACKAGES} ${SUFFIX_PACKAGES}) foreach(PKG ${STANDARD_PACKAGES} ${SUFFIX_PACKAGES})
if(PKG_${PKG}) if(PKG_${PKG})
FetchPotentials(${LAMMPS_SOURCE_DIR}/${PKG} ${LAMMPS_POTENTIALS_DIR}) FetchPotentials(${LAMMPS_SOURCE_DIR}/${PKG} ${LAMMPS_POTENTIALS_DIR})

View File

@ -118,25 +118,27 @@ endfunction(GenerateBinaryHeader)
# fetch missing potential files # fetch missing potential files
function(FetchPotentials pkgfolder potfolder) function(FetchPotentials pkgfolder potfolder)
if(EXISTS "${pkgfolder}/potentials.txt") if(DOWNLOAD_POTENTIALS)
file(STRINGS "${pkgfolder}/potentials.txt" linelist REGEX "^[^#].") if(EXISTS "${pkgfolder}/potentials.txt")
foreach(line ${linelist}) file(STRINGS "${pkgfolder}/potentials.txt" linelist REGEX "^[^#].")
string(FIND ${line} " " blank) foreach(line ${linelist})
math(EXPR plusone "${blank}+1") string(FIND ${line} " " blank)
string(SUBSTRING ${line} 0 ${blank} pot) math(EXPR plusone "${blank}+1")
string(SUBSTRING ${line} ${plusone} -1 sum) string(SUBSTRING ${line} 0 ${blank} pot)
if(EXISTS "${LAMMPS_POTENTIALS_DIR}/${pot}") string(SUBSTRING ${line} ${plusone} -1 sum)
file(MD5 "${LAMMPS_POTENTIALS_DIR}/${pot}" oldsum) if(EXISTS "${LAMMPS_POTENTIALS_DIR}/${pot}")
endif() file(MD5 "${LAMMPS_POTENTIALS_DIR}/${pot}" oldsum)
if(NOT sum STREQUAL oldsum) endif()
message(STATUS "Downloading external potential ${pot} from ${LAMMPS_POTENTIALS_URL}") if(NOT sum STREQUAL oldsum)
string(MD5 TMP_EXT "${CMAKE_BINARY_DIR}") message(STATUS "Downloading external potential ${pot} from ${LAMMPS_POTENTIALS_URL}")
file(DOWNLOAD "${LAMMPS_POTENTIALS_URL}/${pot}.${sum}" "${CMAKE_BINARY_DIR}/${pot}.${TMP_EXT}" string(RANDOM LENGTH 10 TMP_EXT)
EXPECTED_HASH MD5=${sum} SHOW_PROGRESS) file(DOWNLOAD "${LAMMPS_POTENTIALS_URL}/${pot}.${sum}" "${CMAKE_BINARY_DIR}/${pot}.${TMP_EXT}"
file(COPY "${CMAKE_BINARY_DIR}/${pot}.${TMP_EXT}" DESTINATION "${LAMMPS_POTENTIALS_DIR}") EXPECTED_HASH MD5=${sum} SHOW_PROGRESS)
file(RENAME "${LAMMPS_POTENTIALS_DIR}/${pot}.${TMP_EXT}" "${LAMMPS_POTENTIALS_DIR}/${pot}") file(COPY "${CMAKE_BINARY_DIR}/${pot}.${TMP_EXT}" DESTINATION "${LAMMPS_POTENTIALS_DIR}")
endif() file(RENAME "${LAMMPS_POTENTIALS_DIR}/${pot}.${TMP_EXT}" "${LAMMPS_POTENTIALS_DIR}/${pot}")
endforeach() endif()
endforeach()
endif()
endif() endif()
endfunction(FetchPotentials) endfunction(FetchPotentials)