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

CMake policies are not in sync between qt repos and macros included in top-level CMakeLists.txt

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P2: Important
    • None
    • 6.2, 6.5
    • Build System: CMake
    • None
    • f3c10280f (dev), aec0c2693 (6.5), 630d2636a (dev), bb8163a53 (dev), ed88eab0b (6.5), 5bedc7d7f (6.5), 91406ea1a (dev), 3523e7290 (dev), d5bd26fdd (dev), 7d5f292aa (dev), c71453bcd (dev), 31f5e0793 (dev), 078370278 (dev), 6786d4175 (dev), df9b9a9c9 (dev)

    Description

      We setup the CMake policies that are required to build Qt successfully only in the 'qt_build_repo' call. This means that functionality that may rely on the policy behavior and defined before the 'qt_build_repo' call may not work properly. The following code snippet is common for every Qt repository:

      find_package(Qt6 ${PROJECT_VERSION} CONFIG REQUIRED COMPONENTS BuildInternals Core)
      ...
      include(src/module/<QtModule>Macros.cmake)
      ...
      qt_build_repo()
      

      In this case policies that are specified by qt_build_repo will not affect the functions defined by include(src/module/<QtModule>Macros.cmake). This leads to the policy inconsistency that may have unpredictable behavior, like it happens with CMP0118. The inconsistent policy value when setting and getting the GENERATED source file property causes an issue:

      cmake_minimum_required(VERSION 3.16)
      
      project(mytest LANGUAGES CXX)
      
      add_executable(mytest main.cpp)
      
      cmake_policy(PUSH)
      cmake_policy(SET CMP0118 OLD)
      set_source_files_properties(main.cpp PROPERTIES GENERATED TRUE)
      get_source_file_property(is_generated main.cpp GENERATED)
      message("is_generated ${is_generated}")
      cmake_policy(POP)
      
      cmake_policy(PUSH)
      cmake_policy(SET CMP0118 NEW)
      get_source_file_property(is_generated main.cpp GENERATED)
      message("is_generated ${is_generated}")
      cmake_policy(POP)
      

      The above snippet prints:

      is_generated 1
      is_generated 0
      

      if the CMake version is >=3.20.

      As the conclusion:
      We should make sure that we use the consistent policy set for all Qt modules and their macros.

      Attachments

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

        Activity

          People

            semlanik Alexey Edelev
            semlanik Alexey Edelev
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes