1{
2 stdenv,
3 lib,
4 fetchFromGitHub,
5 cmake,
6 pkg-config,
7 libpng,
8 libjpeg,
9 libwebp,
10 blas,
11 lapack,
12 config,
13 guiSupport ? false,
14 libX11,
15 enableShared ? !stdenv.hostPlatform.isStatic, # dlib has a build system that forces the user to choose between either shared or static libraries. See https://github.com/davisking/dlib/issues/923#issuecomment-2175865174
16 sse4Support ? stdenv.hostPlatform.sse4_1Support,
17 avxSupport ? stdenv.hostPlatform.avxSupport,
18 cudaSupport ? config.cudaSupport,
19 cudaPackages,
20}@inputs:
21(if cudaSupport then cudaPackages.backendStdenv else inputs.stdenv).mkDerivation rec {
22 pname = "dlib";
23 version = "20.0";
24
25 src = fetchFromGitHub {
26 owner = "davisking";
27 repo = "dlib";
28 tag = "v${version}";
29 sha256 = "sha256-VTX7s0p2AzlvPUsSMXwZiij+UY9g2y+a1YIge9bi0sw=";
30 };
31
32 postPatch = ''
33 rm -rf dlib/external
34 '';
35
36 cmakeFlags = [
37 (lib.cmakeBool "BUILD_SHARED_LIBS" enableShared)
38 (lib.cmakeBool "USE_SSE4_INSTRUCTIONS" sse4Support)
39 (lib.cmakeBool "USE_AVX_INSTRUCTIONS" avxSupport)
40 (lib.cmakeBool "DLIB_USE_CUDA" cudaSupport)
41 ]
42 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [
43 (lib.cmakeBool "USE_NEON_INSTRUCTIONS" false)
44 ]
45 ++ lib.optionals cudaSupport [
46 (lib.cmakeFeature "DLIB_USE_CUDA_COMPUTE_CAPABILITIES" (
47 builtins.concatStringsSep "," (with cudaPackages.flags; map dropDots cudaCapabilities)
48 ))
49 ];
50
51 nativeBuildInputs = [
52 cmake
53 pkg-config
54 ]
55 ++ lib.optionals cudaSupport (
56 with cudaPackages;
57 [
58 cuda_nvcc
59 ]
60 );
61
62 buildInputs = [
63 libpng
64 libjpeg
65 libwebp
66 blas
67 lapack
68 ]
69 ++ lib.optionals guiSupport [ libX11 ]
70 ++ lib.optionals cudaSupport (
71 with cudaPackages;
72 [
73 cuda_cudart
74 cuda_nvcc
75 libcublas
76 libcurand
77 libcusolver
78 cudnn
79 cuda_cccl
80 ]
81 );
82
83 passthru = {
84 inherit
85 cudaSupport
86 cudaPackages
87 sse4Support
88 avxSupport
89 ;
90 };
91
92 meta = with lib; {
93 description = "General purpose cross-platform C++ machine learning library";
94 homepage = "http://www.dlib.net";
95 license = licenses.boost;
96 maintainers = with maintainers; [ christopherpoole ];
97 platforms = platforms.unix;
98 };
99}