One can use CheckSourceRuns with the CMAKE_REQUIRED_FLAGS
setting.
It is implemented with try_run
using an undocumented -DCOMPILE_DEFINITIONS=<flags>
entry in CMAKE_FLAGS
. One can see in the implementation that the value of the COMPILE_DEFINITIONS
variable gets appended to CMAKE_<LANG>_FLAGS
in the generated test project.