5

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?

Community
  • 1
  • 1
rich.e
  • 3,660
  • 4
  • 28
  • 44

1 Answers1

6

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.

Lars Bilke
  • 4,940
  • 6
  • 45
  • 63
  • Ah, adding that to the `add_executable` command does indeed work. I guess I had assumed that `set_source_file_properties()` could be used in lieu of this. Thanks! – rich.e Jan 12 '15 at 22:15