# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           boost 1.0
PortGroup           cmake 1.1
PortGroup           github 1.0
PortGroup           conflicts_build 1.0

github.setup        rdkit rdkit 2025_09_5 Release_
github.tarball_from archive
version             [join [split ${github.version} _] .]
revision            0

categories          science chemistry
license             BSD
maintainers         {reneeotten @reneeotten} openmaintainer

description         RDKit: Open-Source Cheminformatics Software
long_description    RDKit is a collection of cheminformatics and \
                    machine-learning software written in C++ and Python.

homepage            https://www.rdkit.org/

checksums           rmd160  0be7091b0e08baead7f35b218f414f820361371c \
                    sha256  1ac784a5f83a7db10aa50be0cd213eba7c1f3436ed4da12363e57589b571db46 \
                    size    82970707

# some of the vendored dependencies in the "External" directory fail to build
# when the "boost" port is installed; likely because they pick up libraries in ${prefix}/lib
# instead of the intended ones in ${prefix}/libexec/boost/${boost.version}
conflicts_build     boost
boost.version       1.88
boost.require_numpy yes

compiler.c_standard 1999
compiler.cxx_standard 2020

set py_ver          3.14
set py_ver_nodot    [string map {. {}} ${py_ver}]
set mypydir         ${frameworks_dir}/Python.framework/Versions/${py_ver}

patchfiles          patch-RDK-BOOST-VERSION.diff

depends_build-append \
                    path:bin/pkg-config:pkgconfig

depends_lib-append  port:catch2 \
                    port:coordgen \
                    port:maeparser \
                    port:eigen3 \
                    port:cairo \
                    port:freetype \
                    port:rapidjson \
                    port:sqlite3 \
                    port:python${py_ver_nodot} \
                    port:py${py_ver_nodot}-numpy \
                    port:py${py_ver_nodot}-cairo

cmake.module_path-append \
                    [boost::lib_dir]/cmake \
                    [boost::lib_dir]/cmake/Boost-${boost.version} \
                    ${prefix}/lib/cmake

configure.args-append \
                    -DRDK_INSTALL_INTREE=OFF \
                    -DRDK_BUILD_CPP_TESTS=OFF \
                    -DRDK_INSTALL_STATIC_LIBS=OFF \
                    -DRDK_BUILD_CAIRO_SUPPORT=ON \
                    -DCatch2_DIR=${prefix}/include/catch2 \
                    -DRDK_BUILD_PYTHON_WRAPPERS=ON \
                    -DPython3_EXECUTABLE=${mypydir}/bin/python${py_ver} \
                    -DPython3_NumPy_INCLUDE_DIRS="${mypydir}/lib/python3.13/site-packages/numpy/_core/include" \
                    -DCMAKE_REQUIRE_FIND_PACKAGE_coordgen=ON \
                    -DCMAKE_REQUIRE_FIND_PACKAGE_maeparser=ON \
                    -DRDK_BUILD_INCHI_SUPPORT=ON \
                    -DRDK_BUILD_AVALON_SUPPORT=ON \
                    -DRDK_BUILD_YAEHMOP_SUPPORT=ON \
                    -DRDK_BUILD_FREESASA_SUPPORT=ON \
                    -DRDK_BUILD_COMPRESSED_SUPPLIERS=ON \
                    -DRDK_INSTALL_PYTHON_TESTS=ON

post-destroot {
    # conflicts with the file isntalled by the "expat" port
    file delete ${destroot}${prefix}/lib/libexpat.a
}
