# Copyright 1999-2011 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: $

EAPI="2"

inherit cmake-utils mercurial flag-o-matic python

DESCRIPTION="A GPL unbiased renderer"
HOMEPAGE="http://www.luxrender.net"
EHG_REPO_URI="https://bitbucket.org/luxrender/lux"

LICENSE="GPL-3"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE="sse2 doc debug +blender opencl"

RDEPEND=">=dev-libs/boost-1.43
	media-libs/openexr
	media-libs/tiff
	media-libs/libpng
	virtual/jpeg
	media-libs/ilmbase
	media-libs/freeimage
	virtual/opengl
	opencl? ( virtual/opencl )"

DEPEND="${RDEPEND}
	sys-devel/bison
	sys-devel/flex
	media-libs/luxrays[debug?]
	doc? ( >=app-doc/doxygen-1.5.7[-nodot] )"
PDEPEND="blender? ( =media-gfx/blender-2.63* =media-gfx/luxblend25-9999 )"

src_configure() {
	use sse2 && append-flags "-msse -msse2 -DLUX_USE_SSE"
	use debug && append-flags -ggdb

	if use opencl ; then
		mycmakeargs=(
		-DOPENCL_SEARCH_PATH=/usr/$(get_libdir)/OpenCL/global/include
		)
	else
		mycmakeargs=( -DLUXRAYS_DISABLE_OPENCL=ON )
	fi
	cmake-utils_src_configure
}

src_install() {
	cmake-utils_src_install
	dodoc AUTHORS.txt || die

	# installing API(s) docs
	if use doc; then
		pushd "${S}"/doxygen > /dev/null
		doxygen doxygen.template
		dohtml html/* || die "Couldn't install API docs"
		popd > /dev/null
	fi

	if use blender; then
		insinto /usr/share/blender/2.63/scripts/addons/luxrender/
		doins "${CMAKE_BUILD_DIR}"/pylux.so || die "Couldn't install Pylux"
	fi
}