diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt index de65e85516..7a82a67606 100644 --- a/cmake/CMakeLists.txt +++ b/cmake/CMakeLists.txt @@ -365,6 +365,15 @@ target_link_libraries(lammps PRIVATE ${MATH_LIBRARIES}) include(StyleHeaderUtils) RegisterStyles(${LAMMPS_SOURCE_DIR}) +######################################################## +# Fetch missing external files and archives for packages +######################################################## +foreach(PKG ${STANDARD_PACKAGES} ${SUFFIX_PACKAGES}) + if(PKG_${PKG}) + FetchPotentials(${${PKG}_SOURCES_DIR} ${LAMMPS_POTENTIALS_DIR}) + endif() +endforeach() + ############################################## # add sources of enabled packages ############################################ diff --git a/cmake/Modules/LAMMPSUtils.cmake b/cmake/Modules/LAMMPSUtils.cmake index 02de630c82..b07f49608a 100644 --- a/cmake/Modules/LAMMPSUtils.cmake +++ b/cmake/Modules/LAMMPSUtils.cmake @@ -85,3 +85,20 @@ function(GenerateBinaryHeader varname outfile files) file(APPEND ${outfile} "const unsigned int ${varname}_size = sizeof(${varname});\n") endforeach() endfunction(GenerateBinaryHeader) + +# fetch missing potential files +function(FetchPotentials pkgfolder potfolder) + if (EXISTS "${pkgfolder}/potentials.txt") + set(LAMMPS_POTENTIALS_URL "https://download.lammps.org/potentials") + file(STRINGS "${pkgfolder}/potentials.txt" linelist REGEX "^[^#].") + foreach(line ${linelist}) + string(FIND ${line} " " blank) + math(EXPR plusone "${blank}+1") + string(SUBSTRING ${line} 0 ${blank} pot) + string(SUBSTRING ${line} ${plusone} -1 sum) + message("Checking whether to download external potential ${pot} from ${LAMMPS_POTENTIALS_URL}") + file(DOWNLOAD "${LAMMPS_POTENTIALS_URL}/${pot}.${sum}" "${LAMMPS_POTENTIALS_DIR}/${pot}" + EXPECTED_HASH MD5=${sum} SHOW_PROGRESS) + endforeach() + endif() +endfunction(FetchPotentials)