diff --git a/modules/ECMAddAppIcon.cmake b/modules/ECMAddAppIcon.cmake --- a/modules/ECMAddAppIcon.cmake +++ b/modules/ECMAddAppIcon.cmake @@ -17,9 +17,10 @@ # -.png # # will be added to the executable target whose sources are specified by -# ```` on platforms that support it (Windows and Mac OS X). -# Other icon files are ignored but on Mac SVG files can be supported and -# it is thus possible to mix those with png files in a single macro call. +# ```` (either a target or a list of source files) on platforms +# that support it (Windows and Mac OS X). Other icon files are ignored but on +# Mac SVG files can be supported and it is thus possible to mix those with png +# files in a single macro call. # # ```` is a numeric pixel size (typically 16, 32, 48, 64, 128 or 256). # ```` can be any other text. See the platform notes below for any @@ -113,6 +114,16 @@ message(FATAL_ERROR "Unexpected arguments to ecm_add_app_icon: ${ARG_UNPARSED_ARGUMENTS}") endif() + # Supports adding sources to both source lists and targets. + macro(add_sources sources) + if(TARGET ${sources}) + cmake_minimum_required(VERSION 3.1) + target_sources(${sources} PRIVATE ${ARGN}) + else() + set(${sources} ${${sources}} ${ARGN} PARENT_SCOPE) + endif() + endmacro() + if(APPLE) find_program(KSVG2ICNS NAMES ksvg2icns) foreach(icon ${ARG_ICONS}) @@ -129,7 +140,7 @@ # install the icns file we just created get_filename_component(icon_name ${icon_full} NAME_WE) set(MACOSX_BUNDLE_ICON_FILE ${icon_name}.icns PARENT_SCOPE) - set(${appsources} "${${appsources}};${CMAKE_CURRENT_BINARY_DIR}/${icon_name}.icns" PARENT_SCOPE) + add_sources(${appsources} ${CMAKE_CURRENT_BINARY_DIR}/${icon_name}.icns) set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${icon_name}.icns PROPERTIES MACOSX_PACKAGE_LOCATION Resources) # we're done now return() @@ -244,7 +255,7 @@ endforeach() create_windows_icon_and_rc(IcoTool::IcoTool "${icotool_args}" "${windows_icons_modern}") - set(${appsources} "${${appsources}};${_outfilename}.rc" PARENT_SCOPE) + add_sources(${appsources} ${_outfilename}.rc) # standard png2ico has no rcfile argument elseif(Png2Ico_FOUND AND NOT Png2Ico_HAS_RCFILE_ARGUMENT AND windows_icons_classic) @@ -253,7 +264,7 @@ list(APPEND png2ico_args "${windows_icons_classic}") create_windows_icon_and_rc(Png2Ico::Png2Ico "${png2ico_args}" "${windows_icons_classic}") - set(${appsources} "${${appsources}};${_outfilename}.rc" PARENT_SCOPE) + add_sources(${appsources} ${_outfilename}.rc) # png2ico from kdewin provides rcfile argument elseif(Png2Ico_FOUND AND windows_icons_classic) @@ -268,7 +279,7 @@ WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" ) - set(${appsources} "${${appsources}};${_outfilename}.rc" PARENT_SCOPE) + add_sources(${appsources} ${_outfilename}.rc) # else none of the supported tools was found else() message(WARNING "Unable to find the png2ico or icotool utilities or icons in matching sizes - application will not have an application icon!") @@ -350,7 +361,7 @@ # Append the icns file to the sources list so it will be a dependency to the # main target - set(${appsources} "${${appsources}};${_outfilename}.icns" PARENT_SCOPE) + add_sources(${appsources} ${_outfilename}.icns) # Install the icon into the Resources dir in the bundle set_source_files_properties("${_outfilename}.icns" PROPERTIES MACOSX_PACKAGE_LOCATION Resources)