Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Setting up the application information in CMake

Setting up the application information in CMake

Scheduled Pinned Locked Moved Solved Qt 6
4 Posts 2 Posters 2.0k Views
  • 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 Offline
    A Offline
    akshaybabloo
    wrote on 7 Jan 2021, 01:44 last edited by
    #1

    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
    1
    • A Offline
      A Offline
      akshaybabloo
      wrote on 6 May 2021, 03:30 last edited by
      #4

      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
      0
      • K Offline
        K Offline
        kkoehne
        Moderators
        wrote on 22 Jan 2021, 14:42 last edited by
        #2

        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 30 Jan 2021, 04:30
        3
        • K kkoehne
          22 Jan 2021, 14:42

          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.

          A Offline
          A Offline
          akshaybabloo
          wrote on 30 Jan 2021, 04:30 last edited by
          #3

          @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
          0
          • A Offline
            A Offline
            akshaybabloo
            wrote on 6 May 2021, 03:30 last edited by
            #4

            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
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved