Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkgs/development/libraries/qt-6/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ let
withGtk3 = true;
inherit (srcs.qtbase) src version;
inherit bison cups harfbuzz libGL dconf gtk3 developerBuild cmake;
patches = [
./patches/qtbase-qmake-pkg-config.patch
];
};

qt3d = callPackage ./modules/qt3d.nix { };
Expand Down Expand Up @@ -90,6 +93,14 @@ let
wrapQtAppsHook = makeSetupHook {
deps = [ buildPackages.makeWrapper ];
} ./hooks/wrap-qt-apps-hook.sh;

qmake = makeSetupHook {
deps = [ self.qtbase.dev ];
substitutions = {
inherit debug;
fix_qmake_libtool = ./hooks/fix-qmake-libtool.sh;
};
} ./hooks/qmake-hook.sh;
};

self = lib.makeScope newScope addPackages;
Expand Down
25 changes: 25 additions & 0 deletions pkgs/development/libraries/qt-6/hooks/fix-qmake-libtool.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Fix libtool libraries generated by qmake.
# qmake started inserting filenames of shared objects instead of the appropriate
# linker flags. fixQmakeLibtool searches for broken libtool libraries and
# replaces the filenames with the linker flags that should have been there.
fixQmakeLibtool() {
if [ -d "$1" ]; then
find "$1" -name '*.la' | while read la; do
set +e
framework_libs=$(grep '^dependency_libs' "$la" | grep -Eo -- '-framework +\w+' | tr '\n' ' ')
set -e
sed -i "$la" \
-e '/^dependency_libs/ s,\(/[^ ]\+\)/lib\([^/ ]\+\)\.so,-L\1 -l\2,g' \
-e '/^dependency_libs/ s,-framework \+\w\+,,g'
if [ ! -z "$framework_libs" ]; then
if grep '^inherited_linker_flags=' $la >/dev/null; then
sed -i "$la" -e "s/^\(inherited_linker_flags='[^']*\)/\1 $framework_libs/"
else
echo "inherited_linker_flags='$framework_libs'" >>"$la"
fi
fi
done
fi
}

fixupOutputHooks+=('fixQmakeLibtool $prefix')
66 changes: 66 additions & 0 deletions pkgs/development/libraries/qt-6/hooks/fix-qt-builtin-paths.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# fixQtBuiltinPaths
#
# Usage: fixQtBuiltinPaths _dir_ _pattern_
#
# Fix Qt builtin paths in files matching _pattern_ under _dir_.
#
fixQtBuiltinPaths() {
local dir="$1"
local pattern="$2"
local bin="${!outputBin}"
local dev="${!outputDev}"
local doc="${!outputDoc}"
local lib="${!outputLib}"

if [ -d "$dir" ]; then
find "$dir" -name "$pattern" | while read pr_; do
if grep -q '\$\$\[QT_' "${pr_:?}"; then
echo "fixQtBuiltinPaths: Fixing Qt builtin paths in \`${pr_:?}'..."
sed -i "${pr_:?}" \
-e "s|\\\$\\\$\\[QT_HOST_BINS[^]]*\\]|$dev/bin|g" \
-e "s|\\\$\\\$\\[QT_HOST_LIBEXECS[^]]*\\]|$dev/libexec|g" \
-e "s|\\\$\\\$\\[QT_HOST_DATA[^]]*\\]/mkspecs|$dev/mkspecs|g" \
-e "s|\\\$\\\$\\[QT_HOST_PREFIX[^]]*\\]|$dev|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_ARCHDATA[^]]*\\]|$lib|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_BINS[^]]*\\]|$bin/bin|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_CONFIGURATION[^]]*\\]|$bin|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_DATA[^]]*\\]|$lib|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_DOCS[^]]*\\]|$doc/share/doc|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_EXAMPLES[^]]*\\]|$doc/examples|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_HEADERS[^]]*\\]|$dev/include|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_LIBS[^]]*\\]|$lib/lib|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_LIBEXECS[^]]*\\]|$lib/libexec|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_PLUGINS[^]]*\\]|$bin/$qtPluginPrefix|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_PREFIX[^]]*\\]|$lib|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_TESTS[^]]*\\]|$dev/tests|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_TRANSLATIONS[^]]*\\]|$lib/translations|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_QML[^]]*\\]|$bin/$qtQmlPrefix|g"
fi
done
elif [ -e "$dir" ]; then
if grep -q '\$\$\[QT_' "${dir:?}"; then
echo "fixQtBuiltinPaths: Fixing Qt builtin paths in \`${dir:?}'..."
sed -i "${dir:?}" \
-e "s|\\\$\\\$\\[QT_HOST_BINS[^]]*\\]|$dev/bin|g" \
-e "s|\\\$\\\$\\[QT_HOST_LIBEXECS[^]]*\\]|$dev/libexec|g" \
-e "s|\\\$\\\$\\[QT_HOST_DATA[^]]*\\]/mkspecs|$dev/mkspecs|g" \
-e "s|\\\$\\\$\\[QT_HOST_PREFIX[^]]*\\]|$dev|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_ARCHDATA[^]]*\\]|$lib|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_BINS[^]]*\\]|$bin/bin|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_CONFIGURATION[^]]*\\]|$bin|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_DATA[^]]*\\]|$lib|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_DOCS[^]]*\\]|$doc/share/doc|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_EXAMPLES[^]]*\\]|$doc/examples|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_HEADERS[^]]*\\]|$dev/include|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_LIBS[^]]*\\]|$lib/lib|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_LIBEXECS[^]]*\\]|$lib/libexec|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_PLUGINS[^]]*\\]|$bin/$qtPluginPrefix|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_PREFIX[^]]*\\]|$lib|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_TESTS[^]]*\\]|$dev/tests|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_TRANSLATIONS[^]]*\\]|$lib/translations|g" \
-e "s|\\\$\\\$\\[QT_INSTALL_QML[^]]*\\]|$bin/$qtQmlPrefix|g"
fi
else
echo "fixQtBuiltinPaths: Warning: \`$dir' does not exist"
fi
}
36 changes: 36 additions & 0 deletions pkgs/development/libraries/qt-6/hooks/fix-qt-module-paths.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# fixQtModulePaths
#
# Usage: fixQtModulePaths _dir_
#
# Find Qt module definitions in directory _dir_ and patch the module paths.
#
fixQtModulePaths() {
local dir="$1"
local bin="${!outputBin}"
local dev="${!outputDev}"
local lib="${!outputLib}"

if [ -d "$dir" ]; then
find "$dir" -name 'qt_*.pri' | while read pr; do
if grep -q '\$\$QT_MODULE_' "${pr:?}"; then
echo "fixQtModulePaths: Fixing module paths in \`${pr:?}'..."
sed -i "${pr:?}" \
-e "s|\\\$\\\$QT_MODULE_LIB_BASE|$lib/lib|g" \
-e "s|\\\$\\\$QT_MODULE_HOST_LIB_BASE|$lib/lib|g" \
-e "s|\\\$\\\$QT_MODULE_INCLUDE_BASE|$dev/include|g" \
-e "s|\\\$\\\$QT_MODULE_BIN_BASE|$dev/bin|g"
fi
done
elif [ -e "$dir" ]; then
echo "fixQtModulePaths: Warning: \`$dir' is not a directory"
else
echo "fixQtModulePaths: Warning: \`$dir' does not exist"
fi

if [ "z$bin" != "z$dev" ]; then
if [ -d "$bin/bin" ]; then
mkdir -p "$dev/bin"
lndir -silent "$bin/bin" "$dev/bin"
fi
fi
}
34 changes: 34 additions & 0 deletions pkgs/development/libraries/qt-6/hooks/move-qt-dev-tools.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
updateToolPath() {
local tool="$1"
local target="$2"
local original="${!outputBin}/$tool"
local actual="${!outputDev}/$tool"
if grep -q "$original" "$target"; then
echo "updateToolPath: Updating \`$original' in \`$target\'..."
sed -i "$target" -e "s|$original|$actual|"
fi
}

moveQtDevTools() {
if [ -n "$devTools" ]; then
for tool in $devTools; do
moveToOutput "$tool" "${!outputDev}"
done

if [ -d "${!outputDev}/mkspecs" ]; then
find "${!outputDev}/mkspecs" -name '*.pr?' | while read pr_; do
for tool in $devTools; do
updateToolPath "$tool" "$pr_"
done
done
fi

if [ -d "${!outputDev}/lib/cmake" ]; then
find "${!outputDev}/lib/cmake" -name '*.cmake' | while read cmake; do
for tool in $devTools; do
updateToolPath "$tool" "$cmake"
done
done
fi
fi
}
48 changes: 48 additions & 0 deletions pkgs/development/libraries/qt-6/hooks/qmake-hook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
. @fix_qmake_libtool@

qmakeFlags=(${qmakeFlags-})

qmakePrePhase() {
qmakeFlags_orig=("${qmakeFlags[@]}")

# These flags must be added _before_ the flags specified in the derivation.
# TODO: these flags also need a patch which isn't applied
# can we either remove these flags or update the qt5 patch?
# "NIX_OUTPUT_DOC=${!outputDev}/${qtDocPrefix:?}" \
qmakeFlags=(
"PREFIX=$out"
"NIX_OUTPUT_OUT=$out"
"NIX_OUTPUT_DEV=${!outputDev}"
"NIX_OUTPUT_BIN=${!outputBin}"
"NIX_OUTPUT_QML=${!outputBin}/${qtQmlPrefix:?}"
"NIX_OUTPUT_PLUGIN=${!outputBin}/${qtPluginPrefix:?}"
)

if [ -n "@debug@" ]; then
qmakeFlags+=("CONFIG+=debug")
else
qmakeFlags+=("CONFIG+=release")
fi

qmakeFlags+=("${qmakeFlags_orig[@]}")
}
prePhases+=" qmakePrePhase"

qmakeConfigurePhase() {
runHook preConfigure

echo "QMAKEPATH=$QMAKEPATH"
echo qmake "${qmakeFlags[@]}"
qmake "${qmakeFlags[@]}"

if ! [[ -v enableParallelBuilding ]]; then
enableParallelBuilding=1
echo "qmake: enabled parallel building"
fi

runHook postConfigure
}

if [ -z "${dontUseQmakeConfigure-}" -a -z "${configurePhase-}" ]; then
configurePhase=qmakeConfigurePhase
fi
102 changes: 76 additions & 26 deletions pkgs/development/libraries/qt-6/hooks/qtbase-setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,87 @@ if [[ -n "${__nix_qtbase-}" ]]; then
exit 1
fi
else # Only set up Qt once.
__nix_qtbase="@dev@"
__nix_qtbase="@dev@"

qtPluginPrefix=@qtPluginPrefix@
qtQmlPrefix=@qtQmlPrefix@
qtPluginPrefix=@qtPluginPrefix@
qtQmlPrefix=@qtQmlPrefix@

# 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
. @fix_qt_builtin_paths@
. @fix_qt_module_paths@

# Integration with CMake:
# Set the CMake build type corresponding to how qtbase was built.
if [ -n "@debug@" ]; then
cmakeBuildType="Debug"
else
cmakeBuildType="Release"
fi
# 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

qtPreHook() {
# Check that wrapQtAppsHook is used, or it is explicitly disabled.
if [[ -z "$__nix_wrapQtAppsHook" && -z "$dontWrapQtApps" ]]; then
echo >&2 "Error: wrapQtAppsHook is not used, and dontWrapQtApps is not set."
exit 1
# Integration with CMake:
# Set the CMake build type corresponding to how qtbase was built.
if [ -n "@debug@" ]; then
cmakeBuildType="Debug"
else
cmakeBuildType="Release"
fi

# Build tools are often confused if QMAKE is unset.
export QMAKE=@dev@/bin/qmake

export QMAKEPATH=

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"
QMAKEPATH="${QMAKEPATH}${QMAKEPATH:+:}$1"
fi
}
envBuildHostHooks+=(qmakePathHook)

postPatchMkspecs() {
# Prevent this hook from running multiple times
dontPatchMkspecs=1

local bin="${!outputBin}"
local dev="${!outputDev}"
local doc="${!outputDoc}"
local lib="${!outputLib}"

moveToOutput "mkspecs" "$dev"

if [ -d "$dev/mkspecs/modules" ]; then
fixQtModulePaths "$dev/mkspecs/modules"
fi

if [ -d "$dev/mkspecs" ]; then
fixQtBuiltinPaths "$dev/mkspecs" '*.pr?'
fi

if [ -d "$lib" ]; then
fixQtBuiltinPaths "$lib" '*.pr?'
fi
}
if [ -z "${dontPatchMkspecs-}" ]; then
postPhases="${postPhases-}${postPhases:+ }postPatchMkspecs"
fi
}
prePhases+=" qtPreHook"

addQtModulePrefix () {
addToSearchPath QT_ADDITIONAL_PACKAGES_PREFIX_PATH $1
}
addEnvHooks "$hostOffset" addQtModulePrefix
qtPreHook() {
# Check that wrapQtAppsHook is used, or it is explicitly disabled.
if [[ -z "$__nix_wrapQtAppsHook" && -z "$dontWrapQtApps" ]]; then
echo >&2 "Error: wrapQtAppsHook is not used, and dontWrapQtApps is not set."
exit 1
fi
}
prePhases+=" qtPreHook"

addQtModulePrefix() {
addToSearchPath QT_ADDITIONAL_PACKAGES_PREFIX_PATH $1
}
addEnvHooks "$hostOffset" addQtModulePrefix

fi
Loading