CMake: copy resource binding icon

I have a CMakeLists.txt script that creates the MACOSX_BUNDLE , although I find it difficult to find the "right path" to get the icon file in the package resources directory. I set the icon set properties with the following options:

 # 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 seems that the right way (as indicated in this present report ):

 set_source_files_properties( ${ICON_PATH} PROPERTIES MACOSX_PACKAGE_LOCATION Resources ) 

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

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

Since I will often copy things into the resouces folder, I would prefer to do this in the โ€œright wayโ€, but can anyone tell me why this does not work, since I did it above?

+5
source share
1 answer

You also need to add an icon (with full path) as a resource for your executable:

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

Then it is automatically copied to the resource folder.

+5
source

Source: https://habr.com/ru/post/1207862/


All Articles