summaryrefslogtreecommitdiff
path: root/pkgs/development/libraries/qt-6/modules/qtbase/default.nix
blob: 9329008e29a638d0f543c9d9f139c841c48872f4 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
{
  stdenv,
  lib,
  src,
  version,
  bison,
  flex,
  gperf,
  lndir,
  perl,
  pkg-config,
  which,
  cmake,
  ninja,
  xmlstarlet,
  libproxy,
  xorg,
  zstd,
  double-conversion,
  util-linux,
  systemd,
  systemdSupport ? stdenv.hostPlatform.isLinux,
  libb2,
  md4c,
  mtdev,
  lksctp-tools,
  libselinux,
  libsepol,
  vulkan-headers,
  vulkan-loader,
  libthai,
  libdrm,
  libdatrie,
  lttng-ust,
  libepoxy,
  dbus,
  fontconfig,
  freetype,
  glib,
  harfbuzz,
  icu,
  libX11,
  libXcomposite,
  libXext,
  libXi,
  libXrender,
  libjpeg,
  libpng,
  libxcb,
  libxkbcommon,
  libxml2,
  libxslt,
  openssl,
  pcre,
  pcre2,
  sqlite,
  udev,
  xcbutil,
  xcbutilimage,
  xcbutilkeysyms,
  xcbutilrenderutil,
  xcbutilwm,
  zlib,
  at-spi2-core,
  unixODBC,
  unixODBCDrivers,
  libGL,
  # darwin
  moltenvk,
  moveBuildTree,
  darwinVersionInputs,
  xcbuild,
  # mingw
  pkgsBuildBuild,
  # optional dependencies
  cups,
  libmysqlclient,
  libpq,
  withGtk3 ? false,
  gtk3,
  withLibinput ? false,
  libinput,
  # options
  qttranslations ? null,
  fetchpatch,
}:

let
  isCrossBuild = !stdenv.buildPlatform.canExecute stdenv.hostPlatform;
in
stdenv.mkDerivation rec {
  pname = "qtbase";

  inherit src version;

  propagatedBuildInputs =
    [
      libxml2
      libxslt
      openssl
      sqlite
      zlib
      libGL
      vulkan-headers
      vulkan-loader
      # Text rendering
      harfbuzz
      icu
      # Image formats
      libjpeg
      libpng
      pcre2
      pcre
      zstd
      libb2
      md4c
      double-conversion
    ]
    ++ lib.optionals (!stdenv.hostPlatform.isMinGW) [
      libproxy
      dbus
      glib
      # unixODBC drivers
      unixODBC
      unixODBCDrivers.psql
      unixODBCDrivers.sqlite
      unixODBCDrivers.mariadb
    ]
    ++ lib.optionals systemdSupport [
      systemd
    ]
    ++ lib.optionals stdenv.hostPlatform.isLinux [
      util-linux
      mtdev
      lksctp-tools
      libselinux
      libsepol
      lttng-ust
      libthai
      libdrm
      libdatrie
      udev
      # Text rendering
      fontconfig
      freetype
      # X11 libs
      libX11
      libXcomposite
      libXext
      libXi
      libXrender
      libxcb
      libxkbcommon
      xcbutil
      xcbutilimage
      xcbutilkeysyms
      xcbutilrenderutil
      xcbutilwm
      xorg.libXdmcp
      xorg.libXtst
      xorg.xcbutilcursor
      libepoxy
    ]
    ++ lib.optional (cups != null && lib.meta.availableOn stdenv.hostPlatform cups) cups;

  buildInputs =
    lib.optionals (lib.meta.availableOn stdenv.hostPlatform at-spi2-core) [
      at-spi2-core
    ]
    ++ lib.optionals stdenv.hostPlatform.isDarwin (darwinVersionInputs ++ [ moltenvk ])
    ++ lib.optional withGtk3 gtk3
    ++ lib.optional withLibinput libinput
    ++ lib.optional (libmysqlclient != null && !stdenv.hostPlatform.isMinGW) libmysqlclient
    ++ lib.optional (libpq != null && lib.meta.availableOn stdenv.hostPlatform libpq) libpq;

  nativeBuildInputs = [
    bison
    flex
    gperf
    lndir
    perl
    pkg-config
    which
    cmake
    xmlstarlet
    ninja
  ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ moveBuildTree ];

  propagatedNativeBuildInputs =
    [ lndir ]
    # I’m not sure if this is necessary, but the macOS mkspecs stuff
    # tries to call `xcrun xcodebuild`, so better safe than sorry.
    ++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild ];

  strictDeps = true;

  enableParallelBuilding = true;

  patches = [
    # look for Qt plugins in directories on PATH
    ./derive-plugin-load-path-from-PATH.patch

    # allow translations to be found outside of install prefix, as is the case in our split builds
    ./allow-translations-outside-prefix.patch

    # always link to libraries by name in qmake-generated build scripts
    ./qmake-always-use-libname.patch
    # always explicitly list includedir in qmake-generated pkg-config files
    ./qmake-fix-includedir.patch

    # don't generate SBOM files by default, they don't work with our split installs anyway
    ./no-sbom.patch

    # use cmake from PATH in qt-cmake wrapper, to avoid qtbase runtime-depending on cmake
    ./use-cmake-from-path.patch

    # macdeployqt fixes
    # get qmlimportscanner location from environment variable
    ./find-qmlimportscanner.patch
    # pass QML2_IMPORT_PATH from environment to qmlimportscanner
    ./qmlimportscanner-import-path.patch
    # don't pass qtbase's QML directory to qmlimportscanner if it's empty
    ./skip-missing-qml-directory.patch
  ];

  postPatch = lib.optionalString stdenv.hostPlatform.isDarwin ''
    # TODO: Verify that this catches all the occurrences?
    for file in \
      cmake/QtPublicAppleHelpers.cmake \
      mkspecs/features/mac/asset_catalogs.prf \
      mkspecs/features/mac/default_pre.prf \
      mkspecs/features/mac/sdk.mk \
      mkspecs/features/mac/sdk.prf \
      mkspecs/features/permissions.prf \
      src/corelib/Qt6CoreMacros.cmake
    do
      substituteInPlace "$file" \
        --replace-quiet /usr/bin/xcrun '${lib.getExe' xcbuild "xcrun"}' \
        --replace-quiet /usr/bin/xcode-select '${lib.getExe' xcbuild "xcode-select"}' \
        --replace-quiet /usr/libexec/PlistBuddy '${lib.getExe' xcbuild "PlistBuddy"}'
    done

    substituteInPlace mkspecs/common/macx.conf \
      --replace-fail 'CONFIG += ' 'CONFIG += no_default_rpath '
  '';

  fix_qt_builtin_paths = ../../hooks/fix-qt-builtin-paths.sh;
  fix_qt_module_paths = ../../hooks/fix-qt-module-paths.sh;
  preHook = ''
    . "$fix_qt_builtin_paths"
    . "$fix_qt_module_paths"
  '';

  qtPluginPrefix = "lib/qt-6/plugins";
  qtQmlPrefix = "lib/qt-6/qml";

  cmakeFlags =
    [
      "-DQT_EMBED_TOOLCHAIN_COMPILER=OFF"
      "-DINSTALL_PLUGINSDIR=${qtPluginPrefix}"
      "-DINSTALL_QMLDIR=${qtQmlPrefix}"
      "-DQT_FEATURE_libproxy=ON"
      "-DQT_FEATURE_system_sqlite=ON"
      "-DQT_FEATURE_openssl_linked=ON"
      "-DQT_FEATURE_vulkan=ON"
    ]
    ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
      "-DQT_FEATURE_sctp=ON"
      "-DQT_FEATURE_journald=${if systemdSupport then "ON" else "OFF"}"
    ]
    ++ lib.optionals stdenv.hostPlatform.isDarwin [
      "-DQT_FEATURE_rpath=OFF"
      "-DQT_NO_XCODE_MIN_VERSION_CHECK=ON"
    ]
    ++ lib.optionals isCrossBuild [
      "-DQT_HOST_PATH=${pkgsBuildBuild.qt6.qtbase}"
      "-DQt6HostInfo_DIR=${pkgsBuildBuild.qt6.qtbase}/lib/cmake/Qt6HostInfo"
    ]
    ++ lib.optional (
      qttranslations != null && !isCrossBuild
    ) "-DINSTALL_TRANSLATIONSDIR=${qttranslations}/translations";

  env.NIX_CFLAGS_COMPILE = "-DNIXPKGS_QT_PLUGIN_PREFIX=\"${qtPluginPrefix}\"";

  outputs = [
    "out"
    "dev"
  ];
  separateDebugInfo = true;

  moveToDev = false;

  postFixup =
    ''
      moveToOutput      "mkspecs/modules" "$dev"
      fixQtModulePaths  "$dev/mkspecs/modules"
      fixQtBuiltinPaths "$out" '*.pr?'
    ''
    + lib.optionalString stdenv.hostPlatform.isLinux ''
      # FIXME: not sure why this isn't added automatically?
      patchelf --add-rpath "${libmysqlclient}/lib/mariadb" $out/${qtPluginPrefix}/sqldrivers/libqsqlmysql.so
      patchelf --add-rpath "${vulkan-loader}/lib" --add-needed "libvulkan.so" $out/lib/libQt6Gui.so
    '';

  dontWrapQtApps = true;

  setupHook = ../../hooks/qtbase-setup-hook.sh;

  meta = with lib; {
    homepage = "https://www.qt.io/";
    description = "Cross-platform application framework for C++";
    license = with licenses; [
      fdl13Plus
      gpl2Plus
      lgpl21Plus
      lgpl3Plus
    ];
    maintainers = with maintainers; [
      nickcao
      LunNova
    ];
    platforms = platforms.unix ++ platforms.windows;
  };
}