I think I found the way to do this. We need win.rc on windows and Info.plist on mac, these files tell their OS's what to name the application.
Windows
For example, this is what I have (win.rc):
IDI_ICON1 ICON DISCARDABLE "resources/images/datalogger.ico"
1 VERSIONINFO
FILEVERSION 0,0,0,0
PRODUCTVERSION 0,0,0,0
{
BLOCK "StringFileInfo"
{
BLOCK "000004B0"
{
VALUE "CompanyName", "DataLogger\0"
VALUE "FileDescription", "DataLogger\0"
VALUE "FileVersion", "git\0"
VALUE "OriginalFilename", "datalogger.exe\0"
VALUE "ProductName", "DataLogger\0"
VALUE "ProductVersion", "git\0"
}
}
BLOCK "VarFileInfo"
{
VALUE "Translation", 0x0000, 0x04B0
}
}
then I added this filename to CMakeLists.txt before find_package(...) as:
if (WIN32)
set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/win.rc")
endif ()
Finally add this:
then add
set(PROJECT_SOURCES
main.cpp
resources.qrc
+ ${APP_ICON_RESOURCE_WINDOWS}
mainwindow.cpp mainwindow.h mainwindow.ui
)
macOS
I have a file called Info.plist in the root
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDocumentTypes</key>
<array>
<dict>
<key>CFBundleTypeIconFile</key>
<string>datalogger.icns</string>
<key>CFBundleTypeName</key>
<string>DataLogger</string>
<key>CFBundleTypeRole</key>
<string>Viewer</string>
<key>LSIsAppleDefaultForType</key>
<true/>
</dict>
</array>
<key>CFBundleIconFile</key>
<string>datalogger.icns</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleExecutable</key>
<string>datalogger</string>
<key>NSHumanReadableCopyright</key>
<string>Copyright (c) 2021, Akshay Raj Gollahalli</string>
<key>CFBundleIdentifier</key>
<string>datalogger</string>
<key>CFBundleName</key>
<string>DataLogger</string>
<key>CFBundleShortVersionString</key>
<string>3.1.2</string>
<key>AppleMagnifiedMode</key>
<false/>
</dict>
</plist>
In your CMakeList.txt before find_package(...), add:
if (APPLE)
set(MACOSX_BUNDLE_ICON_FILE datalogger.icns)
# And the following tells CMake where to find and install the file itself.
set(app_icon_macos "resources/images/datalogger.icns")
set_source_files_properties(${app_icon_macos} PROPERTIES
MACOSX_PACKAGE_LOCATION "Resources")
endif ()
then add
set(PROJECT_SOURCES
+ MACOSX_BUNDLE
main.cpp
resources.qrc
+ ${app_icon_macos}
mainwindow.cpp mainwindow.h mainwindow.ui
)