Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Setting up the application information in CMake

    Qt 6
    2
    4
    700
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      akshaybabloo last edited by

      How should I set the application information using CMake. For QMake we can use - https://stackoverflow.com/a/11971210/3782963.

      The process name in Activity monitor (macOS) is empty and looks something like this:

      Screen Shot 2021-01-07 at 2.43.45 PM.png

      1 Reply Last reply Reply Quote 1
      • A
        akshaybabloo last edited by

        I think I found the way to do this. We need win.rc on windows and Info.plist on mac, these files tell their OS's what to name the application.

        Windows

        For example, this is what I have (win.rc):

        IDI_ICON1               ICON    DISCARDABLE     "resources/images/datalogger.ico"
        
        
        1 VERSIONINFO
            FILEVERSION    0,0,0,0
            PRODUCTVERSION 0,0,0,0
        {
            BLOCK "StringFileInfo"
            {
                BLOCK "000004B0"
                {
                    VALUE "CompanyName",        "DataLogger\0"
                    VALUE "FileDescription",    "DataLogger\0"
                    VALUE "FileVersion",        "git\0"
                    VALUE "OriginalFilename",   "datalogger.exe\0"
                    VALUE "ProductName",        "DataLogger\0"
                    VALUE "ProductVersion",     "git\0"
                }
            }
            BLOCK "VarFileInfo"
            {
                VALUE "Translation", 0x0000, 0x04B0
            }
        }
        

        then I added this filename to CMakeLists.txt before find_package(...) as:

        if (WIN32)
            set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/win.rc")
        endif ()
        

        Finally add this:

        then add

        set(PROJECT_SOURCES
        
                main.cpp
        
                resources.qrc
        
        +        ${APP_ICON_RESOURCE_WINDOWS}
        
                mainwindow.cpp mainwindow.h mainwindow.ui
        )
        

        macOS

        I have a file called Info.plist in the root

        <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
        <plist version="1.0">
            <dict>
                <key>CFBundleDocumentTypes</key>
                <array>
                    <dict>
                        <key>CFBundleTypeIconFile</key>
                        <string>datalogger.icns</string>
                        <key>CFBundleTypeName</key>
                        <string>DataLogger</string>
                        <key>CFBundleTypeRole</key>
                        <string>Viewer</string>
                        <key>LSIsAppleDefaultForType</key>
                        <true/>
                    </dict>
                </array>
                <key>CFBundleIconFile</key>
                <string>datalogger.icns</string>
                <key>CFBundlePackageType</key>
                <string>APPL</string>
                <key>NSPrincipalClass</key>
                <string>NSApplication</string>
                <key>CFBundleSignature</key>
                <string>????</string>
                <key>CFBundleExecutable</key>
                <string>datalogger</string>
                <key>NSHumanReadableCopyright</key>
                <string>Copyright (c) 2021, Akshay Raj Gollahalli</string>
                <key>CFBundleIdentifier</key>
                <string>datalogger</string>
                <key>CFBundleName</key>
                <string>DataLogger</string>
                <key>CFBundleShortVersionString</key>
                <string>3.1.2</string>
                <key>AppleMagnifiedMode</key>
                <false/>
            </dict>
        </plist>
        

        In your CMakeList.txt before find_package(...), add:

        if (APPLE)
            set(MACOSX_BUNDLE_ICON_FILE datalogger.icns)
            # And the following tells CMake where to find and install the file itself.
            set(app_icon_macos "resources/images/datalogger.icns")
            set_source_files_properties(${app_icon_macos} PROPERTIES
                    MACOSX_PACKAGE_LOCATION "Resources")
        endif ()
        

        then add

        set(PROJECT_SOURCES
        +        MACOSX_BUNDLE
        
                main.cpp
        
                resources.qrc
        
        +        ${app_icon_macos}
        
                mainwindow.cpp mainwindow.h mainwindow.ui
        )
        
        1 Reply Last reply Reply Quote 0
        • kkoehne
          kkoehne Moderators last edited by

          I assume this is Windows? Unfortunately CMake doesn't provide a convenient API for this yet. See the request https://gitlab.kitware.com/cmake/cmake/-/issues/21314 that we filed about this a while ago.

          Meanwhile you can add the information by adding an .rc file manually. For Qt binaries, the logic for this is done in QtCoreMacros.cmake (check out _qt_internal_generate_win32_rc_file function). But this isn't public API, because we feel this should rather be provided upstream, in CMake.

          Director R&D, The Qt Company

          A 1 Reply Last reply Reply Quote 3
          • A
            akshaybabloo @kkoehne last edited by

            @kkoehne No this is Mac. I think in windows it shows the name with .exe.

            OK will give this a try.

            1 Reply Last reply Reply Quote 0
            • A
              akshaybabloo last edited by

              I think I found the way to do this. We need win.rc on windows and Info.plist on mac, these files tell their OS's what to name the application.

              Windows

              For example, this is what I have (win.rc):

              IDI_ICON1               ICON    DISCARDABLE     "resources/images/datalogger.ico"
              
              
              1 VERSIONINFO
                  FILEVERSION    0,0,0,0
                  PRODUCTVERSION 0,0,0,0
              {
                  BLOCK "StringFileInfo"
                  {
                      BLOCK "000004B0"
                      {
                          VALUE "CompanyName",        "DataLogger\0"
                          VALUE "FileDescription",    "DataLogger\0"
                          VALUE "FileVersion",        "git\0"
                          VALUE "OriginalFilename",   "datalogger.exe\0"
                          VALUE "ProductName",        "DataLogger\0"
                          VALUE "ProductVersion",     "git\0"
                      }
                  }
                  BLOCK "VarFileInfo"
                  {
                      VALUE "Translation", 0x0000, 0x04B0
                  }
              }
              

              then I added this filename to CMakeLists.txt before find_package(...) as:

              if (WIN32)
                  set(APP_ICON_RESOURCE_WINDOWS "${CMAKE_CURRENT_SOURCE_DIR}/win.rc")
              endif ()
              

              Finally add this:

              then add

              set(PROJECT_SOURCES
              
                      main.cpp
              
                      resources.qrc
              
              +        ${APP_ICON_RESOURCE_WINDOWS}
              
                      mainwindow.cpp mainwindow.h mainwindow.ui
              )
              

              macOS

              I have a file called Info.plist in the root

              <?xml version="1.0" encoding="UTF-8"?>
              <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
              <plist version="1.0">
                  <dict>
                      <key>CFBundleDocumentTypes</key>
                      <array>
                          <dict>
                              <key>CFBundleTypeIconFile</key>
                              <string>datalogger.icns</string>
                              <key>CFBundleTypeName</key>
                              <string>DataLogger</string>
                              <key>CFBundleTypeRole</key>
                              <string>Viewer</string>
                              <key>LSIsAppleDefaultForType</key>
                              <true/>
                          </dict>
                      </array>
                      <key>CFBundleIconFile</key>
                      <string>datalogger.icns</string>
                      <key>CFBundlePackageType</key>
                      <string>APPL</string>
                      <key>NSPrincipalClass</key>
                      <string>NSApplication</string>
                      <key>CFBundleSignature</key>
                      <string>????</string>
                      <key>CFBundleExecutable</key>
                      <string>datalogger</string>
                      <key>NSHumanReadableCopyright</key>
                      <string>Copyright (c) 2021, Akshay Raj Gollahalli</string>
                      <key>CFBundleIdentifier</key>
                      <string>datalogger</string>
                      <key>CFBundleName</key>
                      <string>DataLogger</string>
                      <key>CFBundleShortVersionString</key>
                      <string>3.1.2</string>
                      <key>AppleMagnifiedMode</key>
                      <false/>
                  </dict>
              </plist>
              

              In your CMakeList.txt before find_package(...), add:

              if (APPLE)
                  set(MACOSX_BUNDLE_ICON_FILE datalogger.icns)
                  # And the following tells CMake where to find and install the file itself.
                  set(app_icon_macos "resources/images/datalogger.icns")
                  set_source_files_properties(${app_icon_macos} PROPERTIES
                          MACOSX_PACKAGE_LOCATION "Resources")
              endif ()
              

              then add

              set(PROJECT_SOURCES
              +        MACOSX_BUNDLE
              
                      main.cpp
              
                      resources.qrc
              
              +        ${app_icon_macos}
              
                      mainwindow.cpp mainwindow.h mainwindow.ui
              )
              
              1 Reply Last reply Reply Quote 0
              • First post
                Last post