# -*- 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           legacysupport 1.1
PortGroup           conflicts_build 1.0

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

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

# error: '~path' is unavailable: introduced in macOS 10.15
legacysupport.use_mp_libcxx yes
legacysupport.newest_darwin_requires_legacy 19

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}

# avoid errors for 'TARGET_OS_*' is not defined in External/ChemDraw
patchfiles-append   patch-ChemDraw-CMakeLists.txt

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

depends_lib-append  port:catch2 \
                    port:coordgen \
                    port:maeparser \
                    path:share/pkgconfig/eigen3.pc:eigen3 \
                    path:lib/pkgconfig/cairo.pc:cairo \
                    port:freetype \
                    path:lib/pkgconfig/RapidJSON.pc: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/python${py_ver}/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=OFF \
                    -DPYTHON_INSTDIR=${mypydir}/lib/python${py_ver}/site-packages

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