# IT4Innovations
# PH 2025

easyblock = 'CMakeMake'

name = 'libxc'
version = '6.1.0'
versionsuffix = '-nofhc'

homepage = 'https://libxc.gitlab.io'
description = """Libxc is a library of exchange-correlation functionals for density-functional theory.
 The aim is to provide a portable, well tested and reliable set of exchange and correlation functionals."""

toolchain = {'name': 'intel-compilers', 'version': '2022.2.1'}

import os
if os.environ.get("CLUSTERNAME") in ["KAROLINA"]:
   toolchainopts = {'opt': True, 'optarch': 'march=core-avx2'}
else:
   toolchainopts = {'opt': True}

source_urls = ['https://gitlab.com/libxc/libxc/-/archive/%(version)s/']
sources = [SOURCE_TAR_GZ]
checksums = [('9baf23501dca21b05fa22d8e2ffeb56f294abe19ba12584cb3f9b421ae719c5f',
              'a3aa16915942543031a5d9c4a92c439ce54249bdcda8c91c4e69e65329dc9a54')]

builddependencies = [
    ('CMake', '3.24.3'),
    ('Perl', '5.36.0'),
]

local_common_configopts = "-DENABLE_FORTRAN=ON -DENABLE_XHOST=OFF "

# don't disable building of third and fourth derivates, since it's required by some software that depends on libxc
# (like ABINIT, which requires "3rd derivatives of energy")
# see also https://github.com/pyscf/pyscf/issues/1103
local_common_configopts += "-DDISABLE_KXC=OFF -DDISABLE_LXC=OFF"

# Disable fhc, this needs to support codes (like VASP) relying on the projector augmented wave (PAW) approach
local_common_configopts += ' -DDISABLE_FHC=ON'

# perform iterative build to get both static and shared libraries
configopts = [
    local_common_configopts + ' -DBUILD_SHARED_LIBS=OFF',
    local_common_configopts + ' -DBUILD_SHARED_LIBS=ON',
]

# make sure that built libraries (libxc*.so*) in build directory are picked when running tests
# this is required when RPATH linking is used
pretestopts = "export LD_LIBRARY_PATH=%(builddir)s/easybuild_obj:$LD_LIBRARY_PATH && "

runtest = 'test'

sanity_check_paths = {
    'files': ['bin/xc-info'] +
             ['lib/libxc%s.%s' % (x, y) for x in ['', 'f03', 'f90'] for y in ['a', SHLIB_EXT]],
    'dirs': ['include', 'lib/pkgconfig', 'lib/cmake/Libxc'],
}

sanity_check_commands = ['xc-info 1']

moduleclass = 'chem'