cmake issue with clang-scan-deps and macosx

Hello,

cmake version 3.31.7
clang version 21.1.5
ninja version 1.13.1

Trying to cmake the following simple C++ coding and the following CMakeLists.txt with my macosx ..

#include
#include <memory_resource>
#include
#include

int main() {

std::pmr::unsynchronized_pool_resource pool3({
    .max_blocks_per_chunk = 64,
    .largest_required_pool_block = 512,
});

std::pmr::list<std::pmr::string> list6(&pool3);
list6.emplace_back("this string is long enough");

for (auto& l : list6)
  std::cout << l << '\n' ;

return 0;

}

$ cat CMakeLists.txt

cmake_minimum_required(VERSION 3.31)
set(CMAKE_C_COMPILER /opt/local/bin/clang CACHE STRING “C compiler” FORCE)
set(CMAKE_CXX_COMPILER /opt/local/bin/clang++ CACHE STRING “C++ compiler” FORCE)
set(CMAKE_CXX_COMPILER_LINKER /opt/local/libexec/llvm-21/bin/lld)
set(CMAKE_CXX_COMPILER_CLANG_SCAN_DEPS /opt/local/libexec/llvm-21/bin/clang-scan-deps)
project(test-macosx VERSION 0.0.0.1 LANGUAGES C CXX)
set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_EXE_LINKER_FLAGS “-L/opt/local/libexec/llvm-21/lib/libc++ -L/opt/local/libexec/llvm-21/lib/libunwind -lc++ -lc++abi -Wl,-rpath /opt/local/libexec/llvm-21/lib/libc++ -Wl,-rpath /opt/local/libexec/llvm-21/lib/libunwind”)
set(CMAKE_PREFIX_PATH /opt/local/libexec/llvm-21/lib/cmake/llvm)
find_package(LLVM REQUIRED CONFIG)
add_executable(a.out clang.cpp)
target_compile_options(a.out PRIVATE -stdlib=libc++ -lc++abi -fexperimental-library)

With a basic (non scan-deps usage) cmake is behaving all ok ..

$ cmake -S . -B build ; cmake --build build

– The C compiler identification is Clang 21.1.5
– The CXX compiler identification is Clang 21.1.5
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Check for working C compiler: /opt/local/bin/clang - skipped
– Detecting C compile features
– Detecting C compile features - done
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: /opt/local/bin/clang++ - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
– Performing Test HAVE_FFI_CALL
– Performing Test HAVE_FFI_CALL - Success
– Found FFI: /opt/local/lib/libffi.dylib
– Looking for histedit.h
– Looking for histedit.h - found
– Found LibEdit: /opt/local/include (found version “2.11”)
– Found ZLIB: /opt/local/lib/libz.dylib (found version “1.3.1”)
– Found zstd: /opt/local/lib/libzstd.dylib
– Found LibXml2: /opt/local/lib/libxml2.dylib (found version “2.13.9”)
– Configuring done (7.9s)
– Generating done (0.0s)
– Build files have been written to: /Users/vbl/Development/test/build
[ 50%] Building CXX object CMakeFiles/a.out.dir/clang.cpp.o
clang++: warning: -lc++abi: ‘linker’ input unused [-Wunused-command-line-argument]
[100%] Linking CXX executable a.out
[100%] Built target a.o@rpatht@rpath

$ otool -L a.out
a.out:
@rpath/libc++.1.dylib (compatibility version 1.@r@rpathath.0, current version 1.0.0)
@rpath/libc++abi.1.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1319.0.0)

$ ./a.out
this string is long enough

When doing the same thing including Ninja (with scan-deps usage) it is NOK with macosx … with Linux all is Ok

$ cmake -S . -G Ninja -B build ; cmake --build build

– The C compiler identification is Clang 21.1.5
– The CXX compiler identification is Clang 21.1.5
– Detecting C compiler ABI info
– Detecting C compiler ABI info - done
– Check for working C compiler: /opt/local/bin/clang - skipped
– Detecting C compile features
– Detecting C compile features - done
– Detecting CXX compiler ABI info
– Detecting CXX compiler ABI info - done
– Check for working CXX compiler: /opt/local/bin/clang++ - skipped
– Detecting CXX compile features
– Detecting CXX compile features - done
– Performing Test HAVE_FFI_CALL
– Performing Test HAVE_FFI_CALL - Success
– Found FFI: /opt/local/lib/libffi.dylib
– Looking for histedit.h
– Looking for histedit.h - found
– Found LibEdit: /opt/local/include (found version “2.11”)
– Found ZLIB: /opt/local/lib/libz.dylib (found version “1.3.1”)
– Found zstd: /opt/local/lib/libzstd.dylib
– Found LibXml2: /opt/local/lib/libxml2.dylib (found version “2.13.9”)
– Configuring done (3.4s)
– Generating done (0.0s)
– Build files have been written to: /Users/vbl/Development/test/build
[1/4] Scanning /Users/vbl/Development/test/clang.cpp for CXX dependencies
FAILED: [code=1] CMakeFiles/a.out.dir/clang.cpp.o.ddi
“/opt/local/libexec/llvm-21/bin/clang-scan-deps” -format=p1689 – /opt/local/bin/clang++ -std=gnu++23 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.1.sdk -mmacosx-version-min=12.7 -stdlib=libc++ -lc++abi -fexperimental-library -x c++ /Users/vbl/Development/test/clang.cpp -c -o CMakeFiles/a.out.dir/clang.cpp.o -resource-dir “/opt/local/libexec/llvm-21/lib/clang/21” -MT CMakeFiles/a.out.dir/clang.cpp.o.ddi -MD -MF CMakeFiles/a.out.dir/clang.cpp.o.ddi.d > CMakeFiles/a.out.dir/clang.cpp.o.ddi.tmp && mv CMakeFiles/a.out.dir/clang.cpp.o.ddi.tmp CMakeFiles/a.out.dir/clang.cpp.o.ddi
warning: -lc++abi: ‘linker’ input unused
Error while scanning dependencies for /Users/vbl/Development/test/clang.cpp:
warning: -lc++abi: ‘linker’ input unused [-Wunused-command-line-argument]
/Users/vbl/Development/test/clang.cpp:2:10: fatal error: ‘memory_resource’ file not found
ninja: build stopped: subcommand failed.

anything I missed somewhere ?? .. looks with adding scan-deps it is not behaving the same ?? .. and pointing to an older clang thing ..

thanks in advance with your help ..