From 7744998f04bc7b174baf80c7bd56917639bb169c Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Sat, 12 Oct 2019 12:47:55 -0500 Subject: [PATCH] qtbase: Set cmakeFlags and NIX_CFLAGS_COMPILE in setupHook --- .../libraries/qt-5/5.12/default.nix | 2 +- .../libraries/qt-5/5.14/default.nix | 2 +- .../libraries/qt-5/hooks/qtbase-setup-hook.sh | 37 +++++++++++++++++++ .../libraries/qt-5/mkDerivation.nix | 10 ----- .../libraries/qt-5/modules/qtbase.nix | 2 + 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 a092d7a78fb5..e55b66d626a7 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 9c88a405d77c..7be507992759 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 9f2a9f06f1ab..6ea18426af3d 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 3d711e5033d4..ba66dc89edee 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 24f1d6f81a24..e3dcc499a21d 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 = [