1{ config, lib, stdenv, fetchFromGitHub, cmake, pkg-config, xorg, libGLU
2, libGL, glew, ocl-icd, python3
3, cudaSupport ? config.cudaSupport, cudatoolkit
4 # For visibility mostly. The whole approach to cuda architectures and capabilities
5 # will be reworked soon.
6, cudaArch ? "compute_37"
7, openclSupport ? !cudaSupport
8, darwin
9}:
10
11stdenv.mkDerivation rec {
12 pname = "opensubdiv";
13 version = "3.5.1";
14
15 src = fetchFromGitHub {
16 owner = "PixarAnimationStudios";
17 repo = "OpenSubdiv";
18 rev = "v${lib.replaceStrings ["."] ["_"] version}";
19 sha256 = "sha256-uDKCT0Uoa5WQekMUFm2iZmzm+oWAZ6IWMwfpchkUZY0=";
20 };
21
22 outputs = [ "out" "dev" ];
23
24 nativeBuildInputs = [ cmake pkg-config ];
25 buildInputs =
26 [ libGLU libGL python3
27 # FIXME: these are not actually needed, but the configure script wants them.
28 glew xorg.libX11 xorg.libXrandr xorg.libXxf86vm xorg.libXcursor
29 xorg.libXinerama xorg.libXi
30 ]
31 ++ lib.optional (openclSupport && !stdenv.isDarwin) ocl-icd
32 ++ lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [OpenCL Cocoa CoreVideo IOKit AppKit AGL ])
33 ++ lib.optional cudaSupport cudatoolkit;
34
35 cmakeFlags =
36 [ "-DNO_TUTORIALS=1"
37 "-DNO_REGRESSION=1"
38 "-DNO_EXAMPLES=1"
39 "-DNO_METAL=1" # don’t have metal in apple sdk
40 ] ++ lib.optionals (!stdenv.isDarwin) [
41 "-DGLEW_INCLUDE_DIR=${glew.dev}/include"
42 "-DGLEW_LIBRARY=${glew.dev}/lib"
43 ] ++ lib.optionals cudaSupport [
44 "-DOSD_CUDA_NVCC_FLAGS=--gpu-architecture=${cudaArch}"
45 "-DCUDA_HOST_COMPILER=${cudatoolkit.cc}/bin/cc"
46 ] ++ lib.optionals (!openclSupport) [
47 "-DNO_OPENCL=1"
48 ];
49
50 preBuild = let maxBuildCores = 16; in lib.optionalString cudaSupport ''
51 # https://github.com/PixarAnimationStudios/OpenSubdiv/issues/1313
52 NIX_BUILD_CORES=$(( NIX_BUILD_CORES < ${toString maxBuildCores} ? NIX_BUILD_CORES : ${toString maxBuildCores} ))
53 '';
54
55 postInstall = "rm $out/lib/*.a";
56
57 meta = {
58 description = "An Open-Source subdivision surface library";
59 homepage = "http://graphics.pixar.com/opensubdiv";
60 broken = openclSupport && cudaSupport;
61 platforms = lib.platforms.unix;
62 maintainers = [ lib.maintainers.eelco ];
63 license = lib.licenses.asl20;
64 };
65}