CMake 3.20 breaks Qt-based projects using qt5_wrap_ui() command (ninja: error: dependency cycle: Project/Application_autogen -> ...)
Reproduced with CMake from master @ c0aa4244f5b1900c280b54a5453cc881dc7d3d95 on Ubuntu Linux. Steps to reproduce: * Clone https://github.com/KDAB/Charm.git * Note: Needs qt5 dev environment + qtkeychain dev package (should be easy to install on a recent distro) * Build the project, touch a file including a ui_*.h file, try to build again See exact steps to reproduce + my output below: ``` % ninja clean [2/2] Cleaning all built files... Cleaning... 0 files. % ~/opt/cmake-master/bin/cmake . -- Building Charm 1.12.0-25-gfe99 in RelWithDebInfo mode -- Qt5: Install Xcb headers and library for Xcb idle detection. -- Charm will be installed to /home/kfunk/devel/install/master -- The following OPTIONAL packages have been found: * Git * Qt5PrintSupport -- The following REQUIRED packages have been found: * Qt5Gui (required version >= 5.15.2) * Qt5Widgets * Qt5Xml * Qt5Network * Qt5Sql * Qt5Test * Qt5Core * Qt5DBus * Qt5Keychain, Provides support for secure credentials storage, <https://github.com/frankosterfeld/qtkeychain> -- The following RECOMMENDED packages have not been found: * XCB, Provides idle detection support for X11, <http://xcb.freedesktop.org> -- Configuring done -- Generating done -- Build files have been written to: /home/kfunk/devel/build/kdab/Charm % ninja (...) [178/178] Linking CXX executable Charm/charmtimetracker => WORKS % ninja ninja: no work to do. % touch /home/kfunk/devel/src/kdab/Charm/Charm/Widgets/CharmPreferences.h % ninja (...) [6/6] Linking CXX executable Charm/charmtimetracker => WORKS THE FIRST TIME % ninja ninja: error: dependency cycle: Charm/CharmApplication_autogen -> Charm/CMakeFiles/CharmApplication_autogen -> Charm/CharmApplication_autogen/timestamp -> Charm/ui_CharmPreferences.h -> Charm/CharmApplication_autogen => BREAKS ON SECOND TRY ``` This problem seems to be related to this new funcionality in CMake 3.20: https://cmake.org/cmake/help/git-stage/policy/CMP0116.html Reverting the following commit restores old behavior for me: https://gitlab.kitware.com/cmake/cmake/-/commit/3a9550351200e6bfbda993b0ec3064bddb894b69
issue