Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.2, 6.5
-
None
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.