Skip to content

Commit

Permalink
Merge pull request #60 from kambala-decapitator/windows-msvc
Browse files Browse the repository at this point in the history
[Windows] add MSVC support
  • Loading branch information
CvH authored Feb 24, 2024
2 parents b57d5b3 + 2612498 commit a12fa15
Show file tree
Hide file tree
Showing 12 changed files with 2,627 additions and 48 deletions.
44 changes: 43 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,57 @@ jobs:
platform: macos
preset: release-macos
artifact: '*.dmg'
- os: windows-latest
platform: windows-msvc
preset: release-msvc
artifact: '*.Win32.exe'
useQtAction: true
- os: windows-latest
platform: windows-mingw
preset: release-ninja
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup
shell: bash
run: |
ci/${{ matrix.platform }}/setup.sh
setupScript='ci/${{ matrix.platform }}/setup.sh'
[ ! -f "$setupScript" ] || "$setupScript"
env:
MACOS_ASC_API_KEY: ${{ secrets.MACOS_ASC_API_KEY }}
MACOS_CODE_SIGN_KEY_BASE64: ${{ secrets.MACOS_CODE_SIGN_KEY_BASE64 }}
MACOS_KEYCHAIN_PASSWORD: ${{ secrets.MACOS_KEYCHAIN_PASSWORD }}
- name: Install Qt
uses: jurplel/install-qt-action@v3
if: ${{ matrix.useQtAction }}
with:
version: '6.6.2'
arch: 'win64_msvc2019_64'
archives: 'qtbase qttools opengl32sw d3dcompiler_47'
extra: '--external 7z'
cache: true
setup-python: false
- name: Prepare MSVC environment
uses: ilammy/msvc-dev-cmd@v1
if: ${{ matrix.platform == 'windows-msvc' }}
with:
arch: x64
toolset: 14.29
- name: Setup msys2
uses: msys2/setup-msys2@v2
if: ${{ matrix.platform == 'windows-mingw' }}
with:
update: true
install: >-
mingw-w64-x86_64-cmake
mingw-w64-x86_64-gcc
mingw-w64-x86_64-ninja
mingw-w64-x86_64-qt6-base
mingw-w64-x86_64-qt6-tools
- name: Put MSYS2_MinGW64 on PATH
if: ${{ matrix.platform == 'windows-mingw' }}
run: |
echo "${{ runner.temp }}/msys64/mingw64/bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Configure
run: |
cmake --preset ${{ matrix.preset || 'release' }}
Expand All @@ -44,3 +85,4 @@ jobs:
with:
path: build/${{ matrix.artifact }}
name: ${{ matrix.platform }}
compression-level: 0
98 changes: 72 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,31 @@ set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_AUTOUIC ON)

find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
include(GNUInstallDirs)
# GNU dirs must be adjusted before finding Qt for qt_deploy_runtime_dependencies to use customzied vars
if(WIN32)
set(CMAKE_INSTALL_BINDIR .)
endif()

# options
if(WIN32)
option(DUMMY_WRITE "Write image to local file named 'dummy_image_file' instead to real device (for testing)")
endif()

# dependencies
find_package(QT NAMES Qt6 REQUIRED COMPONENTS Core)
set(qtComponents Gui Network Widgets LinguistTools)
if(LINUX)
list(APPEND qtComponents DBus)
endif()
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS ${qtComponents})

if(MSVC_TOOLSET_VERSION EQUAL 142)
list(APPEND CMAKE_PREFIX_PATH "windows/msvc2019/zlib")
endif()
find_package(ZLIB REQUIRED)

# executable
qt_add_executable(LibreELEC.USB-SD.Creator WIN32 MACOSX_BUNDLE
creator.cpp creator.h creator.ui
deviceenumerator.h
Expand Down Expand Up @@ -58,7 +75,7 @@ target_link_libraries(LibreELEC.USB-SD.Creator PUBLIC
Qt${QT_VERSION_MAJOR}::Gui
Qt${QT_VERSION_MAJOR}::Network
Qt${QT_VERSION_MAJOR}::Widgets
z
ZLIB::ZLIB
)

string(TIMESTAMP nowDateTime UTC)
Expand All @@ -67,6 +84,7 @@ target_compile_definitions(LibreELEC.USB-SD.Creator PRIVATE
"BUILD_VERSION=\"${PROJECT_VERSION}\""
"COPYRIGHT_YEARS=\"${copyrightYears}\""
$<$<CONFIG:Debug>:ALWAYS_DEBUG_OUTPUT>
$<$<BOOL:${DUMMY_WRITE}>:WINDOWS_DUMMY_WRITE>
)

qt_add_translations(LibreELEC.USB-SD.Creator
Expand Down Expand Up @@ -107,6 +125,12 @@ qt_add_translations(LibreELEC.USB-SD.Creator
)

if(WIN32)
if(MSVC)
set_target_properties(LibreELEC.USB-SD.Creator PROPERTIES
LINK_OPTIONS "/MANIFEST:NO" # disable default manifest
)
endif()

target_sources(LibreELEC.USB-SD.Creator PUBLIC
deviceenumerator_windows.cpp deviceenumerator_windows.h
diskwriter_windows.cpp diskwriter_windows.h
Expand All @@ -115,6 +139,14 @@ if(WIN32)
)

configure_file("windows/winapp.rc.in" "${CMAKE_SOURCE_DIR}/windows/winapp.rc" @ONLY)

set(qtDeployExecutable "$<TARGET_FILE_NAME:LibreELEC.USB-SD.Creator>")
set(qtDeployExtraCommands "
# windeployqt also packages extra libs that aren't needed
foreach(dll in Qt${QT_VERSION_MAJOR}Svg opengl32sw D3Dcompiler_47)
file(REMOVE \"\\\${QT_DEPLOY_PREFIX}/\\\${QT_DEPLOY_BIN_DIR}/\\\${dll}.dll\")
endforeach()
")
elseif(APPLE)
set_target_properties(LibreELEC.USB-SD.Creator PROPERTIES
OUTPUT_NAME "${projectDisplayName}"
Expand All @@ -126,32 +158,24 @@ elseif(APPLE)
privileges_unix.cpp privileges_unix.h
)

set(bundleContentsDir "$<TARGET_BUNDLE_CONTENT_DIR:LibreELEC.USB-SD.Creator>")
install(FILES "dmg_osx/icon.icns"
DESTINATION "${bundleContentsDir}/Resources"
DESTINATION "$<TARGET_BUNDLE_CONTENT_DIR:LibreELEC.USB-SD.Creator>/Resources"
)

qt_generate_deploy_script(
TARGET LibreELEC.USB-SD.Creator
OUTPUT_SCRIPT qtDeployScript
CONTENT "
qt_deploy_runtime_dependencies(
EXECUTABLE \"$<TARGET_BUNDLE_DIR:LibreELEC.USB-SD.Creator>\"
GENERATE_QT_CONF
NO_APP_STORE_COMPLIANCE
VERBOSE
)
# macdeployqt also packages extra frameworks that aren't needed
foreach(qtModule in Pdf Svg)
file(REMOVE_RECURSE \"${bundleContentsDir}/Frameworks/Qt\\\${qtModule}.framework\")
endforeach()
# codesign
execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/dmg_osx/codesign.sh\"
WORKING_DIRECTORY \"${bundleContentsDir}\"
)
")
install(SCRIPT ${qtDeployScript})
set(qtDeployExecutable "$<TARGET_FILE_NAME:LibreELEC.USB-SD.Creator>.app")
set(qtDeployExtraCommands "
set(bundleContentsDir \"\\\${QT_DEPLOY_PREFIX}/${qtDeployExecutable}/Contents\")
# macdeployqt also packages extra frameworks that aren't needed
foreach(qtModule in Pdf Svg)
file(REMOVE_RECURSE \"\\\${bundleContentsDir}/Frameworks/Qt\\\${qtModule}.framework\")
endforeach()
# codesign
execute_process(COMMAND \"${CMAKE_SOURCE_DIR}/dmg_osx/codesign.sh\"
WORKING_DIRECTORY \"\\\${bundleContentsDir}\"
)
")
elseif(LINUX)
set_target_properties(LibreELEC.USB-SD.Creator PROPERTIES SUFFIX .Linux.bin)

Expand All @@ -166,15 +190,37 @@ elseif(LINUX)
)
endif()

# install
install(TARGETS LibreELEC.USB-SD.Creator
BUNDLE
DESTINATION .
)
if(qtDeployExecutable)
qt_generate_deploy_script(
TARGET LibreELEC.USB-SD.Creator
OUTPUT_SCRIPT qtDeployScript
CONTENT "
qt_deploy_runtime_dependencies(
EXECUTABLE \"${qtDeployExecutable}\"
GENERATE_QT_CONF
NO_APP_STORE_COMPLIANCE
NO_COMPILER_RUNTIME
NO_TRANSLATIONS
VERBOSE
)
${qtDeployExtraCommands}
"
)
install(SCRIPT ${qtDeployScript})
endif()

# cpack
set(CPACK_PACKAGE_NAME "${projectDisplayName}")
set(CPACK_PACKAGE_VENDOR "LibreELEC")
if(APPLE)
if(WIN32)
set(CPACK_PACKAGE_FILE_NAME "LibreELEC.USB-SD.Creator.Win32")
set(CPACK_GENERATOR INNOSETUP)
elseif(APPLE)
set(CPACK_PACKAGE_FILE_NAME "LibreELEC.USB-SD.Creator.macOS")

set(notarizeScript "${CMAKE_BINARY_DIR}/notarize.cmake")
Expand Down
13 changes: 11 additions & 2 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
}
},
{
"name": "release-macos",
"name": "release-ninja",
"inherits": "release",
"generator": "Ninja",
"generator": "Ninja"
},
{
"name": "release-macos",
"inherits": "release-ninja",
"cacheVariables": {
"CMAKE_OSX_ARCHITECTURES": "x86_64;arm64",
"CMAKE_OSX_DEPLOYMENT_TARGET": "11.0"
}
},
{
"name": "release-msvc",
"inherits": "release",
"generator": "NMake Makefiles"
}
],
"buildPresets": [
Expand Down
2 changes: 1 addition & 1 deletion diskwriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <QStringList>
#include <QByteArray>

#include "zlib.h"
#include <zlib.h>

class DiskWriter : public QObject
{
Expand Down
3 changes: 2 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ void noMessageOutput(QtMsgType type, const QMessageLogContext &context, const QS

int main(int argc, char *argv[])
{
qputenv("QT_QPA_PLATFORM", "windows:darkmode=0");
QApplication app(argc, argv);

const auto cmdArgs = app.arguments();
Expand Down Expand Up @@ -88,7 +89,7 @@ int main(int argc, char *argv[])
}
}

Privileges privileges = Privileges();
Privileges privileges;
privileges.Whoami();

QString argFile;
Expand Down
4 changes: 2 additions & 2 deletions privileges.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
#ifndef PRIVILEGES_H
#define PRIVILEGES_H

#include <QString>

class Privileges {
public:
Privileges() {}
void SetRoot() {}
void SetUser() {}
void SetRealUser() {}
void Whoami() {}
void SaveUserEnv(pid_t) {}
QString GetUserEnvDbusSession()
{
return QString();
Expand Down
2 changes: 0 additions & 2 deletions translator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ void Translator::fillLanguages(QMenu *menuPtr, QPushButton *langBtnPtr)
QStringList qmFiles;
// languages from resources
qmFiles << QDir(":/lang").entryList(QStringList("*.qm"));
// languages from a local disk (mostly for testing purposes)
qmFiles << QDir(".").entryList(QStringList("*.qm"));

// add menu entry for all the files
QList<QAction *> actions;
Expand Down
Loading

0 comments on commit a12fa15

Please sign in to comment.