PCH compilations fails on VC++/Ninja if CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP=1
Hello,
I recently updated our CI to 3.25.0 and our builds started to fail immediately (VC++ 2022, C++20, Ninja). I found it is related to CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP
being set to 1 by default, which has already been identified and fixed by #24198 (closed). Great.
But in order to help you improve C++20 module support, here's a simple cmake project that fails to build with CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP=1
.
// pch.h is an empty header file
// empty.cpp is an empty cpp file
# CMakeLists.txt
cmake_minimum_required(VERSION 3.20)
project(Project)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# setting this flag to 1 with VC++ / Ninja makes Ninja to complain:
# ninja: error: dependency cycle: CMakeFiles/MyLibWithPCH.dir/cmake_pch.cxx.obj -> CMakeFiles/MyLibWithPCH.dir/CXX.dd -> CMakeFiles/MyLibWithPCH.dir/empty.cpp.obj.ddi -> CMakeFiles/MyLibWithPCH.dir/cmake_pch.cxx.pch -> CMakeFiles/MyLibWithPCH.dir/cmake_pch.cxx.obj
set(CMAKE_EXPERIMENTAL_CXX_MODULE_DYNDEP 1)
add_library(MyLibWithPCH
empty.cpp
)
target_precompile_headers(MyLibWithPCH PUBLIC pch.h)
REM from VC++ 2022 command prompt
mkdir build && cd build
cmake .. -G Ninja
ninja
ninja: error: dependency cycle: CMakeFiles/MyLibWithPCH.dir/cmake_pch.cxx.obj -> CMakeFiles/MyLibWithPCH.dir/CXX.dd -> CMakeFiles/MyLibWithPCH.dir/empty.cpp.obj.ddi -> CMakeFiles/MyLibWithPCH.dir/cmake_pch.cxx.pch -> CMakeFiles/MyLibWithPCH.dir/cmake_pch.cxx.obj
Hope it helps!