about summary refs log tree commit diff
diff options
context:
space:
mode:
authorThomas Tuegel <ttuegel@mailbox.org>2019-10-12 12:47:55 -0500
committerThomas Tuegel <ttuegel@mailbox.org>2021-01-25 15:56:05 -0600
commit7744998f04bc7b174baf80c7bd56917639bb169c (patch)
tree1dcb8fa7f19728a1ca26c3dd2252dda07a3627b1
parentb80ce0aecaa1a233d69f3e169ad28c09146c2676 (diff)
qtbase: Set cmakeFlags and NIX_CFLAGS_COMPILE in setupHook
-rw-r--r--pkgs/development/libraries/qt-5/5.12/default.nix2
-rw-r--r--pkgs/development/libraries/qt-5/5.14/default.nix2
-rw-r--r--pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh37
-rw-r--r--pkgs/development/libraries/qt-5/mkDerivation.nix10
-rw-r--r--pkgs/development/libraries/qt-5/modules/qtbase.nix2
5 files changed, 41 insertions, 12 deletions
diff --git a/pkgs/development/libraries/qt-5/5.12/default.nix b/pkgs/development/libraries/qt-5/5.12/default.nix
index a092d7a78fb58..e55b66d626a7b 100644
--- a/pkgs/development/libraries/qt-5/5.12/default.nix
+++ b/pkgs/development/libraries/qt-5/5.12/default.nix
@@ -145,7 +145,7 @@ let
         patches = patches.qtbase;
         inherit bison cups harfbuzz libGL;
         withGtk3 = true; inherit dconf gtk3;
-        inherit developerBuild decryptSslTraffic;
+        inherit debug developerBuild decryptSslTraffic;
       };
 
       qtcharts = callPackage ../modules/qtcharts.nix {};
diff --git a/pkgs/development/libraries/qt-5/5.14/default.nix b/pkgs/development/libraries/qt-5/5.14/default.nix
index 9c88a405d77c1..7be5079927595 100644
--- a/pkgs/development/libraries/qt-5/5.14/default.nix
+++ b/pkgs/development/libraries/qt-5/5.14/default.nix
@@ -149,7 +149,7 @@ let
         patches = patches.qtbase;
         inherit bison cups harfbuzz libGL;
         withGtk3 = true; inherit dconf gtk3;
-        inherit developerBuild decryptSslTraffic;
+        inherit debug developerBuild decryptSslTraffic;
       };
 
       qtcharts = callPackage ../modules/qtcharts.nix {};
diff --git a/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh b/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh
index 9f2a9f06f1aba..6ea18426af3dd 100644
--- a/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh
+++ b/pkgs/development/libraries/qt-5/hooks/qtbase-setup-hook.sh
@@ -1,3 +1,14 @@
+if [[ -n "${__nix_qtbase-}" ]]; then
+    # Throw an error if a different version of Qt was already set up.
+    if [[ "$__nix_qtbase" != "@dev@" ]]; then
+        echo >&2 "Error: detected mismatched Qt dependencies:"
+        echo >&2 "    @dev@"
+        echo >&2 "    $__nix_qtbase"
+        exit 1
+    fi
+else # Only set up Qt once.
+__nix_qtbase="@dev@"
+
 qtPluginPrefix=@qtPluginPrefix@
 qtQmlPrefix=@qtQmlPrefix@
 qtDocPrefix=@qtDocPrefix@
@@ -5,6 +16,20 @@ qtDocPrefix=@qtDocPrefix@
 . @fix_qt_builtin_paths@
 . @fix_qt_module_paths@
 
+# Disable debug symbols if qtbase was built without debugging.
+# This stops -dev paths from leaking into other outputs.
+if [ -z "@debug@" ]; then
+    NIX_CFLAGS_COMPILE="${NIX_CFLAGS_COMPILE-}${NIX_CFLAGS_COMPILE:+ }-DQT_NO_DEBUG"
+fi
+
+# Integration with CMake:
+# Set the CMake build type corresponding to how qtbase was built.
+if [ -n "@debug@" ]; then
+    cmakeBuildType="Debug"
+else
+    cmakeBuildType="Release"
+fi
+
 providesQtRuntime() {
     [ -d "$1/$qtPluginPrefix" ] || [ -d "$1/$qtQmlPrefix" ]
 }
@@ -19,7 +44,12 @@ export QMAKEPATH
 QMAKEMODULES=
 export QMAKEMODULES
 
+declare -Ag qmakePathSeen=()
 qmakePathHook() {
+    # Skip this path if we have seen it before.
+    # MUST use 'if' because 'qmakePathSeen[$]' may be unset.
+    if [ -n "${qmakePathSeen[$1]-}" ]; then return; fi
+    qmakePathSeen[$1]=1
     if [ -d "$1/mkspecs" ]
     then
         QMAKEMODULES="${QMAKEMODULES}${QMAKEMODULES:+:}/mkspecs"
@@ -34,7 +64,12 @@ envBuildHostHooks+=(qmakePathHook)
 # package depending on the building package. (This is necessary in case
 # the building package does not provide runtime dependencies itself and so
 # would not be propagated to the user environment.)
+declare -Ag qtEnvHostTargetSeen=()
 qtEnvHostTargetHook() {
+    # Skip this path if we have seen it before.
+    # MUST use 'if' because 'qmakePathSeen[$]' may be unset.
+    if [ -n "${qtEnvHostTargetSeen[$1]-}" ]; then return; fi
+    qtEnvHostTargetSeen[$1]=1
     if providesQtRuntime "$1" && [ "z${!outputBin}" != "z${!outputDev}" ]
     then
         propagatedBuildInputs+=" $1"
@@ -64,3 +99,5 @@ postPatchMkspecs() {
 if [ -z "${dontPatchMkspecs-}" ]; then
     postPhases="${postPhases-}${postPhases:+ }postPatchMkspecs"
 fi
+
+fi
diff --git a/pkgs/development/libraries/qt-5/mkDerivation.nix b/pkgs/development/libraries/qt-5/mkDerivation.nix
index 3d711e5033d47..ba66dc89edee3 100644
--- a/pkgs/development/libraries/qt-5/mkDerivation.nix
+++ b/pkgs/development/libraries/qt-5/mkDerivation.nix
@@ -9,16 +9,6 @@ args:
 let
   args_ = {
 
-    NIX_CFLAGS_COMPILE = toString (
-      optional (!debug) "-DQT_NO_DEBUG"
-      ++ lib.toList (args.NIX_CFLAGS_COMPILE or []));
-
-    cmakeFlags =
-      (args.cmakeFlags or [])
-      ++ [
-        ("-DCMAKE_BUILD_TYPE=" + (if debug then "Debug" else "Release"))
-      ];
-
     enableParallelBuilding = args.enableParallelBuilding or true;
 
     nativeBuildInputs = (args.nativeBuildInputs or []) ++ [ wrapQtAppsHook ];
diff --git a/pkgs/development/libraries/qt-5/modules/qtbase.nix b/pkgs/development/libraries/qt-5/modules/qtbase.nix
index 24f1d6f81a24b..e3dcc499a21d9 100644
--- a/pkgs/development/libraries/qt-5/modules/qtbase.nix
+++ b/pkgs/development/libraries/qt-5/modules/qtbase.nix
@@ -22,6 +22,7 @@
   libGL,
   buildExamples ? false,
   buildTests ? false,
+  debug ? false,
   developerBuild ? false,
   decryptSslTraffic ? false
 }:
@@ -39,6 +40,7 @@ stdenv.mkDerivation {
 
   name = "qtbase-${version}";
   inherit qtCompatVersion src version;
+  inherit debug;
 
   propagatedBuildInputs =
     [