treewide: stdenv.is -> stdenv.hostPlatform.is (#356363)
[NixPkgs.git] / pkgs / development / libraries / imgui / default.nix
blob16f9976e2df5b0e28470e09141c8df03219e5a3e
2   stdenv,
3   lib,
4   applyPatches,
5   callPackage,
6   cmake,
7   fetchFromGitHub,
8   fetchpatch,
9   darwin,
10   glfw,
11   libGL,
12   SDL2,
13   vcpkg,
14   vulkan-headers,
15   vulkan-loader,
17   # NOTE: Not coming from vcpkg
18   IMGUI_LINK_GLVND ? !stdenv.hostPlatform.isWindows && (IMGUI_BUILD_OPENGL2_BINDING || IMGUI_BUILD_OPENGL3_BINDING),
20   # The intent is to mirror vcpkg's flags[^1],
21   # but we only actually support Linux and glfw3 until someone contributes the rest
22   # [^1]: https://github.com/microsoft/vcpkg/blob/095ee06e7f60dceef7d713e3f8b1c2eb10d650d7/ports/imgui/CMakeLists.txt#L33-L108
23   IMGUI_BUILD_ALLEGRO5_BINDING ? false,
24   IMGUI_BUILD_ANDROID_BINDING ? stdenv.hostPlatform.isAndroid,
25   IMGUI_BUILD_DX9_BINDING ? false,
26   IMGUI_BUILD_DX10_BINDING ? false,
27   IMGUI_BUILD_DX11_BINDING ? false,
28   IMGUI_BUILD_DX12_BINDING ? false,
29   IMGUI_BUILD_GLFW_BINDING ? !stdenv.hostPlatform.isDarwin,
30   IMGUI_BUILD_GLUT_BINDING ? false,
31   IMGUI_BUILD_METAL_BINDING ? stdenv.hostPlatform.isDarwin,
32   IMGUI_BUILD_OPENGL2_BINDING ? false,
33   IMGUI_BUILD_OPENGL3_BINDING ?
34     IMGUI_BUILD_SDL2_BINDING || IMGUI_BUILD_GLFW_BINDING || IMGUI_BUILD_GLUT_BINDING,
35   IMGUI_BUILD_OSX_BINDING ? stdenv.hostPlatform.isDarwin,
36   IMGUI_BUILD_SDL2_BINDING ?
37     !IMGUI_BUILD_GLFW_BINDING && !stdenv.hostPlatform.isDarwin,
38   IMGUI_BUILD_SDL2_RENDERER_BINDING ? IMGUI_BUILD_SDL2_BINDING,
39   IMGUI_BUILD_VULKAN_BINDING ? false,
40   IMGUI_BUILD_WIN32_BINDING ? false,
41   IMGUI_FREETYPE ? false,
42   IMGUI_FREETYPE_LUNASVG ? false,
43   IMGUI_USE_WCHAR32 ? false,
44 }@args:
46 let
47   vcpkgSource = applyPatches {
48     inherit (vcpkg) src;
49     patches = [
50       # Install imgui into split outputs:
51       (fetchpatch {
52         url = "https://github.com/microsoft/vcpkg/commit/4108dd75ce9731a4fdcf50fd05034405156eaddf.patch";
53         hash = "sha256-jXbR0NfyuO8EESmva5A+H3WmBfCG83OiA8ZCcWsRhQA=";
54       })
55     ];
56   };
59 stdenv.mkDerivation rec {
60   pname = "imgui";
61   version = "1.91.4";
62   outputs = [
63     # Note: no "dev" because vcpkg installs include/ and imgui-config.cmake
64     # into different prefixes but expects the merged layout at import time
65     "out"
66     "lib"
67   ];
69   src = fetchFromGitHub {
70     owner = "ocornut";
71     repo = "imgui";
72     rev = "refs/tags/v${version}";
73     hash = "sha256-6j4keBOAzbBDsV0+R4zTNlsltxz2dJDGI43UIrHXDNM=";
74   };
76   cmakeRules = "${vcpkgSource}/ports/imgui";
77   postPatch = ''
78     cp "$cmakeRules"/{CMakeLists.txt,*.cmake.in} ./
79   '';
81   nativeBuildInputs = [ cmake ];
83   buildInputs = lib.optionals stdenv.hostPlatform.isDarwin [
84     darwin.apple_sdk.frameworks.ApplicationServices
85     darwin.apple_sdk.frameworks.Cocoa
86     darwin.apple_sdk.frameworks.GameController
87   ];
89   propagatedBuildInputs =
90     lib.optionals IMGUI_LINK_GLVND [ libGL ]
91     ++ lib.optionals IMGUI_BUILD_GLFW_BINDING [ glfw ]
92     ++ lib.optionals IMGUI_BUILD_SDL2_BINDING [ SDL2 ]
93     ++ lib.optionals IMGUI_BUILD_VULKAN_BINDING [
94       vulkan-headers
95       vulkan-loader
96     ]
97     ++ lib.optionals IMGUI_BUILD_METAL_BINDING [ darwin.apple_sdk.frameworks.Metal ];
99   cmakeFlags = [
100     (lib.cmakeBool "IMGUI_BUILD_GLFW_BINDING" IMGUI_BUILD_GLFW_BINDING)
101     (lib.cmakeBool "IMGUI_BUILD_ALLEGRO5_BINDING" IMGUI_BUILD_ALLEGRO5_BINDING)
102     (lib.cmakeBool "IMGUI_BUILD_ANDROID_BINDING" IMGUI_BUILD_ANDROID_BINDING)
103     (lib.cmakeBool "IMGUI_BUILD_DX9_BINDING" IMGUI_BUILD_DX9_BINDING)
104     (lib.cmakeBool "IMGUI_BUILD_DX10_BINDING" IMGUI_BUILD_DX10_BINDING)
105     (lib.cmakeBool "IMGUI_BUILD_DX11_BINDING" IMGUI_BUILD_DX11_BINDING)
106     (lib.cmakeBool "IMGUI_BUILD_DX12_BINDING" IMGUI_BUILD_DX12_BINDING)
107     (lib.cmakeBool "IMGUI_BUILD_GLFW_BINDING" IMGUI_BUILD_GLFW_BINDING)
108     (lib.cmakeBool "IMGUI_BUILD_GLUT_BINDING" IMGUI_BUILD_GLUT_BINDING)
109     (lib.cmakeBool "IMGUI_BUILD_METAL_BINDING" IMGUI_BUILD_METAL_BINDING)
110     (lib.cmakeBool "IMGUI_BUILD_OPENGL2_BINDING" IMGUI_BUILD_OPENGL2_BINDING)
111     (lib.cmakeBool "IMGUI_BUILD_OPENGL3_BINDING" IMGUI_BUILD_OPENGL3_BINDING)
112     (lib.cmakeBool "IMGUI_BUILD_OSX_BINDING" IMGUI_BUILD_OSX_BINDING)
113     (lib.cmakeBool "IMGUI_BUILD_SDL2_BINDING" IMGUI_BUILD_SDL2_BINDING)
114     (lib.cmakeBool "IMGUI_BUILD_SDL2_RENDERER_BINDING" IMGUI_BUILD_SDL2_RENDERER_BINDING)
115     (lib.cmakeBool "IMGUI_BUILD_VULKAN_BINDING" IMGUI_BUILD_VULKAN_BINDING)
116     (lib.cmakeBool "IMGUI_BUILD_WIN32_BINDING" IMGUI_BUILD_WIN32_BINDING)
117     (lib.cmakeBool "IMGUI_FREETYPE" IMGUI_FREETYPE)
118     (lib.cmakeBool "IMGUI_FREETYPE_LUNASVG" IMGUI_FREETYPE_LUNASVG)
119     (lib.cmakeBool "IMGUI_USE_WCHAR32" IMGUI_USE_WCHAR32)
120   ];
122   passthru = {
123     tests = {
124       demo = callPackage ./demo { };
125     };
126   };
128   meta = {
129     # These flags haven't been tested:
130     broken =
131       IMGUI_FREETYPE
132       || IMGUI_FREETYPE_LUNASVG
133       || IMGUI_BUILD_DX9_BINDING
134       || IMGUI_BUILD_DX10_BINDING
135       || IMGUI_BUILD_DX11_BINDING
136       || IMGUI_BUILD_DX12_BINDING
137       || IMGUI_BUILD_WIN32_BINDING
138       || IMGUI_BUILD_ALLEGRO5_BINDING
139       || IMGUI_BUILD_ANDROID_BINDING;
140     description = "Bloat-free Graphical User interface for C++ with minimal dependencies";
141     homepage = "https://github.com/ocornut/imgui";
142     license = lib.licenses.mit; # vcpkg licensed as MIT too
143     maintainers = with lib.maintainers; [
144       SomeoneSerge
145     ];
146     platforms = lib.platforms.all;
147   };