Skip to content
Open
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
60 changes: 60 additions & 0 deletions cntp-appicontool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ int main(int argc, char* argv[]) {
{"r", "output-rc"},
"Qt Resource output file", "rc-output"
});
parser.addOption({
{"p", "output-png"},
"PNG output file", "png-output"
});
parser.addOption({
{"w", "output-msix"},
"MSIX PNG output files", "msix-output"
});
parser.addOption({
{"b", "blueprint"},
"Create Blueprint style icon"
Expand Down Expand Up @@ -175,5 +183,57 @@ int main(int argc, char* argv[]) {
rcFile.close();
}

if (parser.isSet("output-png")) {
eoutput << "Creating PNG icon";
CombinedIcon pngIcon;
pngIcon.setBaseIcon(CombinedIcon::PlatformSpecificIcon);
pngIcon.setIconGradientColors(color1, color2);
pngIcon.setGenerateBlueprintIcon(parser.isSet("blueprint"));
pngIcon.setOverlayIcon(overlayIcon);
pngIcon.setOverlayIconMac(overlayIconMac);

QSize size(256, 256);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should generate all the right sizes and assets according to https://learn.microsoft.com/en-us/windows/apps/design/style/iconography/app-icon-construction. We also need to make sure that the sizing is correct


QImage image(size, QImage::Format_ARGB32);
image.fill(Qt::transparent);

QPainter imagePainter(&image);

QSvgRenderer renderer(pngIcon.generatedIcon().toUtf8());
renderer.render(&imagePainter, QRect(QPoint(0, 0), size));
imagePainter.end();

image.save(parser.value("output-png"), "PNG");
}

if (parser.isSet("output-msix")) {
eoutput << "Creating MSIX icons";

QDir msixDir(parser.value("output-msix"));

QDir::root().mkpath(msixDir.path());

CombinedIcon pngIcon;
pngIcon.setBaseIcon(CombinedIcon::PlatformSpecificIcon);
pngIcon.setIconGradientColors(color1, color2);
pngIcon.setGenerateBlueprintIcon(parser.isSet("blueprint"));
pngIcon.setOverlayIcon(overlayIcon);
pngIcon.setOverlayIconMac(overlayIconMac);

for (auto width : QList<int> {30, 44, 70, 71, 150, 310}) {
QSize size{width, width};
QImage image(size, QImage::Format_ARGB32);
image.fill(Qt::transparent);

QPainter imagePainter(&image);

QSvgRenderer renderer(pngIcon.generatedIcon().toUtf8());
renderer.render(&imagePainter, QRect(QPoint(0, 0), size));
imagePainter.end();

image.save(msixDir.absoluteFilePath(QStringLiteral("msix-%1.png").arg(size.width())), "PNG");
}
}

return 0;
}
19 changes: 17 additions & 2 deletions cntp-windeploy/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QProcess>
#include "deployfolder.h"
#include "common.h"
#include "systemlibrarydatabase.h"
Expand All @@ -14,6 +15,11 @@ int main(int argc, char** argv) {
parser.addOption({{"q", "qt-path"}, "Path to Qt installation to use", "qt-path"});
parser.addOption({{"h", "host-qt-path"}, "When deploying a cross-compiled application, path to Host Qt installation", "host-qt-path"});
parser.addOption({{"l", "library-path"}, "Path to search for libraries to deploy (defaults to Program Files)", "library-path"});
parser.addPositionalArgument("directory", "Directory containing application to prepare for deployment");
parser.addOption({
{"a", "appx-output"},
"APPX bundle output file", "appx-output"
});
QCommandLineOption helpOption = parser.addHelpOption();
parser.parse(a.arguments());

Expand Down Expand Up @@ -85,7 +91,7 @@ int main(int argc, char** argv) {
QStringList supportLibraryPaths;

QDir rootProjectDir = deployFolder.destinationDir().absoluteFilePath("./");
for (QString markerFile : Common::findInPaths(".cntp-is-support-library", {rootProjectDir.absolutePath()}, true)) {
for (const QString &markerFile : Common::findInPaths(".cntp-is-support-library", {rootProjectDir.absolutePath()}, true)) {
QFileInfo markerFileInfo(markerFile);
QDir libDir = markerFileInfo.dir();

Expand All @@ -100,11 +106,20 @@ int main(int argc, char** argv) {

output << "Creating System Library Database...\n";
output.flush();
SystemLibraryDatabase* libraryDatabase = new SystemLibraryDatabase(supportLibraryPaths, sdkVersion, qt6CorePe.targetMachine(), libraryPaths);
auto* libraryDatabase = new SystemLibraryDatabase(supportLibraryPaths, sdkVersion, qt6CorePe.targetMachine(), libraryPaths);

output << "Making folder self contained\n";
output.flush();
deployFolder.makeSelfContained(libraryDatabase);

if (parser.isSet("appx-output")) {
QFile::remove(parser.value("appx-output"));

QProcess makeappxProcess;
makeappxProcess.setProcessChannelMode(QProcess::ForwardedChannels);
makeappxProcess.start("makeappx", {"pack", "/d", deployFolder.destinationDir().absolutePath(), "/p", parser.value("appx-output")});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to be able to make multi-architecture bundles too. Bonus if we can split the architecture-neutral files out as well

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll need to have some discussions about the multi-architecture bundles once support for cross compiling arm is complete

makeappxProcess.waitForFinished(-1);
}

return 0;
}
3 changes: 2 additions & 1 deletion lib/cmake-scripts/cntp-appicon.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ function(cntp_app_icon targetName)

IF(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
list(APPEND ICONTOOL_ARGS
-n ${CMAKE_CURRENT_BINARY_DIR}/native.ico)
-n ${CMAKE_CURRENT_BINARY_DIR}/native.ico
-w ${CMAKE_CURRENT_BINARY_DIR}/appxicons)

list(APPEND ICONTOOL_OUTPUTS
${CMAKE_CURRENT_BINARY_DIR}/native.ico)
Expand Down
2 changes: 2 additions & 0 deletions lib/cmake-scripts/cntp-init.cmake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include_guard()

set(CNTP_TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR} CACHE STRING "Architecture to build for")

function(cntp_init target cxx-standard)
option(CNTP_ASAN "Enable the use of AddressSanitizer" OFF)

Expand Down
47 changes: 47 additions & 0 deletions lib/cmake-scripts/cntp-repoversion.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
include_guard()

function(cntp_repoversion outvar)
set(${outvar}_MAJOR 0 PARENT_SCOPE)
set(${outvar}_MINOR 0 PARENT_SCOPE)
set(${outvar}_REVISION 0 PARENT_SCOPE)
set(${outvar}_BUILD 0 PARENT_SCOPE)

find_program(CNTP_GIT_COMMAND git)
if(CNTP_GIT_COMMAND)
execute_process(COMMAND ${CNTP_GIT_COMMAND} describe --abbrev=0 --tags
OUTPUT_VARIABLE GIT_DESCRIBE_OUTPUT
RESULT_VARIABLE GIT_DESCRIBE_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
if(CNTP_GIT_RESULT EQUAL 0)
execute_process(COMMAND ${CNTP_GIT_COMMAND} rev-list ${GIT_DESCRIBE_OUTPUT}.. --count
OUTPUT_VARIABLE GIT_REVLIST_OUTPUT
RESULT_VARIABLE GIT_DESCRIBE_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
if(CNTP_GIT_RESULT EQUAL 0)
if(GIT_DESCRIBE_OUTPUT MATCHES "v*")
string(SUBSTRING ${GIT_DESCRIBE_OUTPUT} 1 -1 GIT_VERSION_STRIPPED)
string(REGEX REPLACE "\\." ";" GIT_VERSION_PARTS ${GIT_VERSION_STRIPPED})

# Default versions to 0 if they can't be found - the list will always have at least 3 elements
list(APPEND GIT_VERSION_PARTS 0 0 0)
list(POP_FRONT GIT_VERSION_PARTS ${outvar}_MAJOR ${outvar}_MINOR ${outvar}_REVISION)

set(${outvar}_MAJOR ${${outvar}_MAJOR} PARENT_SCOPE)
set(${outvar}_MINOR ${${outvar}_MINOR} PARENT_SCOPE)
set(${outvar}_REVISION ${${outvar}_REVISION} PARENT_SCOPE)
set(${outvar}_BUILD ${GIT_REVLIST_OUTPUT} PARENT_SCOPE)
else()
message("Cannot determine repo version from Git; last tag does not start with v")
endif()
else()
message("Cannot determine repo version from Git; maybe not a Git repository?")
endif()
else()
message("Cannot determine repo version from Git; maybe not a Git repository?")
endif()
else()
message("Cannot determine repo version because Git is not installed")
endif()
endfunction()
3 changes: 2 additions & 1 deletion lib/cmake-scripts/cntp-targetname.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ function(cntp_target_name targetName targetReadableName)


set_target_properties(${targetName} PROPERTIES
OUTPUT_NAME "${TARGET_FINAL_NAME}")
OUTPUT_NAME "${TARGET_FINAL_NAME}"
READABLE_NAME "${TARGET_READABLE_NAME}")
target_compile_definitions(${targetName} PRIVATE
T_APPMETA_READABLE_NAME="${TARGET_READABLE_NAME}")
endfunction()
44 changes: 44 additions & 0 deletions lib/cmake-scripts/cntp-winappx.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
include_guard()

function(cntp_translate_arch outvar arch)
if(${arch} STREQUAL "AMD64")
set(${outvar} "x64" PARENT_SCOPE)
elseif(${arch} STREQUAL "arm64")
set(${outvar} "arm64" PARENT_SCOPE)
else()
set(${outvar} ${arch} PARENT_SCOPE)
endif()
endfunction()

function(cntp_winappx target appxmanifest)
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
get_target_property(APPX_DISPLAY_NAME ${target} READABLE_NAME)
get_target_property(APPX_EXECUTABLE_NAME ${target} OUTPUT_NAME)

cntp_repoversion(REPOVERSION)

if(";${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION};$ENV{UCRTVersion};$ENV{WindowsSDKVersion};" MATCHES [=[;(10\.[0-9.]+)[;\]]=])
get_filename_component(WINDOWS_KITS_BASE_DIR "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots;KitsRoot10]" ABSOLUTE)
set(WINDOWS_SDK_VERSION ${CMAKE_MATCH_1})
endif()

cntp_translate_arch(CNTP_TARGET_TRANSLATED_ARCH ${CNTP_TARGET_ARCH})

string(REGEX REPLACE "\\." ";" APPX_SDK_VERSION_PARTS ${WINDOWS_SDK_VERSION})

# Default versions to 0 if they can't be found - the list will always have at least 4 elements
list(APPEND APPX_SDK_VERSION_PARTS 0 0 0 0)
list(POP_FRONT APPX_SDK_VERSION_PARTS APPX_SDK_VERSION_MAJOR APPX_SDK_VERSION_MINOR APPX_SDK_VERSION_REVISION APPX_SDK_VERSION_BUILD)

set(${outvar}_MAJOR ${${outvar}_MAJOR} PARENT_SCOPE)
set(${outvar}_MINOR ${${outvar}_MINOR} PARENT_SCOPE)
set(${outvar}_REVISION ${${outvar}_REVISION} PARENT_SCOPE)
set(${outvar}_BUILD ${GIT_REVLIST_OUTPUT} PARENT_SCOPE)

set(APPX_EXECUTABLE_NAME ${APPX_EXECUTABLE_NAME}.exe)
set(APPX_ARCH ${CNTP_TARGET_TRANSLATED_ARCH})
set(APPX_VERSION ${REPOVERSION_MAJOR}.${REPOVERSION_MINOR}.${REPOVERSION_REVISION}.0)
set(APPX_SDK_VERSION ${APPX_SDK_VERSION_MAJOR}.${APPX_SDK_VERSION_MINOR}.${APPX_SDK_VERSION_REVISION}.${APPX_SDK_VERSION_BUILD})
configure_file(${appxmanifest} appxmanifest.xml)
endif()
endfunction()