# Template file for 'freecad'
pkgname=freecad
version=0.19.2
revision=4
wrksrc="FreeCAD-${version}"
build_style=cmake

_inst_prefix=/usr/lib/${pkgname}
configure_args="
 -DPYTHON_EXECUTABLE=/usr/bin/python3
 -DBUILD_QT5=ON
 -DBUILD_FEM_NETGEN=OFF
 -DBUILD_FLAT_MESH=ON
 -DCMAKE_INSTALL_PREFIX=${_inst_prefix}
 -DCMAKE_INSTALL_DATAROOTDIR=/usr/share
 -DCMAKE_INSTALL_DATADIR=/usr/share/${pkgname}
 -DMEDFILE_INCLUDE_DIRS=/usr/include/med
 -DPYSIDE2RCCBINARY=/usr/bin/rcc-qt5
 -DPYSIDE2UICBINARY=/usr/bin/uic-qt5"
hostmakedepends="pkg-config swig doxygen graphviz"
makedepends="python3-devel boost-devel libxerces-c-devel zlib-devel occt-devel
 vtk-devel hdf5-devel openmpi-devel libmed-devel eigen double-conversion-devel
 coin3-devel libshiboken2-devel libspnav-devel pyside2-tools
 liblz4-devel libpyside2-python3-devel python3-matplotlib netcdf-devel
 jsoncpp-devel qt5-devel qt5-svg-devel qt5-tools-devel qt5-webkit-devel
 qt5-xmlpatterns-devel coin3-doc glew-devel"

# FreeCAD help: qt5/assistant with SQLite storage
depends="python3-matplotlib python3-pyside2 qt5-plugin-sqlite python3-pivy"

python_version=3
pycompile_dirs="usr/lib/${pkgname}/Mod"

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"
checksum=47e39e3d6fcafe6e0c68923fb1b86acda16986268e5e6011694057b940139fba

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

post_extract() {
	# Report exact minor version
	vsed -i -e "s,^\(set(PACKAGE_VERSION_MINOR\) .*,\1 \"${version#*.}\")," 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},VoidLinux package ${pkgname}," \
	     -i src/Build/Version.h.cmake
}

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
}