1{ lib, stdenv
2, fetchFromGitHub
3, cmake
4, pkg-config
5, hidapi
6, SDL2
7, libGL
8, glew
9, withExamples ? true
10}:
11
12let examplesOnOff = if withExamples then "ON" else "OFF"; in
13
14stdenv.mkDerivation rec {
15 pname = "openhmd";
16 version = "0.3.0";
17
18 src = fetchFromGitHub {
19 owner = "OpenHMD";
20 repo = "OpenHMD";
21 rev = version;
22 sha256 = "1hkpdl4zgycag5k8njvqpx01apxmm8m8pvhlsxgxpqiqy9a38ccg";
23 };
24
25 nativeBuildInputs = [ cmake pkg-config ];
26
27 buildInputs = [
28 hidapi
29 ] ++ lib.optionals withExamples [
30 SDL2
31 glew
32 libGL
33 ];
34
35 cmakeFlags = [
36 "-DBUILD_BOTH_STATIC_SHARED_LIBS=ON"
37 "-DOPENHMD_EXAMPLE_SIMPLE=${examplesOnOff}"
38 "-DOPENHMD_EXAMPLE_SDL=${examplesOnOff}"
39 "-DOpenGL_GL_PREFERENCE=GLVND"
40
41 # RPATH of binary /nix/store/.../bin/... contains a forbidden reference to /build/
42 "-DCMAKE_SKIP_BUILD_RPATH=ON"
43 ];
44
45 postInstall = lib.optionalString withExamples ''
46 mkdir -p $out/bin
47 install -D examples/simple/simple $out/bin/openhmd-example-simple
48 install -D examples/opengl/openglexample $out/bin/openhmd-example-opengl
49 '';
50
51 meta = with lib; {
52 homepage = "http://www.openhmd.net"; # https does not work
53 description = "Library API and drivers immersive technology";
54 longDescription = ''
55 OpenHMD is a very simple FLOSS C library and a set of drivers
56 for interfacing with Virtual Reality (VR) Headsets aka
57 Head-mounted Displays (HMDs), controllers and trackers like
58 Oculus Rift, HTC Vive, Windows Mixed Reality, and etc.
59 '';
60 license = licenses.boost;
61 maintainers = with maintainers; [ oxij ];
62 platforms = platforms.unix;
63 };
64}