cmake 3.28 CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS-NOTFOUND: not found

I’m writing code in docker and my dockerfile is as below.

# Add the LLVM repository
RUN apt-get update && \
    apt-get install -y software-properties-common wget jq sudo curl gnupg2 && \
    wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor -o /etc/apt/trusted.gpg.d/llvm-archive-keyring.gpg && \
    echo "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy main" > /etc/apt/sources.list.d/llvm.list && \
    echo "deb-src http://apt.llvm.org/jammy/ llvm-toolchain-jammy main" >> /etc/apt/sources.list.d/llvm.list

# Install development tools, utilities, and zsh
RUN apt-get update && \
    apt-get install -y \
    clang \
    lldb \
    libstdc++-11-dev \
    git \
    unzip \
    zsh && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

when I upgraded to cmake 3.28 I had the issues like below, when switching back to 3.27 it compiles successfully.

[1/4] Scanning /home/Dev/CPU_Sched/src/user_scheduler.cpp for CXX dependencies
FAILED: CMakeFiles/Scheduler.dir/src/user_scheduler.cpp.o.ddi 
"CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS-NOTFOUND" -format=p1689 -- /usr/bin/c++ -DSPDLOG_COMPILED_LIB -I/home/Dev/CPU_Sched/build/_deps/spdlog-src/include -I/home/Dev/CPU_Sched/build/_deps/argparse-src/include -O3 -DNDEBUG -std=c++20 -x c++ /home/Dev/CPU_Sched/src/user_scheduler.cpp -c -o CMakeFiles/Scheduler.dir/src/user_scheduler.cpp.o -MT CMakeFiles/Scheduler.dir/src/user_scheduler.cpp.o.ddi -MD -MF CMakeFiles/Scheduler.dir/src/user_scheduler.cpp.o.ddi.d > CMakeFiles/Scheduler.dir/src/user_scheduler.cpp.o.ddi
/bin/sh: 1: CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS-NOTFOUND: not found
ninja: build stopped: subcommand failed.

What is the cmake_minimum_required call for the project you’re building? Is it setting the C++ standard to 20 or newer?

I have set the version checker

cmake_minimum_required(VERSION 3.28)
project(Foo LANGUAGES CXX)

# Set the C++ standard to C++20
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_FLAGS_DEBUG "-g -O0 -Wall -Wextra -Wpedantic -Werror")


# Export compile commands for use with clangd
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

A minimum version of 3.28 and C++20 will default to scanning all such sources. If you’re not using modules, set(CMAKE_CXX_SCAN_FOR_MODULES 0) to initialize the “this target does not need any module dependency scanning” property.

If you do need scanning, you’ll need to install clang-scan-deps as well. I’m not sure what package that might be in. clang-tools-extra would probably be the Fedora name, but you seem to have Debian/Ubuntu.

After install clang-tidy, everything is work. But the clangd doesn’t recognize the module I defined

I would guess that clang-tidy lives in the same package as clang-scan-deps.

clangd doesn’t know how to build modules yet. You’ll need to have CMake build the modules before clangd will understand them.