Skip to content

Commit 7b3ffb4

Browse files
committed
Write the icons with qiconmaker at build time
1 parent 925fa59 commit 7b3ffb4

4 files changed

Lines changed: 89 additions & 159 deletions

File tree

‎cmake/AddIcon.cmake‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# SPDX-FileCopyrightText: Team OpenVPI
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
# Icons written at build time by qiconmaker (https://github.com/stdware/qiconmaker) from images,
5+
# so that the repository keeps the images rather than the icon files. The package qiconmaker is
6+
# found before this file is included.
7+
8+
# Qt Core for the directory of its DLLs, which qiconmaker loads on Windows
9+
qm_find_qt(Core)
10+
11+
# add_icon(<output> <directory>)
12+
#
13+
# Writes the icon <output>, an .ico of Windows or an .icns of macOS by its suffix, from the images
14+
# <directory>/<size>x<size>.png in a custom command. The image of 1024 px is the master image. A
15+
# size of the format that has an image of its own takes that image, and qiconmaker reduces the
16+
# master image to every other size. A target of the same directory that lists <output> as a source
17+
# builds the icon first, and qm_add_win_rc_enhanced() and qm_add_mac_bundle() of qmsetup accept it.
18+
function(add_icon _output _directory)
19+
set(_master "${_directory}/1024x1024.png")
20+
set(_arguments "${_output}" "${_master}")
21+
set(_depends "${_master}")
22+
23+
# The sizes that qiconmaker writes for each format by default
24+
if(_output MATCHES "\\.icns$")
25+
set(_sizes 16 32 64 128 256 512)
26+
else()
27+
set(_sizes 16 20 24 30 32 36 40 48 60 64 72 80 96 256)
28+
endif()
29+
30+
foreach(_size IN LISTS _sizes)
31+
set(_file "${_directory}/${_size}x${_size}.png")
32+
if(EXISTS "${_file}")
33+
list(APPEND _arguments "${_size}=${_file}")
34+
list(APPEND _depends "${_file}")
35+
endif()
36+
endforeach()
37+
38+
# The program loads the DLLs of Qt, which Windows finds through PATH. On the other systems the
39+
# program holds the run path to the libraries of Qt.
40+
set(_command $<TARGET_FILE:qiconmaker::qiconmaker>)
41+
if(WIN32)
42+
set(_command ${CMAKE_COMMAND} -E env "PATH=$<TARGET_FILE_DIR:Qt6::Core>" ${_command})
43+
endif()
44+
add_custom_command(OUTPUT "${_output}"
45+
COMMAND ${_command} ${_arguments}
46+
DEPENDS ${_depends}
47+
COMMENT "Writing ${_output}"
48+
VERBATIM
49+
)
50+
endfunction()

‎scripts/vcpkg-manifest/vcpkg.json‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@
4343
},
4444
"xxhash",
4545
"signalsmith-dsp",
46-
"rubberband"
46+
"rubberband",
47+
{
48+
"name": "qiconmaker",
49+
"platform": "windows | osx"
50+
}
4751
],
4852
"vcpkg-configuration": {
4953
"overlay-ports": [

‎src/app/CMakeLists.txt‎

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,52 @@
11
# SPDX-FileCopyrightText: Team OpenVPI
22
# SPDX-License-Identifier: Apache-2.0
33

4-
add_subdirectory(icons)
5-
4+
# The icons of the application and of the project files, written at build time from the images in
5+
# icons/<name>. The installer of Windows takes the icon of the project files from the resources of
6+
# the executable, and the bundle of macOS from its resources. Linux uses the images directly.
67
set(_ico_args)
78
set(_icns_args)
9+
set(_icons)
810

9-
if(WIN32)
10-
list(APPEND _ico_path
11-
${CMAKE_CURRENT_BINARY_DIR}/icons/app.ico
12-
${CMAKE_CURRENT_BINARY_DIR}/icons/dspx.ico
13-
)
14-
set(_filtered_ico_path "")
15-
foreach(_file IN LISTS _ico_path)
16-
if(EXISTS ${_file})
17-
list(APPEND _filtered_ico_path ${_file})
18-
endif()
19-
endforeach()
20-
set(_ico_args ICO ${_filtered_ico_path})
21-
endif()
11+
if(WIN32 OR APPLE)
12+
find_package(qiconmaker CONFIG REQUIRED)
13+
include(AddIcon)
2214

23-
if(APPLE)
24-
set(_icns_path ${CMAKE_CURRENT_BINARY_DIR}/icons/app.icns)
25-
if(EXISTS ${_icns_path})
26-
set(_icns_args ICNS ${_icns_path})
15+
if(WIN32)
16+
set(_suffix .ico)
17+
else()
18+
set(_suffix .icns)
2719
endif()
28-
endif()
2920

21+
foreach(_name IN ITEMS app dspx)
22+
set(_icon ${CMAKE_CURRENT_BINARY_DIR}/icons/${_name}${_suffix})
23+
add_icon(${_icon} ${CMAKE_CURRENT_SOURCE_DIR}/icons/${_name})
24+
list(APPEND _icons ${_icon})
25+
endforeach()
3026

27+
if(WIN32)
28+
set(_ico_args ICO ${_icons})
29+
else()
30+
set(_icns_args ICNS ${CMAKE_CURRENT_BINARY_DIR}/icons/app.icns)
31+
endif()
32+
endif()
3133

3234
ck_configure_application(
3335
${_ico_args}
3436
${_icns_args}
3537
INFO_PLIST ${CMAKE_CURRENT_SOURCE_DIR}/info.plist.in
3638
)
3739

40+
if(_icons)
41+
target_sources(${PROJECT_NAME} PRIVATE ${_icons})
42+
endif()
43+
44+
if(APPLE)
45+
set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/icons/dspx.icns PROPERTIES
46+
MACOSX_PACKAGE_LOCATION Resources
47+
)
48+
endif()
49+
3850
qm_configure_target(${PROJECT_NAME}
3951
SOURCES main.cpp
4052
QT_LINKS_PRIVATE
@@ -75,19 +87,12 @@ ck_add_shared_files(
7587
# SRC conf/${CK_PLATFORM_LOWER}/qtmediate.json DEST ${CK_BUILD_QT_CONF_DIR} # qtmediate.json
7688
)
7789

78-
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/icons/dspx.icns)
79-
ck_add_shared_files(
80-
SRC ${CMAKE_CURRENT_BINARY_DIR}/icons/dspx.icns DEST ${CK_BUILD_DATA_DIR}
81-
)
82-
endif()
83-
84-
file(GLOB _icons icons/*)
85-
list(FILTER _icons EXCLUDE REGEX CMakeLists.txt)
90+
file(GLOB _icon_images icons/*)
8691

8792
qt_add_resources(${PROJECT_NAME} icons
8893
PREFIX /diffscope/icons
8994
BASE icons
90-
FILES ${_icons}
95+
FILES ${_icon_images}
9196
)
9297

9398
if(LINUX)

‎src/app/icons/CMakeLists.txt‎

Lines changed: 0 additions & 129 deletions
This file was deleted.

0 commit comments

Comments
 (0)