Skip to content

Commit 2e9436c

Browse files
committed
cmake: Fix IWYU in nix by adding CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES
Without this change, building with -DMP_ENABLE_IWYU=ON and newer versions of nixpkgs (after 2025-11-12) fails with mysterious errors that look like: make[2]: *** [CMakeFiles/mputil.dir/build.make:79: CMakeFiles/mputil.dir/src/mp/util.cpp.o] Error 1 with no other error messages. The are no messages because cmake -E __run_co_compile hides the output from IWYU and does not display anything itself. The actual problem is missing include directories on the compiler command line, and the fix here is to extend a workaround previously added for clang-tidy to be used for IWYU as well. Breakage seems to have been caused by NixOS/nixpkgs@76a8ffa from NixOS/nixpkgs#445095, which I found by bisecting with --first-parent to a change between the following merge commit: https://github.com/NixOS/nixpkgs/commits/de21549a840be528ef4763dd7dca2006caf9c11f (bad) https://github.com/NixOS/nixpkgs/commits/c4d1151093af5d483d1900d9214a65e68bc21560 (good) If you check out the bad commit above (or any later commit) and revert NixOS/nixpkgs@76a8ffa the problem disappears. I suspect the problem happens because cmake is not handling -cxx-isystem properly, but did not debug further.
1 parent d0fc108 commit 2e9436c

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ if(MP_ENABLE_CLANG_TIDY)
9090
message(FATAL_ERROR "MP_ENABLE_CLANG_TIDY is ON but clang-tidy is not found.")
9191
endif()
9292
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}")
93-
94-
# Workaround for nix from https://gitlab.kitware.com/cmake/cmake/-/issues/20912#note_793338
95-
# Nix injects header paths via $NIX_CFLAGS_COMPILE; CMake tags these as
96-
# CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES and omits them from the compile
97-
# database, so clang-tidy, which ignores $NIX_CFLAGS_COMPILE, can't find capnp
98-
# headers. Setting them as standard passes them to clang-tidy.
99-
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
10093
endif()
10194

10295
option(MP_ENABLE_IWYU "Run include-what-you-use with the compiler." OFF)
@@ -111,6 +104,15 @@ if(MP_ENABLE_IWYU)
111104
endif()
112105
endif()
113106

107+
if(MP_ENABLE_CLANG_TIDY OR MP_ENABLE_IWYU)
108+
# Workaround for nix from https://gitlab.kitware.com/cmake/cmake/-/issues/20912#note_793338
109+
# Nix injects header paths via $NIX_CFLAGS_COMPILE; CMake tags these as
110+
# CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES and omits them from the compile
111+
# database, so clang-tidy, which ignores $NIX_CFLAGS_COMPILE, can't find capnp
112+
# headers. Setting them as standard passes them to clang-tidy.
113+
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
114+
endif()
115+
114116
include("cmake/compat_config.cmake")
115117
include("cmake/pthread_checks.cmake")
116118
include(GNUInstallDirs)

0 commit comments

Comments
 (0)