CMake/Tests/MSVCRuntimeChecks/verify.h
AJIOB 2b2344b412 MSVC: Add abstraction for runtime checks
Replace our hard-coded default for `/RTC1` with a first-class
abstraction to select runtime checks from an enumeration of logical
names.  Add a `MSVC_RUNTIME_CHECKS` target property and corresponding
`CMAKE_MSVC_RUNTIME_CHECKS` variable.

Removing the old default flag requires a policy because existing
projects may rely on string processing to edit them and choose
runtime checks under the old behavior.  Add policy CMP0184 to
provide compatibility.

Fixes: #26614
2025-01-29 13:07:41 -05:00

62 lines
2.1 KiB
C

/* Some compilers ignore the -RTC flags even if specified. */
#if (defined(_MSC_VER) && _MSC_VER <= 1310) || defined(__clang__) || \
defined(__INTEL_LLVM_COMPILER) || defined(__INTEL_COMPILER)
# define NO__MSVC_RUNTIME_CHECKS
#endif
#ifdef VERIFY_RTCc
# ifndef TEST_RTCc
# error "TEST_RTCc incorrectly not defined by enabled runtime check"
# endif
# if !defined(__MSVC_RUNTIME_CHECKS) && !defined(NO__MSVC_RUNTIME_CHECKS)
# error \
"__MSVC_RUNTIME_CHECKS incorrectly not defined by enabled RTCc runtime check"
# endif
#else
# ifdef TEST_RTCc
# error "TEST_RTCc incorrectly defined by disabled runtime check"
# endif
#endif
#ifdef VERIFY_RTCs
# ifndef TEST_RTCs
# error "TEST_RTCs incorrectly not defined by enabled runtime check"
# endif
# if !defined(__MSVC_RUNTIME_CHECKS) && !defined(NO__MSVC_RUNTIME_CHECKS)
# error \
"__MSVC_RUNTIME_CHECKS incorrectly not defined by enabled RTCs runtime check"
# endif
#else
# ifdef TEST_RTCs
# error "TEST_RTCs incorrectly defined by disabled runtime check"
# endif
#endif
#ifdef VERIFY_RTCu
# ifndef TEST_RTCu
# error "TEST_RTCu incorrectly not defined by enabled runtime check"
# endif
# if !defined(__MSVC_RUNTIME_CHECKS) && !defined(NO__MSVC_RUNTIME_CHECKS)
# error \
"__MSVC_RUNTIME_CHECKS incorrectly not defined by enabled RTCu runtime check"
# endif
#else
# ifdef TEST_RTCu
# error "TEST_RTCu incorrectly defined by disabled runtime check"
# endif
#endif
#ifdef VERIFY_RTCsu
# ifndef TEST_RTCsu
# error "TEST_RTCsu incorrectly not defined by enabled runtime check"
# endif
# if !defined(__MSVC_RUNTIME_CHECKS) && !defined(NO__MSVC_RUNTIME_CHECKS)
# error \
"__MSVC_RUNTIME_CHECKS incorrectly not defined by enabled RTCsu runtime check"
# endif
#else
# ifdef TEST_RTCsu
# error "TEST_RTCsu incorrectly defined by disabled runtime check"
# endif
#endif