SUMMARY="A large scale non-linear optimization library"
DESCRIPTION="Ceres Solver 1 is an open source C++ library for modeling and \
solving large, complicated optimization problems. It can be used to solve \
Non-linear Least Squares problems with bounds constraints and general \
unconstrained optimization problems. It is a mature, feature rich, and \
performant library that has been used in production at Google since 2010."
HOMEPAGE="http://ceres-solver.org/"
COPYRIGHT="2015 Google Inc."
LICENSE="BSD (3-clause)
	Apache v2"
REVISION="1"
srcGitRev="46b3495a4f84eb5b7832b686a0b053cd71a1acab"
SOURCE_URI="https://github.com/ceres-solver/ceres-solver/archive/$srcGitRev.tar.gz"
CHECKSUM_SHA256="1a76b9aeb1d8e5565c49ca90a04108242a934270e8d14baeab4dd8672321c9b5"
SOURCE_FILENAME="ceres-solver-$portVersion-tar.gz"
SOURCE_DIR="ceres-solver-$srcGitRev"

ARCHITECTURES="!x86_gcc2 all"
SECONDARY_ARCHITECTURES="x86"

libVersion="2.1.0"
libVersionCompat="$libVersion compat >= ${libVersion%%.*}"

PROVIDES="
	ceres_solver$secondaryArchSuffix = $portVersion
	lib:libceres$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libamd$secondaryArchSuffix
	lib:libcamd$secondaryArchSuffix
	lib:libccolamd$secondaryArchSuffix
	lib:libcholmod$secondaryArchSuffix
	lib:libcolamd$secondaryArchSuffix
	lib:libglog$secondaryArchSuffix
	lib:liblapack$secondaryArchSuffix
	lib:libmetis$secondaryArchSuffix
	lib:libopenblas$secondaryArchSuffix
	lib:libspqr$secondaryArchSuffix
	lib:libsuitesparseconfig$secondaryArchSuffix
	lib:libtbb$secondaryArchSuffix
	"

PROVIDES_devel="
	ceres_solver${secondaryArchSuffix}_devel = $portVersion
	devel:libceres$secondaryArchSuffix = $libVersionCompat
	"
REQUIRES_devel="
	ceres_solver$secondaryArchSuffix == $portVersion base
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	devel:eigen$secondaryArchSuffix
	devel:libamd$secondaryArchSuffix
	devel:libcamd$secondaryArchSuffix
	devel:libccolamd$secondaryArchSuffix
	devel:libcholmod$secondaryArchSuffix
	devel:libcolamd$secondaryArchSuffix
	devel:libglog$secondaryArchSuffix
	devel:liblapack$secondaryArchSuffix
	devel:libmetis$secondaryArchSuffix
	devel:libopenblas$secondaryArchSuffix
	devel:libspqr$secondaryArchSuffix
	devel:libsuitesparseconfig$secondaryArchSuffix
	devel:libtbb$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:make
	cmd:pkg_config$secondaryArchSuffix
	"

defineDebugInfoPackage ceres_solver$secondaryArchSuffix \
	$libDir/libceres.so.$libVersion

BUILD()
{
	mkdir -p build && cd "$_"

	cmake .. \
		-DBUILD_SHARED_LIBS=ON \
		-DEigen3_DIR=`finddir B_SYSTEM_DATA_DIRECTORY`/eigen3/cmake \
		-DCMAKE_BUILD_TYPE=RelWithDebInfo \
		$cmakeDirArgs

	make # parallel builds needs way too much ram
}

INSTALL()
{
	cd build

	make install $jobArgs

	prepareInstalledDevelLib libceres

	fixPkgconfig

	packageEntries devel \
		$developDir \
		$libDir/cmake
}

TEST()
{
	cd build
	make test
}
