Issue
I am starting a Clang tool project, so I built the LLVM/Clang from source code using Cmake and ninja. There are two folders -- src/
and build/
. Then I created my project folder as src/tools/clang/tools/extra/my-tool and added add_subdirectory(my-tool)
to the tools/clang/tools/extra/CMakeLists.txt. However, every time I modify the file under my project folder and run ninja
under build/, the system sometimes only builds the modified file but sometimes rebuilds all files (more than 3000 tasks), which is very slow. I am wondering what causes the rebuilding?
BTW, the situation also happens when I modify another project, which uses the Google's Bazel building system. I am suspecting the file time-stamp is changed randomly?
Solution
I had a similar problem with ninja
and my GNU based toolchain. After a lot of trial and error I found that CMake/ninja
scanned the standard include directories and sometimes concluded that those header files have changed.
So changing the dependency checking options to exclude system includes did solve this problem.
Add the following CMake code - probably with some changes for Clang - before your project()
command or inside your toolchain file:
if (CMAKE_GENERATOR MATCHES "Ninja")
file(
WRITE "${CMAKE_BINARY_DIR}/GNUMakeRulesOverwrite.cmake"
"STRING(REPLACE \"-MD\" \"-MMD\" CMAKE_DEPFILE_FLAGS_C \"\${CMAKE_DEPFILE_FLAGS_C}\")\n"
"STRING(REPLACE \"-MD\" \"-MMD\" CMAKE_DEPFILE_FLAGS_CXX \"\${CMAKE_DEPFILE_FLAGS_CXX}\")\n"
)
set(CMAKE_USER_MAKE_RULES_OVERRIDE "${CMAKE_BINARY_DIR}/GNUMakeRulesOverwrite.cmake" CACHE INTERNAL "")
)
Answered By - Florian Answer Checked By - Willingham (WPSolving Volunteer)