# IT4Innovations 2020

easyblock = 'CMakeMake'

name = 'libxc'
version = '4.3.4'

homepage = 'http://www.tddft.org/programs/octopus/wiki/index.php/Libxc'
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', 'version': '2019a'}

source_urls = ['http://www.tddft.org/programs/libxc/down.php?file=4.3.4/']
sources = ['libxc-4.3.4.tar.gz']
patches = ['libxc-%(version)s_rename-F03.patch']

builddependencies = [
    ('CMake', '3.16.2', '', True),
    ('Perl', '5.30.0', '', ('GCCcore', '8.3.0')),
]

separate_build_dir = True

# rename *.F03 source file since Intel Fortran local_compiler doesn't like that extension
# also requires patch file to rename file in CMakeLists.txt and src/Makefile.in
preconfigopts = "mv ../libxc-%(version)s/src/libxc_master.F03 ../libxc-%(version)s/src/libxc_master_F03.F90 && "

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

# 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',
]

parallel = 1

runtest = 'test'

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

moduleclass = 'chem'
