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

EAPI="5"

inherit cmake-utils eutils versionator

CMAKE_MIN_VERSION="2.8.3"

MY_MAJORV="0$(get_major_version)"
MY_PV=$(replace_all_version_separators "_" "$MY_MAJORV-"$(get_after_major_version))
MY_P="${PN}_${MY_PV}"
S="${WORKDIR}/${PN}"

SLOT="0"

DESCRIPTION="Virtual-Reality Peripheral Network"
HOMEPAGE="http://www.cs.unc.edu/Research/vrpn/"
SRC_URI="http://www.cs.unc.edu/Research/${PN}/downloads/${MY_P}.zip"

LICENSE="Boost-1.0"
KEYWORDS="~amd64 ~x86"
# TODO: USE flags: ghost, intersense, java, jsonnet, libnifalcon, nidaqmx, openhaptics, phantom, python, viewpoint
IUSE="gpm hid modbus mpi +server usb wiiuse"
REQUIRED_USE="
	      wiiuse? ( server )
	     "

# VRPN comes bundled with its subproject libquat
RDEPEND="
	hid? ( dev-libs/hidapi  )
	modbus? ( dev-libs/libmodbus  )
	mpi? ( virtual/mpi )
	usb? ( >=virtual/libusb-1 )
	wiiuse? ( games-util/wiiuse )
"
DEPEND="${RDEPEND}"

src_configure() {
	local mycmakeargs=(
		$(cmake-utils_use gpm)
		$(cmake-utils_use gpm VRPN_USE_GPM_MOUSE)
		$(cmake-utils_use hid VRPN_USE_HID)
		$(cmake-utils_use modbus VRPN_USE_MODBUS)
		$(cmake-utils_use mpi VRPN_USE_MPI)
		$(cmake-utils_use server VRPN_BUILD_SERVERS) # Server applications
		$(cmake-utils_use server VRPN_BUILD_SERVER_LIBRARY)
		$(cmake-utils_use server VRPN_GPL_SERVER)
		$(cmake-utils_use usb VRPN_USE_LIBUSB_1_0)
		# To enable bindings for Python 2.x generated by SWIG set VRPN_BUILD_PYTHON
		-DVRPN_BUILD_PYTHON=NO
		# To enable bindings for Python 2.x set VRPN_BUILD_PYTHON_HANDCODED_2X
		-DVRPN_BUILD_PYTHON_HANDCODED_2X=NO
		# To enable bindings for Python 3.x set VRPN_BUILD_PYTHON_HANDCODED_3X
		-DVRPN_BUILD_PYTHON_HANDCODED_3X=NO
		-DVRPN_BUILD_JAVA=NO
		$(cmake-utils_use wiiuse VRPN_USE_WIIUSE)
		-DVRPN_USE_LOCAL_HIDAPI=NO # Disable bundled HIDAPI
		-DVRPN_USE_LOCAL_JSONCPP=NO # Disable bundled jsoncpp
	)
	cmake-utils_src_configure
}