MacOS QT qmake 与 CMake 设置ICON

生成icon

创建文件夹

mkdir icons.iconset

生成多尺寸

sips -z 16 16     icon.png --out icons.iconset/icon_16x16.png
sips -z 32 32     icon.png --out icons.iconset/[email protected]
sips -z 32 32     icon.png --out icons.iconset/icon_32x32.png
sips -z 64 64     icon.png --out icons.iconset/[email protected]
sips -z 64 64     icon.png --out icons.iconset/icon_64x64.png
sips -z 128 128   icon.png --out icons.iconset/[email protected]
sips -z 128 128   icon.png --out icons.iconset/icon_128x128.png
sips -z 256 256   icon.png --out icons.iconset/[email protected]
sips -z 256 256   icon.png --out icons.iconset/icon_256x256.png
sips -z 512 512   icon.png --out icons.iconset/[email protected]
sips -z 512 512   icon.png --out icons.iconset/icon_512x512.png
sips -z 1024 1024   icon.png --out icons.iconset/[email protected]

生成icns图标

iconutil -c icns icons.iconset -o icon.icns

qmake 设置icon

ICON = Icon.icns

CMake 设置icon

  • 在项目更目录下创建icons文件夹

  • 将生成的icon.icns放入icons文件夹

  • 在项目更目录下创建macOS文件夹

  • 在maccOS文件夹下创建Info.plist.in文件

      
      
      
      
      	CFBundleDevelopmentRegion
      	English
      	CFBundleExecutable
      	${MACOSX_BUNDLE_EXECUTABLE_NAME}
      	CFBundleIconFile
      	${MACOSX_BUNDLE_ICON_FILE}
      	CFBundleIdentifier
      	${MACOSX_BUNDLE_GUI_IDENTIFIER}
      	CFBundleInfoDictionaryVersion
      	6.0
      	CFBundleName
      	${MACOSX_BUNDLE_BUNDLE_NAME}
      	CFBundlePackageType
      	APPL
      	CFBundleShortVersionString
      	${MACOSX_BUNDLE_SHORT_VERSION_STRING}
      	CFBundleVersion
      	${MACOSX_BUNDLE_BUNDLE_VERSION}
      	CSResourcesFileMapped
      	
      	NSHumanReadableCopyright
      	${MACOSX_BUNDLE_COPYRIGHT}
      	NSPrincipalClass
      	NSApplication
      	NSHighResolutionCapable
      	True
      	NSUserNotificationAlertStyle
      	alert
      
      
    
  • CMake 配置

      set(MACOSX_BUNDLE_GUI_IDENTIFIER ${IDENTIFIER})
      set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
      
      set(MACOSX_BUNDLE_COPYRIGHT ${COPYRIGHT})
      
      set(MACOSX_BUNDLE_SHORT_VERSION_STRING ${spectral_VERSION})
      set(MACOSX_BUNDLE_BUNDLE_VERSION ${spectral_VERSION})
      
      set(ICON_NAME "icon.icns")
      set(${PROJECT_NAME}_MAC_ICON "${PROJECT_SOURCE_DIR}/icons/${ICON_NAME}")
      set(MACOSX_BUNDLE_ICON_FILE ${ICON_NAME})
      set_property(SOURCE "${${PROJECT_NAME}_MAC_ICON}" PROPERTY
          MACOSX_PACKAGE_LOCATION Resources)
    
      add_executable( ${PROJECT_NAME}  MACOSX_BUNDLE
          ${${PROJECT_NAME}_MAC_ICON}
          main.cpp
          qml.qrc
          )
    
    
      set_property(TARGET ${PROJECT_NAME} PROPERTY
          MACOSX_BUNDLE_INFO_PLIST "${PROJECT_SOURCE_DIR}/macOS/Info.plist.in")
    

你可能感兴趣的:(QT)