cmake __FILE_NAME__ in a portable way?

gcc 12 has __FILE__NAME__ defined which is a great improvement to __FILE__ for reducing the string contamination in the binaries. In the lack of gcc 12, is there a way to have cmake generate a base file name to the pre-processed file in a portable way? If often see this makefile hack in cmake, but this does not work on e.g. ninja

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")

I was trying to make use of -fmacro-prefix-map, so at least I can eliminate the path to the source tree, but it does not give me the base name of the file.

AFAIK, there’s no portable way to do this without per-source properties setting some common define.

I see. If I decide to backport this to an older gcc, can I then with cmake check if the builtin macro exists? Similar way that check_symbol_exists works but for gcc macros…

check_symbol_exists should work for macros too.