Skip to content

Commit

Permalink
πŸ› support nix-darwin and qt6 on macos (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
OlivierLDff authored Jan 5, 2025
1 parent 82a3b30 commit 089a96a
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 47 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ set(QATERIALHOTRELOAD_ENABLE_HOTRELOAD_APP ${QATERIALHOTRELOAD_MAIN_PROJECT} CAC
set(QATERIALHOTRELOAD_IGNORE_ENV OFF CACHE BOOL "Ignore qt environment variables")

set(QATERIALHOTRELOAD_ENABLE_APPIMAGE ON CACHE BOOL "Enable AppImage building")
set(QATERIALHOTRELOAD_ENABLE_DMG ON CACHE BOOL "Enable Dmg building")
set(QATERIALHOTRELOAD_ENABLE_CHARTS ON CACHE BOOL "Enable Qt::Charts")
set(QATERIALHOTRELOAD_ENABLE_DATAVIZ ON CACHE BOOL "Enable Qt::DataVisualization")
set(QATERIALHOTRELOAD_ENABLE_VIRTUALKEYBOARD ON CACHE BOOL "Enable Qt::VirtualKeyboard")
Expand Down Expand Up @@ -202,6 +203,10 @@ if(QATERIALHOTRELOAD_ENABLE_HOTRELOAD_APP)
qt_add_library(${QATERIALHOTRELOAD_APP} SHARED ${QATERIALHOTRELOAD_APP_SRCS})
else()
qt_add_executable(${QATERIALHOTRELOAD_APP} ${QATERIALHOTRELOAD_APP_SRCS})

if(APPLE)
set_target_properties(${QATERIALHOTRELOAD_APP} PROPERTIES MACOSX_BUNDLE TRUE)
endif()
endif()

target_link_libraries(${QATERIALHOTRELOAD_APP}
Expand Down
2 changes: 1 addition & 1 deletion cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ set(QBC_REPOSITORY "https://github.com/OlivierLdff/QBCInstaller.git" CACHE STRIN
set(QBC_TAG "965118e5570da9bcc53662abc8c0525f04751c89" CACHE STRING "QBC git tag")

set(QTMACCMAKE_REPOSITORY "https://github.com/OlivierLDff/QtMacCMake.git" CACHE STRING "QtMacCMake repository, can be a local URL")
set(QTMACCMAKE_TAG "a398dd9c529aeda674fd63af747d84e0752732fd" CACHE STRING "QtMacCMake git tag")
set(QTMACCMAKE_TAG "v1.1.1" CACHE STRING "QtMacCMake git tag")

## CMake Resources scripts

Expand Down
16 changes: 8 additions & 8 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 43 additions & 37 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
inputs.nixpkgs.follows = "nixpkgs";
};
qolm = {
url = "github:olivierldff/qolm/v3.2.2";
url = "github:olivierldff/qolm/v3.2.3";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.nix-filter.follows = "nix-filter";
};
qaterial = {
url = "github:olivierldff/qaterial/v1.5.0";
url = "github:olivierldff/qaterial/v1.5.2";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
inputs.nix-filter.follows = "nix-filter";
Expand Down Expand Up @@ -47,7 +47,7 @@
};

qt = pkgs.qt6;
nixglhost = nix-gl-host.packages.${system}.default;
nixglhost = if pkgs.stdenv.isLinux then nix-gl-host.packages.${system}.default else null;

nativeBuildInputs = with pkgs; [
qt.wrapQtAppsHook
Expand All @@ -74,11 +74,6 @@
qtshadertools
]);

nativeCheckInputs = with pkgs; [
dbus
xvfb-run
];

shellHook = ''
# Crazy shell hook to set up Qt environment, from:
# https://discourse.nixos.org/t/python-qt-woes/11808/12
Expand All @@ -96,8 +91,12 @@
CPM_USE_LOCAL_PACKAGES = "ON";
version = import ./nix/get-project-version.nix { file = ./cmake/Version.cmake; prefix = "QATERIALHOTRELOAD"; };

outFolder = if pkgs.stdenv.isLinux then "bin" else if pkgs.stdenv.isDarwin then "Applications" else throw "Unsupported system: ${pkgs.stdenv.system}";
outApp = if pkgs.stdenv.isLinux then "QaterialHotReloadApp" else if pkgs.stdenv.isDarwin then "QaterialHotReloadApp.app" else throw "Unsupported system: ${pkgs.stdenv.system}";
outAppExe = if pkgs.stdenv.isLinux then outApp else if pkgs.stdenv.isDarwin then "${outApp}/Contents/MacOS/QaterialHotReloadApp" else throw "Unsupported system: ${pkgs.stdenv.system}";

qaterialHotReloadApp = pkgs.stdenv.mkDerivation rec {
inherit version nativeBuildInputs buildInputs nativeCheckInputs;
inherit version nativeBuildInputs buildInputs;
inherit CPM_USE_LOCAL_PACKAGES;
propagatedBuildInputs = buildInputs;

Expand All @@ -115,6 +114,7 @@

cmakeFlags = [
(pkgs.lib.strings.cmakeBool "QATERIALHOTRELOAD_ENABLE_APPIMAGE" false)
(pkgs.lib.strings.cmakeBool "QATERIALHOTRELOAD_ENABLE_DMG" false)
(pkgs.lib.strings.cmakeBool "QATERIALHOTRELOAD_USE_LOCAL_CPM_FILE" true)
"-GNinja"
];
Expand Down Expand Up @@ -144,8 +144,12 @@
runHook preInstall
echo "Installing qaterialhotreloadapp version ${version} in ${cmakeConfigType} mode into $out"
mkdir -p $out/bin
cp -r QaterialHotReloadApp $out/bin
mkdir -p $out/${outFolder}
cp -r ${outApp} $out/${outFolder}
${pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
mkdir -p $out/bin
ln -s $out/${outFolder}/${outAppExe} $out/bin/qaterialhotreloadapp
''}
runHook postInstall
'';
Expand All @@ -157,62 +161,65 @@
echo "Run shell hook"
${shellHook}
xvfb-run dbus-run-session \
--config-file=${pkgs.dbus}/share/dbus-1/session.conf \
$out/bin/QaterialHotReloadApp --help
export QT_QPA_PLATFORM=offscreen
$out/${outFolder}/${outAppExe} --help
runHook postInstallCheck
'';
};

qaterialHotReloadAppGlHost = pkgs.stdenv.mkDerivation {
pname = "qaterialHotReloadAppGlHost";
inherit version;
qaterialHotReloadAppGlHost =
if pkgs.stdenv.isLinux then
(pkgs.stdenv.mkDerivation {
pname = "qaterialHotReloadAppGlHost";
inherit version;

dontUnpack = true;
dontUnpack = true;

installPhase = ''
mkdir -p $out/bin
cat > $out/bin/qaterialHotReloadAppGlHost <<EOF
#!${pkgs.bash}/bin/bash
exec ${nixglhost}/bin/nixglhost ${packages.qaterialHotReloadApp}/bin/QaterialHotReloadApp -- \$@
EOF
chmod +x $out/bin/qaterialHotReloadAppGlHost
'';
};
installPhase = ''
mkdir -p $out/bin
cat > $out/bin/qaterialHotReloadAppGlHost <<EOF
#!${pkgs.bash}/bin/bash
exec ${nixglhost}/bin/nixglhost ${packages.qaterialHotReloadApp}/bin/QaterialHotReloadApp -- \$@
EOF
chmod +x $out/bin/qaterialHotReloadAppGlHost
'';
}) else null;

packages = {
inherit qaterialHotReloadApp qaterialHotReloadAppGlHost;
inherit qaterialHotReloadApp;
default = qaterialHotReloadApp;
deadnix = pkgs.runCommand "deadnix" { } ''
${pkgs.deadnix}/bin/deadnix --fail ${./.}
mkdir $out
'';
};
} // (
if pkgs.stdenv.isLinux then { inherit qaterialHotReloadAppGlHost; } else { }
);

apps = {
qaterialHotReloadApp = flake-utils.lib.mkApp {
drv = packages.qaterialHotReloadApp;
};
qaterialHotReloadAppGlHost = flake-utils.lib.mkApp {
drv = packages.qaterialHotReloadAppGlHost;
};
default = apps.qaterialHotReloadApp;
};
} // (
if pkgs.stdenv.isLinux then {
qaterialHotReloadAppGlHost = flake-utils.lib.mkApp {
drv = packages.qaterialHotReloadAppGlHost;
};
} else { }
);

minimalDevBuildInputs = with pkgs; [
gh
];
fullDevBuildInputs = with pkgs; nativeBuildInputs
++ nativeCheckInputs
++ minimalDevBuildInputs
++ [
sccache
nixpkgs-fmt
cmake-format
clang-tools
lazygit
neovim
nixglhost
]
++ (with pkgs.qt6; [ qtlanguageserver ])
Expand All @@ -232,7 +239,6 @@
inherit CPM_USE_LOCAL_PACKAGES;

nativeBuildInputs = nativeBuildInputs
++ nativeCheckInputs
++ minimalDevBuildInputs;
};

Expand Down
2 changes: 1 addition & 1 deletion platforms/Deploy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ endif()

# ──── MACOS ────

if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin")
if(${CMAKE_SYSTEM_NAME} STREQUAL "Darwin" AND QATERIALHOTRELOAD_ENABLE_DMG)

if(NOT QATERIALHOTRELOAD_BUILD_SHARED)

Expand Down

0 comments on commit 089a96a

Please sign in to comment.