Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-86726

qt_add_resource BASE argument doesn't behave as the qmake counterpart

    XMLWordPrintable

Details

    Description

      Since https://codereview.qt-project.org/c/qt/qtbase/+/110708, qmake handles a few kind of resources.

      Processing of regular qrc files that exist on the file system

      RESOURCES += foo.qrc
      

      Bundling of regular files into an auto-generated qrc file (standalone files / immediate mode)

      RESOURCES += main.cpp my.jpg
      

      Dynamic creation of a .qrc file that bundles a collection of files, via pseudo qmake objects.
      These can specify a prefix, as well as a 'base' parameter.

      pro_file.files = resources.pro
      pro_file.prefix = /prefix
      
      subdir.files = subdir/file.txt
      subdir.base = subdir
      
      RESOURCES += pro_file subdir
      

      The purpose of the 'base' parameter is to serve as the root point for the alias name of the files. Basically everything in the absolute file path of the file up to and including the base dir is stripped from the beginning of the alias name. Here's the generated qrc file contents.

      $ cat .rcc/qmake_subdir.qrc
      
      <!DOCTYPE RCC><RCC version="1.0">
      <qresource prefix="/">
      <file alias="file.txt">/Volumes/T3/Dev/qt/qt5_cmake/qtbase/tests/auto/tools/qmake/testdata/resources/subdir/file.txt</file>
      </qresource>
      </RCC>
      ~
      

      Note alias is just file.txt, not subdir/file.txt. On the file system, the file is in a subdir directory though.

      qt_add_resource aka qt6_process_resource also takes a BASE parameter. This parameter behaves differently than the qmake counterpart though.
      In the following example:

      # Resources:
      set(qmake_resourcestyle_resource_files
          "resources/ResourceStyle/Button.qml"
          "resources/ResourceStyle/qmldir"
      )
      
      qt_add_resource(tst_styleimports "qmake_resourcestyle"
          PREFIX
              "/"
          BASE
              "resources"
          FILES
              ${qmake_resourcestyle_resource_files}
      )
      

      The BASE parameter value is prepended to each of the passed files, which means it expects a file to exist in "${CMAKE_CURRENT_SOURCE_DIR}/resources/resources/ResourceStyle/qmldir".
      Note the doubled 'resources'.

      I suspect this is an oversight on the API expectations when the function was implemented.
      The above code was generated by pro2cmake in
      https://codereview.qt-project.org/c/qt/qtquickcontrols2/+/311974/14/tests/auto/styleimports/CMakeLists.txt#37
      Here's the qmake counter part https://codereview.qt-project.org/c/qt/qtquickcontrols2/+/311974/14/tests/auto/styleimports/styleimports.pro#12

      The local workaround is to remove the 'resources' from the file path var, while keeping it in the BASE parameter. This will ensure BASE is prepended, and the final file path will be valid on disk.

      To fix this, we either need to keep the existing behaviour of the function, and see if we can fix pro2cmake to output correct info.
      Or we change the behaviour of BASE to match the qmake one, but that implies regenerating all projects that contain qt_add_resource (which is a lot).

      Note there aren't many qmake .pro projects in the qt sources that explicitly set the .base parameter.
      There are a few tests in qtbase, some in qtlocation, and some in qtvirtualkeyboard.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            jbornema Joerg Bornemann
            alexandru.croitor Alexandru Croitor
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes