Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake: copy icon to bundle resources

Tags:

macos

cmake

I have a CMakeLists.txt script that builds a MACOSX_BUNDLE executable, though I'm having difficulty finding the 'right way' to get the icon file into the bundle's resource directory. I set the icon bundle properties with the following:

# set icon
set( ICON_NAME "MyApp.icns" )
set( ICON_PATH "${PROJECT_SOURCE_DIR}/../data/${ICON_NAME}" )

set_target_properties( MyApp PROPERTIES MACOSX_BUNDLE_ICON_FILE ${ICON_NAME} )

It appears the correct way (as found in this existing post) should be:

set_source_files_properties( ${ICON_PATH} PROPERTIES MACOSX_PACKAGE_LOCATION Resources )

However, there is no MyApp.app/Contents/Resources, nor copied MyApp.icns.. The following is (in my opinion) a workaround:

file( COPY ${ICON_PATH} DESTINATION "MyApp.app/Contents/Resources/" )

As I'll often be copying things into the resouces folder, I'd rather do it the 'right way', but can anyone tell why this doesn't work as I've done it above?

like image 852
rich.e Avatar asked Nov 28 '14 04:11

rich.e


1 Answers

You also have to add the icon (with full path) as a resource to your executable:

add_executable( MyApp MACOSX_BUNDLE main.cpp ${ICON_PATH})

Then it gets automatically copied to the resources folder.

like image 125
Lars Bilke Avatar answered Sep 20 '22 07:09

Lars Bilke