#  Copyright (C) 2019 The authors of Py-ChemShell
#
#  This file is part of Py-ChemShell.
#
#  Py-ChemShell is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as
#  published by the Free Software Foundation, either version 3 of the
#  License, or (at your option) any later version.
#
#  Py-ChemShell is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU Lesser General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public
#  License along with Py-ChemShell.  If not, see
#  <http://www.gnu.org/licenses/>.

# you.lu@stfc.ac.uk
# Oct 2019

include(ExternalProject)

if(NOT "${CHARMM_FF}" STREQUAL "")

    # get the CHARMM_FF version
    string(REGEX MATCH "([A-Za-z]+[0-9][0-9][A-Za-z]*[_]?[A-Za-z]*[0-9]*[0-9]?)" CHARMM_FF_VERSION "${CHARMM_FF}")
    set(CHARMM_FF_NAME charmm_ff-${CHARMM_FF_VERSION})

    # YL 17/10/2019: get_module(module_name module_loc destination prefix)
    get_module(CHARMM_FF "${CHARMM_FF}" "${CMAKE_CURRENT_SOURCE_DIR}" "${CHARMM_FF_VERSION}" ON "")
    # cache-level variable cannot be set within a function
    set(CHARMM_FF_SRC_DIR "${CHARMM_FF_SRC_DIR}" CACHE FILEPATH "" FORCE)

    # YL 16/11/2021: v2021
    if(${CHARMM_FF_VERSION} STREQUAL "c36_jul21")
        get_filename_component(CHARMM_FF_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${CHARMM_FF_VERSION}/toppar_${CHARMM_FF_VERSION} ABSOLUTE)
    # v2020
    else()
        get_filename_component(CHARMM_FF_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${CHARMM_FF_VERSION} ABSOLUTE)
    endif()

    configure_file(info.py.in info.py @ONLY)

else()
    return()
endif()

set(CHARMM_FF_OBJ_DIR ${CHARMM_FF_SRC_DIR}/${CHARMM_FF_ARCH}/obj)

