Import std in clang with custom stdlibc++

Merge request 10727 added support for import std using clang and stdlibc++. I use clang with a custom gcc installation passed through a flag --gcc-install-dir via CMAKE_CXX_FLAGS.

In the Clang-CXX-CXXImportStd.cmake file, there is the following call:

execute_process(
    COMMAND
      "${CMAKE_CXX_COMPILER}"
      ${CMAKE_CXX_COMPILER_ID_ARG1}
      "-print-file-name=${_clang_modules_json_impl}.modules.json"
    OUTPUT_VARIABLE _clang_libcxx_modules_json_file
    ERROR_VARIABLE _clang_libcxx_modules_json_file_err
    RESULT_VARIABLE _clang_libcxx_modules_json_file_res
    OUTPUT_STRIP_TRAILING_WHITESPACE
    ERROR_STRIP_TRAILING_WHITESPACE)

This call ignores CMAKE_CXX_FLAGS so it uses the gcc12 installed on my system and libstdc++.modules.json isn’t found. Is this a bug or can I somehow pass --gcc-install-dir to this call or specify a path to libstdc++.modules.json by hand?

Hmm. Does adding ${CMAKE_CXX_FLAGS} to the argument list fix it?