Try workaround like
SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX14.sdk/ cmake -Bbuild
cmake --build build
that worked on the trivial project above. It seems that the current Homebrew GCC 14.2 doesn’t want the new 15.0 SDK that CMake grabs by default.