# Template file for 'freecad'
pkgname=freecad
version=1.0.0
revision=2
_pycxx_ver=7.1.8
_ondsel_ver=91f70382beeb58b32432b5a82da3802e4c19199c
build_style=cmake
pycompile_dirs="usr/lib/${pkgname}/Mod"
_inst_prefix=/usr/lib/${pkgname}
configure_args="-DPYTHON_EXECUTABLE=/usr/bin/python3 -DBUILD_GUI=ON
 -DFREECAD_QT_VERSION=6 -DBUILD_FEM_NETGEN=OFF -DBUILD_FLAT_MESH=ON
 -DENABLE_DEVELOPER_TESTS=OFF -DBUILD_TEST=OFF
 -DFREECAD_USE_EXTERNAL_PIVY=ON -DCMAKE_INSTALL_PREFIX=${_inst_prefix}
 -DCMAKE_INSTALL_DATAROOTDIR=/usr/share -DCMAKE_INSTALL_DATADIR=/usr/share/${pkgname}
 -DMEDFILE_INCLUDE_DIRS=/usr/include/med -DCOIN3D_INCLUDE_DIRS=/usr/include/Coin3"
hostmakedepends="pkg-config swig doxygen graphviz python3-setuptools
 python3-matplotlib python3-pivy"
makedepends="boost-devel boost-python3 libxerces-c-devel zlib-devel occt-devel vtk-devel
 hdf5-devel openmpi-devel libmed-devel eigen double-conversion-devel
 coin3-devel libspnav-devel liblz4-devel netcdf-devel jsoncpp-devel
 glew-devel python3-devel yaml-cpp-devel guidelines-support-library
 qt6-base-devel qt6-svg-devel qt6-tools-devel libpyside6-devel"
depends="python3-matplotlib python3-pivy python3-GitPython python3-Markdown
 python3-pyside6"
short_desc="General purpose 3D CAD modeler"
maintainer="yopito <pierre.bourgin@free.fr>"
license="LGPL-2.0-or-later"
homepage="https://freecadweb.org/"
distfiles="https://github.com/FreeCAD/FreeCAD/archive/${version}.tar.gz
 ${SOURCEFORGE_SITE}/cxx/pycxx-${_pycxx_ver}.tar.gz
 https://github.com/Ondsel-Development/OndselSolver/archive/${_ondsel_ver}.tar.gz>OndselSolver-${_ondsel_ver}.tar.gz"
checksum="51115afd8e3b89f4bac343b986b0800d8e1c68fc1e322c3cd179cfe1033ef937
 4b91e1e1141c23fbd5039df635c4bb6e75632168548f56b83ce177193c0c98c6
 061f651f503f1ec5a9814e174cdb8a9ba84d511a3b8be3d94852e84976c6b158"
python_version=3
skip_extraction="pycxx-${_pycxx_ver}.tar.gz
 OndselSolver-${_ondsel_ver}.tar.gz"

if [ "$XBPS_TARGET_LIBC" = musl ]; then
	makedepends+=" libexecinfo-devel"
	LDFLAGS="-lexecinfo"
fi

CXXFLAGS="-DPYCXX_PYTHON_2TO3"

post_extract() {
	vsrcextract -C src/3rdParty/OndselSolver "OndselSolver-${_ondsel_ver}.tar.gz"
	vsrcextract -C pycxx "pycxx-${_pycxx_ver}.tar.gz"
	rm -r src/CXX
	ln -Tsr ./pycxx/CXX src/CXX
}

post_patch() {
	# Report exact minor version
	# Freecad has a record of shipping mismatching version info
	vminor=${version#*.}
	vminor=${vminor%%.*}
	sed -i -e "s,^\(set(PACKAGE_VERSION_MINOR\) .*,\1 \"${vminor}\")," CMakeLists.txt

	# SubWCRev.py (SCM check) reports "unknown" for these fields
	vsed -e "s,\${PACKAGE_WCREF},${revision}_voidlinux," \
	     -e "s,\${PACKAGE_WCDATE},(from release)," \
	     -e "s,\${PACKAGE_WCURL},Void Linux package ${pkgname}," \
	     -i src/Build/Version.h.cmake
}

pre_configure() {
	configure_args+=" -DPYCXX_INCLUDE_DIR=${wrksrc}/pycxx
	 -DPYCXX_SOURCE_DIR=${wrksrc}/pycxx/Src"
}

post_install() {
	# AppHomePath is computed with binary's realpath:
	# do not move binaries but symlink them instead.
	vmkdir usr/bin
	for f in FreeCAD FreeCADCmd; do
		ln -s ${_inst_prefix}/bin/${f} ${DESTDIR}/usr/bin/${f}
	done
}
