cmDebugTools: offer a way to disable CM_DBG output at runtime

This allows information to be gathered while debugging while also
supporting running the test suite with the debugging enabled to test
CMake module changes without tripping `stderr` output checkers.
This commit is contained in:
Ben Boeckel
2024-02-24 17:20:45 -05:00
parent 709f4ea1de
commit 68b32ff801

View File

@@ -4,6 +4,8 @@
#include <iostream>
#include "cmSystemTools.h"
#define CM_DBG(expr) cm::dbg_impl(__FILE__, __LINE__, #expr, expr)
namespace cm {
@@ -13,8 +15,10 @@ namespace {
template <typename T>
T dbg_impl(const char* fname, int line, const char* expr, T value)
{
std::cerr << fname << ':' << line << ": " << expr << " = " << value
<< std::endl;
if (!cmSystemTools::GetEnvVar("CMAKE_NO_DBG")) {
std::cerr << fname << ':' << line << ": " << expr << " = " << value
<< std::endl;
}
return value;
}