check_c_source_compiles doesn't handle properly escaped source code.
Originally found on CMake discourse: https://discourse.cmake.org/t/syntax-error-in-cmake-code-at-usr-share-cmake-modules-checkcsourcecompiles-cmake-59/10432
Properly escaped code isn't accepted by check_c_source_compiles
.
Here is a small example to illustrate the issue:
include(CheckCSourceCompiles)
check_c_source_compiles("int main() { return '\\0'; }" RESULT)
The aforementioned code will fail:
when parsing string
int main() { return '\0'; }
Invalid character escape '\0'.
The route cause is issue #19281
Although a quick solution might be replace the implementation with a function.
The above situation also applies to other CMake modules that must accept arbitrary code:
check_c_source_runs
, check_cxx_source_compiles
, check_cxx_source_runs
, etc.