CMake 设置 Application Icon

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/theArcticOcean/article/details/83041198

For Windows

增添rc文件到工程中。
add file:
Source/myapp.rc
包含内容:

IDI_ICON1               ICON    DISCARDABLE     "Images/logo.ico"

他指明了图标文件的路径。
然后将这份rc文件添加到CMakeLists.txt中:

file( GLOB SourceFiles Source/*.cpp Source/myapp.rc )

add_executable(
    ${PROJECT_NAME}
    MACOSX_BUNDLE
    ${SourceFiles}
    ${HeaderFiles}
    ${ResourceFiles}
    ${UISrcs}
    )

For Mac OS X

在CMakeLists.txt中指明图标文件的路径,然后添加到executable 的依赖文件列表中

# CMAKE_AUTOMOC in ON so the MOC headers will be automatically wrapped.
set( CMAKE_AUTOMOC ON )

# NOTE: Don't include the path in MACOSX_BUNDLE_ICON_FILE -- this is
# the property added to Info.plist
#     <key>CFBundleIconFile</key>
#     <string>logo</string>
set(MACOSX_BUNDLE_ICON_FILE logo)

# And this part tells CMake where to find and install the file itself
set(myApp_ICON ${CMAKE_CURRENT_SOURCE_DIR}/Images/logo.icns)
# set_source_files_properties would create Resources folder to store icns
# The folder is at same path where Info.plist located
set_source_files_properties(${myApp_ICON} PROPERTIES
     MACOSX_PACKAGE_LOCATION "Resources")

add_executable(
    ${PROJECT_NAME}
    MACOSX_BUNDLE
    ${SourceFiles}
    ${HeaderFiles}
    ${ResourceFiles}
    ${UISrcs}
    ${myApp_ICON}   # Add icon file to see in IDE.
    )
阅读更多
换一批

没有更多推荐了,返回首页