Unverified Commit f36a84bd authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

add CMake support for fetching external potential files

parent 20a9794b
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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
############################################
+17 −0
Original line number Diff line number Diff line
@@ -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)