linux_xanmod: 5.11.14 -> 5.11.15
[NixPkgs.git] / pkgs / development / libraries / qt-5 / modules / qtbase.nix
blob0d0bef342b02cee1cedcaeb9d4f165b507e93e77
2   stdenv, lib,
3   src, patches, version, qtCompatVersion,
5   coreutils, bison, flex, gdb, gperf, lndir, perl, pkg-config, python3,
6   which,
7   # darwin support
8   darwin, libiconv,
10   dbus, fontconfig, freetype, glib, harfbuzz, icu, libX11, libXcomposite,
11   libXcursor, libXext, libXi, libXrender, libinput, libjpeg, libpng,
12   libxcb, libxkbcommon, libxml2, libxslt, openssl, pcre16, pcre2, sqlite, udev,
13   xcbutil, xcbutilimage, xcbutilkeysyms, xcbutilrenderutil, xcbutilwm,
14   zlib,
16   # optional dependencies
17   cups ? null, libmysqlclient ? null, postgresql ? null,
18   withGtk3 ? false, dconf ? null, gtk3 ? null,
20   # options
21   libGLSupported ? !stdenv.isDarwin,
22   libGL,
23   buildExamples ? false,
24   buildTests ? false,
25   debug ? false,
26   developerBuild ? false,
27   decryptSslTraffic ? false
30 assert withGtk3 -> dconf != null;
31 assert withGtk3 -> gtk3 != null;
33 let
34   compareVersion = v: builtins.compareVersions version v;
35   qmakeCacheName =
36     if compareVersion "5.12.4" < 0 then ".qmake.cache" else ".qmake.stash";
37   debugSymbols = debug || developerBuild;
40 stdenv.mkDerivation {
42   name = "qtbase-${version}";
43   inherit qtCompatVersion src version;
44   debug = debugSymbols;
46   propagatedBuildInputs =
47     [
48       libxml2 libxslt openssl sqlite zlib
50       # Text rendering
51       harfbuzz icu
53       # Image formats
54       libjpeg libpng
55       (if compareVersion "5.9.0" < 0 then pcre16 else pcre2)
56     ]
57     ++ (
58       if stdenv.isDarwin
59       then with darwin.apple_sdk.frameworks;
60         [
61           # TODO: move to buildInputs, this should not be propagated.
62           AGL AppKit ApplicationServices Carbon Cocoa CoreAudio CoreBluetooth
63           CoreLocation CoreServices DiskArbitration Foundation OpenGL
64           darwin.libobjc libiconv MetalKit IOKit
65         ]
66       else
67         [
68           dbus glib udev
70           # Text rendering
71           fontconfig freetype
73           # X11 libs
74           libX11 libXcomposite libXext libXi libXrender libxcb libxkbcommon xcbutil
75           xcbutilimage xcbutilkeysyms xcbutilrenderutil xcbutilwm
76         ]
77         ++ lib.optional libGLSupported libGL
78     );
80   buildInputs =
81     [ python3 ]
82     ++ lib.optionals (!stdenv.isDarwin)
83     (
84       [ libinput ]
85       ++ lib.optional withGtk3 gtk3
86     )
87     ++ lib.optional developerBuild gdb
88     ++ lib.optional (cups != null) cups
89     ++ lib.optional (libmysqlclient != null) libmysqlclient
90     ++ lib.optional (postgresql != null) postgresql;
92   nativeBuildInputs =
93     [ bison flex gperf lndir perl pkg-config which ];
95   propagatedNativeBuildInputs = [ lndir ];
97   outputs = [ "bin" "dev" "out" ];
99   inherit patches;
101   fix_qt_builtin_paths = ../hooks/fix-qt-builtin-paths.sh;
102   fix_qt_module_paths = ../hooks/fix-qt-module-paths.sh;
103   preHook = ''
104     . "$fix_qt_builtin_paths"
105     . "$fix_qt_module_paths"
106     . ${../hooks/move-qt-dev-tools.sh}
107     . ${../hooks/fix-qmake-libtool.sh}
108   '';
110   postPatch =
111     ''
112       for prf in qml_plugin.prf qt_plugin.prf qt_docs.prf qml_module.prf create_cmake.prf; do
113           substituteInPlace "mkspecs/features/$prf" \
114               --subst-var qtPluginPrefix \
115               --subst-var qtQmlPrefix \
116               --subst-var qtDocPrefix
117       done
119       substituteInPlace configure --replace /bin/pwd pwd
120       substituteInPlace src/corelib/global/global.pri --replace /bin/ls ${coreutils}/bin/ls
121       sed -e 's@/\(usr\|opt\)/@/var/empty/@g' -i mkspecs/*/*.conf
123       sed -i '/PATHS.*NO_DEFAULT_PATH/ d' src/corelib/Qt5Config.cmake.in
124       sed -i '/PATHS.*NO_DEFAULT_PATH/ d' src/corelib/Qt5CoreMacros.cmake
125       sed -i 's/NO_DEFAULT_PATH//' src/gui/Qt5GuiConfigExtras.cmake.in
126       sed -i '/PATHS.*NO_DEFAULT_PATH/ d' mkspecs/features/data/cmake/Qt5BasicConfig.cmake.in
127     ''
129     + (
130       if stdenv.isDarwin
131       then
132         ''
133           sed -i \
134               -e 's|! /usr/bin/xcode-select --print-path >/dev/null 2>&1;|false;|' \
135               -e 's|! /usr/bin/xcrun -find xcodebuild >/dev/null 2>&1;|false;|' \
136               -e 's|sysroot=$(/usr/bin/xcodebuild -sdk $sdk -version Path 2>/dev/null)|sysroot=/nonsense|' \
137               -e 's|sysroot=$(/usr/bin/xcrun --sdk $sdk --show-sdk-path 2>/dev/null)|sysroot=/nonsense|' \
138               -e 's|QMAKE_CONF_COMPILER=`getXQMakeConf QMAKE_CXX`|QMAKE_CXX="clang++"\nQMAKE_CONF_COMPILER="clang++"|' \
139               -e 's|XCRUN=`/usr/bin/xcrun -sdk macosx clang -v 2>&1`|XCRUN="clang -v 2>&1"|' \
140               -e 's#sdk_val=$(/usr/bin/xcrun -sdk $sdk -find $(echo $val | cut -d \x27 \x27 -f 1))##' \
141               -e 's#val=$(echo $sdk_val $(echo $val | cut -s -d \x27 \x27 -f 2-))##' \
142               ./configure
143               substituteInPlace ./mkspecs/common/mac.conf \
144                   --replace "/System/Library/Frameworks/OpenGL.framework/" "${darwin.apple_sdk.frameworks.OpenGL}/Library/Frameworks/OpenGL.framework/"
145               substituteInPlace ./mkspecs/common/mac.conf \
146                   --replace "/System/Library/Frameworks/AGL.framework/" "${darwin.apple_sdk.frameworks.AGL}/Library/Frameworks/AGL.framework/"
147         ''
148         # Note on the above: \x27 is a way if including a single-quote
149         # character in the sed string arguments.
150       else
151         lib.optionalString libGLSupported
152           ''
153             sed -i mkspecs/common/linux.conf \
154                 -e "/^QMAKE_INCDIR_OPENGL/ s|$|${libGL.dev or libGL}/include|" \
155                 -e "/^QMAKE_LIBDIR_OPENGL/ s|$|${libGL.out}/lib|"
156           '' +
157         lib.optionalString (stdenv.hostPlatform.isx86_32 && stdenv.cc.isGNU)
158           ''
159             sed -i mkspecs/common/gcc-base-unix.conf \
160                 -e "/^QMAKE_LFLAGS_SHLIB/ s/-shared/-shared -static-libgcc/"
161           ''
162     );
164   qtPluginPrefix = "lib/qt-${qtCompatVersion}/plugins";
165   qtQmlPrefix = "lib/qt-${qtCompatVersion}/qml";
166   qtDocPrefix = "share/doc/qt-${qtCompatVersion}";
168   setOutputFlags = false;
169   preConfigure = ''
170     export LD_LIBRARY_PATH="$PWD/lib:$PWD/plugins/platforms''${LD_LIBRARY_PATH:+:}$LD_LIBRARY_PATH"
171     ${lib.optionalString (compareVersion "5.9.0" < 0) ''
172     # We need to set LD to CXX or otherwise we get nasty compile errors
173     export LD=$CXX
174     ''}
176     NIX_CFLAGS_COMPILE+=" -DNIXPKGS_QT_PLUGIN_PREFIX=\"$qtPluginPrefix\""
177   '';
179   postConfigure = ''
180     qmakeCacheInjectNixOutputs() {
181         local cache="$1/${qmakeCacheName}"
182         echo "qmakeCacheInjectNixOutputs: $cache"
183         if ! [ -f "$cache" ]; then
184             echo >&2 "qmakeCacheInjectNixOutputs: WARNING: $cache does not exist"
185         fi
186         cat >>"$cache" <<EOF
187     NIX_OUTPUT_BIN = $bin
188     NIX_OUTPUT_DEV = $dev
189     NIX_OUTPUT_OUT = $out
190     NIX_OUTPUT_DOC = $dev/$qtDocPrefix
191     NIX_OUTPUT_QML = $bin/$qtQmlPrefix
192     NIX_OUTPUT_PLUGIN = $bin/$qtPluginPrefix
193     EOF
194     }
196     find . -name '.qmake.conf' | while read conf; do
197         qmakeCacheInjectNixOutputs "$(dirname $conf)"
198     done
199   '';
201   NIX_CFLAGS_COMPILE = toString ([
202     "-Wno-error=sign-compare" # freetype-2.5.4 changed signedness of some struct fields
203     ''-DNIXPKGS_QTCOMPOSE="${libX11.out}/share/X11/locale"''
204     ''-D${if compareVersion "5.11.0" >= 0 then "LIBRESOLV_SO" else "NIXPKGS_LIBRESOLV"}="${stdenv.cc.libc.out}/lib/libresolv"''
205     ''-DNIXPKGS_LIBXCURSOR="${libXcursor.out}/lib/libXcursor"''
206   ] ++ lib.optional libGLSupported ''-DNIXPKGS_MESA_GL="${libGL.out}/lib/libGL"''
207     ++ lib.optionals withGtk3 [
208          ''-DNIXPKGS_QGTK3_XDG_DATA_DIRS="${gtk3}/share/gsettings-schemas/${gtk3.name}"''
209          ''-DNIXPKGS_QGTK3_GIO_EXTRA_MODULES="${dconf.lib}/lib/gio/modules"''
210        ]
211     ++ lib.optional decryptSslTraffic "-DQT_DECRYPT_SSL_TRAFFIC");
213   prefixKey = "-prefix ";
215   # PostgreSQL autodetection fails sporadically because Qt omits the "-lpq" flag
216   # if dependency paths contain the string "pq", which can occur in the hash.
217   # To prevent these failures, we need to override PostgreSQL detection.
218   PSQL_LIBS = lib.optionalString (postgresql != null) "-L${postgresql.lib}/lib -lpq";
220   # TODO Remove obsolete and useless flags once the build will be totally mastered
221   configureFlags =
222     [
223       "-plugindir $(out)/$(qtPluginPrefix)"
224       "-qmldir $(out)/$(qtQmlPrefix)"
225       "-docdir $(out)/$(qtDocPrefix)"
227       "-verbose"
228       "-confirm-license"
229       "-opensource"
231       "-release"
232       "-shared"
233       "-accessibility"
234       "-optimized-qmake"
235       "-strip"
236       "-system-proxies"
237       "-pkg-config"
239       "-gui"
240       "-widgets"
241       "-opengl desktop"
242       "-icu"
243       "-L" "${icu.out}/lib"
244       "-I" "${icu.dev}/include"
245       "-pch"
246     ]
247     ++ lib.optional debugSymbols "-debug"
248     ++ lib.optionals (compareVersion "5.11.0" < 0)
249     [
250       "-qml-debug"
251     ]
252     ++ lib.optionals (compareVersion "5.9.0" < 0)
253     [
254       "-c++11"
255       "-no-reduce-relocations"
256     ]
257     ++ lib.optionals developerBuild [
258       "-developer-build"
259       "-no-warnings-are-errors"
260     ]
261     ++ (
262       if (!stdenv.hostPlatform.isx86_64) then [
263         "-no-sse2"
264       ] else if (compareVersion "5.9.0" >= 0) then [
265         "-sse2"
266         "${if stdenv.hostPlatform.sse3Support   then "" else "-no"}-sse3"
267         "${if stdenv.hostPlatform.ssse3Support  then "" else "-no"}-ssse3"
268         "${if stdenv.hostPlatform.sse4_1Support then "" else "-no"}-sse4.1"
269         "${if stdenv.hostPlatform.sse4_2Support then "" else "-no"}-sse4.2"
270         "${if stdenv.hostPlatform.avxSupport    then "" else "-no"}-avx"
271         "${if stdenv.hostPlatform.avx2Support   then "" else "-no"}-avx2"
272       ] else [
273       ]
274     )
275     ++ [
276       "-no-mips_dsp"
277       "-no-mips_dspr2"
278     ]
280     ++ [
281       "-system-zlib"
282       "-L" "${zlib.out}/lib"
283       "-I" "${zlib.dev}/include"
284       "-system-libjpeg"
285       "-L" "${libjpeg.out}/lib"
286       "-I" "${libjpeg.dev}/include"
287       "-system-harfbuzz"
288       "-L" "${harfbuzz.out}/lib"
289       "-I" "${harfbuzz.dev}/include"
290       "-system-pcre"
291       "-openssl-linked"
292       "-L" "${openssl.out}/lib"
293       "-I" "${openssl.dev}/include"
294       "-system-sqlite"
295       ''-${if libmysqlclient != null then "plugin" else "no"}-sql-mysql''
296       ''-${if postgresql != null then "plugin" else "no"}-sql-psql''
298       "-make libs"
299       "-make tools"
300       ''-${lib.optionalString (!buildExamples) "no"}make examples''
301       ''-${lib.optionalString (!buildTests) "no"}make tests''
302     ]
303     ++ lib.optional (compareVersion "5.15.0" < 0) "-v"
305     ++ (
306       if stdenv.isDarwin
307       then
308         [
309           "-platform macx-clang"
310           "-no-fontconfig"
311           "-qt-freetype"
312           "-qt-libpng"
313           "-no-framework"
314         ]
315       else
316         [
317           "-${lib.optionalString (compareVersion "5.9.0" < 0) "no-"}rpath"
318         ]
319         ++ lib.optional (compareVersion "5.15.0" < 0) "-system-xcb"
320         ++ [
321           "-xcb"
322           "-qpa xcb"
323           "-L" "${libX11.out}/lib"
324           "-I" "${libX11.out}/include"
325           "-L" "${libXext.out}/lib"
326           "-I" "${libXext.out}/include"
327           "-L" "${libXrender.out}/lib"
328           "-I" "${libXrender.out}/include"
330           "-libinput"
332           ''-${lib.optionalString (cups == null) "no-"}cups''
333           "-dbus-linked"
334           "-glib"
335         ]
336         ++ lib.optional (compareVersion "5.15.0" < 0) "-system-libjpeg"
337         ++ [
338           "-system-libpng"
339         ]
340         ++ lib.optional withGtk3 "-gtk"
341         ++ lib.optional (compareVersion "5.9.0" >= 0) "-inotify"
342         ++ lib.optionals (compareVersion "5.10.0" >= 0) [
343           # Without these, Qt stops working on kernels < 3.17. See:
344           # https://github.com/NixOS/nixpkgs/issues/38832
345           "-no-feature-renameat2"
346           "-no-feature-getentropy"
347         ]
348         ++ lib.optionals (compareVersion "5.12.1" < 0) [
349           # use -xkbcommon and -xkbcommon-evdev for versions before 5.12.1
350           "-system-xkbcommon"
351           "-xkbcommon-evdev"
352         ]
353         ++ lib.optionals (cups != null) [
354           "-L" "${cups.lib}/lib"
355           "-I" "${cups.dev}/include"
356         ]
357         ++ lib.optionals (libmysqlclient != null) [
358           "-L" "${libmysqlclient}/lib"
359           "-I" "${libmysqlclient}/include"
360         ]
361     );
363   postInstall =
364     # Move selected outputs.
365     ''
366       moveToOutput "mkspecs" "$dev"
367     '';
369   devTools = [
370     "bin/fixqt4headers.pl"
371     "bin/moc"
372     "bin/qdbuscpp2xml"
373     "bin/qdbusxml2cpp"
374     "bin/qlalr"
375     "bin/qmake"
376     "bin/rcc"
377     "bin/syncqt.pl"
378     "bin/uic"
379   ];
381   postFixup =
382     # Don't retain build-time dependencies like gdb.
383     ''
384       sed '/QMAKE_DEFAULT_.*DIRS/ d' -i $dev/mkspecs/qconfig.pri
385     ''
387     + ''
388       fixQtModulePaths "''${!outputDev}/mkspecs/modules"
389       fixQtBuiltinPaths "''${!outputDev}" '*.pr?'
390     ''
392     # Move development tools to $dev
393     + ''
394       moveQtDevTools
395       moveToOutput bin "$dev"
396     ''
398     # fixup .pc file (where to find 'moc' etc.)
399     + ''
400       sed -i "$dev/lib/pkgconfig/Qt5Core.pc" \
401           -e "/^host_bins=/ c host_bins=$dev/bin"
402     '';
404   dontStrip = debugSymbols;
406   setupHook = ../hooks/qtbase-setup-hook.sh;
408   meta = with lib; {
409     homepage = "http://www.qt.io";
410     description = "A cross-platform application framework for C++";
411     license = with licenses; [ fdl13 gpl2 lgpl21 lgpl3 ];
412     maintainers = with maintainers; [ qknight ttuegel periklis bkchr ];
413     platforms = platforms.unix;
414     broken = stdenv.isDarwin && (compareVersion "5.9.0" < 0);
415   };