3 src, patches, version, qtCompatVersion,
5 coreutils, bison, flex, gdb, gperf, lndir, perl, pkg-config, python3,
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,
16 # optional dependencies
17 cups ? null, libmysqlclient ? null, postgresql ? null,
18 withGtk3 ? false, dconf ? null, gtk3 ? null,
21 libGLSupported ? !stdenv.isDarwin,
23 buildExamples ? false,
26 developerBuild ? false,
27 decryptSslTraffic ? false
30 assert withGtk3 -> dconf != null;
31 assert withGtk3 -> gtk3 != null;
34 compareVersion = v: builtins.compareVersions version v;
36 if compareVersion "5.12.4" < 0 then ".qmake.cache" else ".qmake.stash";
37 debugSymbols = debug || developerBuild;
42 name = "qtbase-${version}";
43 inherit qtCompatVersion src version;
46 propagatedBuildInputs =
48 libxml2 libxslt openssl sqlite zlib
55 (if compareVersion "5.9.0" < 0 then pcre16 else pcre2)
59 then with darwin.apple_sdk.frameworks;
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
74 libX11 libXcomposite libXext libXi libXrender libxcb libxkbcommon xcbutil
75 xcbutilimage xcbutilkeysyms xcbutilrenderutil xcbutilwm
77 ++ lib.optional libGLSupported libGL
82 ++ lib.optionals (!stdenv.isDarwin)
85 ++ lib.optional withGtk3 gtk3
87 ++ lib.optional developerBuild gdb
88 ++ lib.optional (cups != null) cups
89 ++ lib.optional (libmysqlclient != null) libmysqlclient
90 ++ lib.optional (postgresql != null) postgresql;
93 [ bison flex gperf lndir perl pkg-config which ];
95 propagatedNativeBuildInputs = [ lndir ];
97 outputs = [ "bin" "dev" "out" ];
101 fix_qt_builtin_paths = ../hooks/fix-qt-builtin-paths.sh;
102 fix_qt_module_paths = ../hooks/fix-qt-module-paths.sh;
104 . "$fix_qt_builtin_paths"
105 . "$fix_qt_module_paths"
106 . ${../hooks/move-qt-dev-tools.sh}
107 . ${../hooks/fix-qmake-libtool.sh}
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
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
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-))##' \
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/"
148 # Note on the above: \x27 is a way if including a single-quote
149 # character in the sed string arguments.
151 lib.optionalString libGLSupported
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|"
157 lib.optionalString (stdenv.hostPlatform.isx86_32 && stdenv.cc.isGNU)
159 sed -i mkspecs/common/gcc-base-unix.conf \
160 -e "/^QMAKE_LFLAGS_SHLIB/ s/-shared/-shared -static-libgcc/"
164 qtPluginPrefix = "lib/qt-${qtCompatVersion}/plugins";
165 qtQmlPrefix = "lib/qt-${qtCompatVersion}/qml";
166 qtDocPrefix = "share/doc/qt-${qtCompatVersion}";
168 setOutputFlags = false;
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
176 NIX_CFLAGS_COMPILE+=" -DNIXPKGS_QT_PLUGIN_PREFIX=\"$qtPluginPrefix\""
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"
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
196 find . -name '.qmake.conf' | while read conf; do
197 qmakeCacheInjectNixOutputs "$(dirname $conf)"
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"''
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
223 "-plugindir $(out)/$(qtPluginPrefix)"
224 "-qmldir $(out)/$(qtQmlPrefix)"
225 "-docdir $(out)/$(qtDocPrefix)"
243 "-L" "${icu.out}/lib"
244 "-I" "${icu.dev}/include"
247 ++ lib.optional debugSymbols "-debug"
248 ++ lib.optionals (compareVersion "5.11.0" < 0)
252 ++ lib.optionals (compareVersion "5.9.0" < 0)
255 "-no-reduce-relocations"
257 ++ lib.optionals developerBuild [
259 "-no-warnings-are-errors"
262 if (!stdenv.hostPlatform.isx86_64) then [
264 ] else if (compareVersion "5.9.0" >= 0) then [
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"
282 "-L" "${zlib.out}/lib"
283 "-I" "${zlib.dev}/include"
285 "-L" "${libjpeg.out}/lib"
286 "-I" "${libjpeg.dev}/include"
288 "-L" "${harfbuzz.out}/lib"
289 "-I" "${harfbuzz.dev}/include"
292 "-L" "${openssl.out}/lib"
293 "-I" "${openssl.dev}/include"
295 ''-${if libmysqlclient != null then "plugin" else "no"}-sql-mysql''
296 ''-${if postgresql != null then "plugin" else "no"}-sql-psql''
300 ''-${lib.optionalString (!buildExamples) "no"}make examples''
301 ''-${lib.optionalString (!buildTests) "no"}make tests''
303 ++ lib.optional (compareVersion "5.15.0" < 0) "-v"
309 "-platform macx-clang"
317 "-${lib.optionalString (compareVersion "5.9.0" < 0) "no-"}rpath"
319 ++ lib.optional (compareVersion "5.15.0" < 0) "-system-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"
332 ''-${lib.optionalString (cups == null) "no-"}cups''
336 ++ lib.optional (compareVersion "5.15.0" < 0) "-system-libjpeg"
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"
348 ++ lib.optionals (compareVersion "5.12.1" < 0) [
349 # use -xkbcommon and -xkbcommon-evdev for versions before 5.12.1
353 ++ lib.optionals (cups != null) [
354 "-L" "${cups.lib}/lib"
355 "-I" "${cups.dev}/include"
357 ++ lib.optionals (libmysqlclient != null) [
358 "-L" "${libmysqlclient}/lib"
359 "-I" "${libmysqlclient}/include"
364 # Move selected outputs.
366 moveToOutput "mkspecs" "$dev"
370 "bin/fixqt4headers.pl"
382 # Don't retain build-time dependencies like gdb.
384 sed '/QMAKE_DEFAULT_.*DIRS/ d' -i $dev/mkspecs/qconfig.pri
388 fixQtModulePaths "''${!outputDev}/mkspecs/modules"
389 fixQtBuiltinPaths "''${!outputDev}" '*.pr?'
392 # Move development tools to $dev
395 moveToOutput bin "$dev"
398 # fixup .pc file (where to find 'moc' etc.)
400 sed -i "$dev/lib/pkgconfig/Qt5Core.pc" \
401 -e "/^host_bins=/ c host_bins=$dev/bin"
404 dontStrip = debugSymbols;
406 setupHook = ../hooks/qtbase-setup-hook.sh;
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);