# Template file for 'freecad'
pkgname=freecad
version=1.1.3
revision=1
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
 -DFREECAD_CHECK_PIVY=OFF -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}"
hostmakedepends="pkg-config swig qt6-base qt6-tools"
makedepends="boost-devel-minimal boost-python3 libboost_filesystem
 libboost_thread libboost_program_options libxerces-c-devel zlib-devel occt-devel
 vtk-devel hdf5-devel libgomp-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 python3-pybind11"
depends="python3-matplotlib python3-pivy python3-GitPython python3-Markdown
 python3-pyside6-gui python3-pyside6-network python3-pyside6-printsupport
 python3-pyside6-ui-tools python3-pyside6-widgets vtk-python3
 python3-pyside6-svg python3-yaml"
short_desc="General purpose 3D CAD modeler"
maintainer="Orphaned <orphan@voidlinux.org>"
license="GPL-2.0-or-later"
homepage="https://www.freecad.org"
distfiles="https://github.com/FreeCAD/FreeCAD/releases/download/${version}/freecad_source_${version}.tar.gz"
checksum=4813a5cd12be05253cd40cc1dc3995b1aaa1aa06f7dfbc15c7ffa99c1c3903b7

CXXFLAGS="-DPYCXX_PYTHON_2TO3"

pre_configure() {
	configure_args+=" -DPYCXX_INCLUDE_DIR=${wrksrc}/src/3rdParty/PyCXX
					  -DPYCXX_SOURCE_DIR=${wrksrc}/src/3rdParty/PyCXX/CXX"

	if [ -n "$CROSS_BUILD" ]; then
		configure_args+=" -DMEDFILE_INCLUDE_DIRS=${XBPS_CROSS_BASE}/usr/include/med"
		configure_args+=" -DCOIN3D_INCLUDE_DIRS=${XBPS_CROSS_BASE}/usr/include/Coin3"
	else
		configure_args+=" -DMEDFILE_INCLUDE_DIRS=/usr/include/med"
		configure_args+=" -DCOIN3D_INCLUDE_DIRS=/usr/include/Coin3"
	fi
}

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
}

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
}
