Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cmake: set icon for a Mac OS X app

Tags:

macos

icons

cmake

Installing a Mac OS X app using cmake environment, I want to set and install the icon in the process of installation.

Therefore, I try to set

set( MACOSX_BUNDLE_ICON_FILE ${CMAKE_CURRENT_SOURCE_DIR}/images/myAopImage.icns )
ADD_EXECUTABLE(MYAPP MACOSX_BUNDLE ${MACOSX_BUNDLE_ICON_FILE} ${allSources})
#(I could set it in the source directory to any other path)

However, this does not work, it writes the complete path into the Info.plist, and installs nothing into the Resources directory (the resources dir even does not get created in the app folder which gets installed)

Anyhow, even if I put by hand into the Info.plist the information

<key>CFBundleIconFile</key>
<string>myAppImage.icns</string>

and create the Resources directory by hand, putting into there the icns File,

the icon appears anyhow for the app.

How do I solve this problem? At first to do it by hand maybe, but also within the cmake context?

like image 772
user3478292 Avatar asked Mar 30 '14 15:03

user3478292


1 Answers

There are two pieces to bundling the .icns file from CMake: adding the source file itself, and configuring it in the .plist. If you want to specify a path to your .icns file (e.g. because it is in a subdirectory), then these two properties will refer to the .icns file slightly differently:

# NOTE: Don't include the path in MACOSX_BUNDLE_ICON_FILE -- this is
# the property added to Info.plist
set(MACOSX_BUNDLE_ICON_FILE myAppImage.icns)

# And this part tells CMake where to find and install the file itself
set(myApp_ICON ${CMAKE_CURRENT_SOURCE_DIR}/images/myAppImage.icns)
set_source_files_properties(${myApp_ICON} PROPERTIES
       MACOSX_PACKAGE_LOCATION "Resources")

add_executable(myApp MACOSX_BUNDLE ${myApp_ICON} ${allSources})
like image 142
Zrax Avatar answered Oct 24 '22 08:10

Zrax