1
0
mirror of https://github.com/Kitware/CMake.git synced 2025-10-16 05:26:58 +08:00

cmFindCommon: use DebugModeEnabled to query for debug mode

This simplifies changing how debug mode is represented.
This commit is contained in:
Ben Boeckel
2025-04-09 14:11:59 +02:00
parent 76ea613f4c
commit bd5cb1f8e6
4 changed files with 28 additions and 28 deletions

View File

@@ -660,7 +660,7 @@ cmFindBaseDebugState::~cmFindBaseDebugState()
} }
#endif #endif
if (!this->FindCommand->DebugMode) { if (!this->FindCommand->DebugModeEnabled()) {
return; return;
} }

View File

@@ -226,14 +226,14 @@ void cmFindCommon::RerootPaths(std::vector<std::string>& paths,
return; return;
} }
if (this->DebugMode && debugBuffer) { if (this->DebugModeEnabled() && debugBuffer) {
*debugBuffer = cmStrCat( *debugBuffer = cmStrCat(
*debugBuffer, "Prepending the following roots to each prefix:\n"); *debugBuffer, "Prepending the following roots to each prefix:\n");
} }
auto debugRoot = [this, debugBuffer](std::string const& name, auto debugRoot = [this, debugBuffer](std::string const& name,
cmValue value) { cmValue value) {
if (this->DebugMode && debugBuffer) { if (this->DebugModeEnabled() && debugBuffer) {
*debugBuffer = cmStrCat(*debugBuffer, name, '\n'); *debugBuffer = cmStrCat(*debugBuffer, name, '\n');
cmList roots{ value }; cmList roots{ value };
if (roots.empty()) { if (roots.empty()) {

View File

@@ -85,7 +85,7 @@ void cmFindLibraryCommand::AddArchitecturePaths(char const* suffix)
original.swap(this->SearchPaths); original.swap(this->SearchPaths);
for (std::string const& o : original) { for (std::string const& o : original) {
this->AddArchitecturePath(o, 0, suffix); this->AddArchitecturePath(o, 0, suffix);
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string msg = cmStrCat( std::string msg = cmStrCat(
"find_library(", this->VariableName, ") removed original suffix ", o, "find_library(", this->VariableName, ") removed original suffix ", o,
" from PATH_SUFFIXES while adding architecture paths for suffix '", " from PATH_SUFFIXES while adding architecture paths for suffix '",
@@ -153,7 +153,7 @@ void cmFindLibraryCommand::AddArchitecturePath(
if (use_dirX) { if (use_dirX) {
dirX += "/"; dirX += "/";
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string msg = cmStrCat( std::string msg = cmStrCat(
"find_library(", this->VariableName, ") added replacement path ", "find_library(", this->VariableName, ") added replacement path ",
dirX, " to PATH_SUFFIXES for architecture suffix '", suffix, "'"); dirX, " to PATH_SUFFIXES for architecture suffix '", suffix, "'");
@@ -164,7 +164,7 @@ void cmFindLibraryCommand::AddArchitecturePath(
if (use_dir) { if (use_dir) {
this->SearchPaths.push_back(dir); this->SearchPaths.push_back(dir);
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string msg = cmStrCat( std::string msg = cmStrCat(
"find_library(", this->VariableName, ") added replacement path ", "find_library(", this->VariableName, ") added replacement path ",
dir, " to PATH_SUFFIXES for architecture suffix '", suffix, "'"); dir, " to PATH_SUFFIXES for architecture suffix '", suffix, "'");

View File

@@ -1073,12 +1073,12 @@ bool cmFindPackageCommand::FindPackage(
cmState::Command const providerCommand = state->GetDependencyProviderCommand( cmState::Command const providerCommand = state->GetDependencyProviderCommand(
cmDependencyProvider::Method::FindPackage); cmDependencyProvider::Method::FindPackage);
if (argsForProvider.empty()) { if (argsForProvider.empty()) {
if (this->DebugMode && providerCommand) { if (this->DebugModeEnabled() && providerCommand) {
this->DebugMessage( this->DebugMessage(
"BYPASS_PROVIDER given, skipping dependency provider"); "BYPASS_PROVIDER given, skipping dependency provider");
} }
} else if (providerCommand) { } else if (providerCommand) {
if (this->DebugMode) { if (this->DebugModeEnabled()) {
this->DebugMessage(cmStrCat("Trying dependency provider command: ", this->DebugMessage(cmStrCat("Trying dependency provider command: ",
state->GetDependencyProvider()->GetCommand(), state->GetDependencyProvider()->GetCommand(),
"()")); "()"));
@@ -1095,7 +1095,7 @@ bool cmFindPackageCommand::FindPackage(
return false; return false;
} }
if (this->Makefile->IsOn(cmStrCat(this->Name, "_FOUND"))) { if (this->Makefile->IsOn(cmStrCat(this->Name, "_FOUND"))) {
if (this->DebugMode) { if (this->DebugModeEnabled()) {
this->DebugMessage("Package was found by the dependency provider"); this->DebugMessage("Package was found by the dependency provider");
} }
this->AppendSuccessInformation(); this->AppendSuccessInformation();
@@ -1447,8 +1447,8 @@ bool cmFindPackageCommand::FindModule(bool& found)
std::string debugBuffer = cmStrCat( std::string debugBuffer = cmStrCat(
"find_package considered the following paths for ", moduleFileName, ":\n"); "find_package considered the following paths for ", moduleFileName, ":\n");
std::string mfile = this->Makefile->GetModulesFile( std::string mfile = this->Makefile->GetModulesFile(
moduleFileName, system, this->DebugMode, debugBuffer); moduleFileName, system, this->DebugModeEnabled(), debugBuffer);
if (this->DebugMode) { if (this->DebugModeEnabled()) {
if (mfile.empty()) { if (mfile.empty()) {
debugBuffer = cmStrCat(debugBuffer, "The file was not found.\n"); debugBuffer = cmStrCat(debugBuffer, "The file was not found.\n");
} else { } else {
@@ -1487,7 +1487,7 @@ bool cmFindPackageCommand::FindModule(bool& found)
bool result = this->ReadListFile(mfile, DoPolicyScope); bool result = this->ReadListFile(mfile, DoPolicyScope);
this->Makefile->RemoveDefinition(var); this->Makefile->RemoveDefinition(var);
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string const foundVar = cmStrCat(this->Name, "_FOUND"); std::string const foundVar = cmStrCat(this->Name, "_FOUND");
if (this->Makefile->IsDefinitionSet(foundVar) && if (this->Makefile->IsDefinitionSet(foundVar) &&
!this->Makefile->IsOn(foundVar)) { !this->Makefile->IsOn(foundVar)) {
@@ -1797,7 +1797,7 @@ bool cmFindPackageCommand::FindConfig()
// Look for the project's configuration file. // Look for the project's configuration file.
bool found = false; bool found = false;
if (this->DebugMode) { if (this->DebugModeEnabled()) {
this->DebugBuffer = cmStrCat(this->DebugBuffer, this->DebugBuffer = cmStrCat(this->DebugBuffer,
"find_package considered the following " "find_package considered the following "
"locations for ", "locations for ",
@@ -1833,7 +1833,7 @@ bool cmFindPackageCommand::FindConfig()
found = this->FindAppBundleConfig(); found = this->FindAppBundleConfig();
} }
if (this->DebugMode) { if (this->DebugModeEnabled()) {
if (found) { if (found) {
this->DebugBuffer = cmStrCat( this->DebugBuffer = cmStrCat(
this->DebugBuffer, "The file was found at\n ", this->FileFound, '\n'); this->DebugBuffer, "The file was found at\n ", this->FileFound, '\n');
@@ -2322,7 +2322,7 @@ void cmFindPackageCommand::FillPrefixesPackageRedirect()
if (redirectDir && !redirectDir->empty()) { if (redirectDir && !redirectDir->empty()) {
paths.AddPath(*redirectDir); paths.AddPath(*redirectDir);
} }
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string debugBuffer = std::string debugBuffer =
"The internally managed CMAKE_FIND_PACKAGE_REDIRECTS_DIR.\n"; "The internally managed CMAKE_FIND_PACKAGE_REDIRECTS_DIR.\n";
collectPathsForDebug(debugBuffer, paths); collectPathsForDebug(debugBuffer, paths);
@@ -2342,7 +2342,7 @@ void cmFindPackageCommand::FillPrefixesPackageRoot()
paths.AddPath(path); paths.AddPath(path);
} }
} }
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string debugBuffer = "<PackageName>_ROOT CMake variable " std::string debugBuffer = "<PackageName>_ROOT CMake variable "
"[CMAKE_FIND_USE_PACKAGE_ROOT_PATH].\n"; "[CMAKE_FIND_USE_PACKAGE_ROOT_PATH].\n";
collectPathsForDebug(debugBuffer, paths); collectPathsForDebug(debugBuffer, paths);
@@ -2359,7 +2359,7 @@ void cmFindPackageCommand::FillPrefixesCMakeEnvironment()
// Check the environment variable with the same name as the cache // Check the environment variable with the same name as the cache
// entry. // entry.
paths.AddEnvPath(this->Variable); paths.AddEnvPath(this->Variable);
if (this->DebugMode) { if (this->DebugModeEnabled()) {
debugBuffer = cmStrCat("Env variable ", this->Variable, debugBuffer = cmStrCat("Env variable ", this->Variable,
" [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n"); " [CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n");
debugOffset = collectPathsForDebug(debugBuffer, paths); debugOffset = collectPathsForDebug(debugBuffer, paths);
@@ -2367,7 +2367,7 @@ void cmFindPackageCommand::FillPrefixesCMakeEnvironment()
// And now the general CMake environment variables // And now the general CMake environment variables
paths.AddEnvPath("CMAKE_PREFIX_PATH"); paths.AddEnvPath("CMAKE_PREFIX_PATH");
if (this->DebugMode) { if (this->DebugModeEnabled()) {
debugBuffer = cmStrCat(debugBuffer, debugBuffer = cmStrCat(debugBuffer,
"CMAKE_PREFIX_PATH env variable " "CMAKE_PREFIX_PATH env variable "
"[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n"); "[CMAKE_FIND_USE_CMAKE_ENVIRONMENT_PATH].\n");
@@ -2376,7 +2376,7 @@ void cmFindPackageCommand::FillPrefixesCMakeEnvironment()
paths.AddEnvPath("CMAKE_FRAMEWORK_PATH"); paths.AddEnvPath("CMAKE_FRAMEWORK_PATH");
paths.AddEnvPath("CMAKE_APPBUNDLE_PATH"); paths.AddEnvPath("CMAKE_APPBUNDLE_PATH");
if (this->DebugMode) { if (this->DebugModeEnabled()) {
debugBuffer = debugBuffer =
cmStrCat(debugBuffer, cmStrCat(debugBuffer,
"CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env " "CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH env "
@@ -2393,14 +2393,14 @@ void cmFindPackageCommand::FillPrefixesCMakeVariable()
std::size_t debugOffset = 0; std::size_t debugOffset = 0;
paths.AddCMakePath("CMAKE_PREFIX_PATH"); paths.AddCMakePath("CMAKE_PREFIX_PATH");
if (this->DebugMode) { if (this->DebugModeEnabled()) {
debugBuffer = "CMAKE_PREFIX_PATH variable [CMAKE_FIND_USE_CMAKE_PATH].\n"; debugBuffer = "CMAKE_PREFIX_PATH variable [CMAKE_FIND_USE_CMAKE_PATH].\n";
debugOffset = collectPathsForDebug(debugBuffer, paths); debugOffset = collectPathsForDebug(debugBuffer, paths);
} }
paths.AddCMakePath("CMAKE_FRAMEWORK_PATH"); paths.AddCMakePath("CMAKE_FRAMEWORK_PATH");
paths.AddCMakePath("CMAKE_APPBUNDLE_PATH"); paths.AddCMakePath("CMAKE_APPBUNDLE_PATH");
if (this->DebugMode) { if (this->DebugModeEnabled()) {
debugBuffer = debugBuffer =
cmStrCat(debugBuffer, cmStrCat(debugBuffer,
"CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables " "CMAKE_FRAMEWORK_PATH and CMAKE_APPBUNDLE_PATH variables "
@@ -2427,7 +2427,7 @@ void cmFindPackageCommand::FillPrefixesSystemEnvironment()
paths.AddPath(i); paths.AddPath(i);
} }
} }
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string debugBuffer = "Standard system environment variables " std::string debugBuffer = "Standard system environment variables "
"[CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH].\n"; "[CMAKE_FIND_USE_SYSTEM_ENVIRONMENT_PATH].\n";
collectPathsForDebug(debugBuffer, paths); collectPathsForDebug(debugBuffer, paths);
@@ -2456,7 +2456,7 @@ void cmFindPackageCommand::FillPrefixesUserRegistry()
this->LabeledPaths[PathLabel::UserRegistry]); this->LabeledPaths[PathLabel::UserRegistry]);
} }
#endif #endif
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string debugBuffer = std::string debugBuffer =
"CMake User Package Registry [CMAKE_FIND_USE_PACKAGE_REGISTRY].\n"; "CMake User Package Registry [CMAKE_FIND_USE_PACKAGE_REGISTRY].\n";
collectPathsForDebug(debugBuffer, collectPathsForDebug(debugBuffer,
@@ -2475,7 +2475,7 @@ void cmFindPackageCommand::FillPrefixesSystemRegistry()
this->LoadPackageRegistryWinSystem(); this->LoadPackageRegistryWinSystem();
#endif #endif
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string debugBuffer = std::string debugBuffer =
"CMake System Package Registry " "CMake System Package Registry "
"[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY].\n"; "[CMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY].\n";
@@ -2679,7 +2679,7 @@ void cmFindPackageCommand::FillPrefixesCMakeSystemVariable()
paths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH"); paths.AddCMakePath("CMAKE_SYSTEM_FRAMEWORK_PATH");
paths.AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH"); paths.AddCMakePath("CMAKE_SYSTEM_APPBUNDLE_PATH");
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string debugBuffer = "CMake variables defined in the Platform file " std::string debugBuffer = "CMake variables defined in the Platform file "
"[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH].\n"; "[CMAKE_FIND_USE_CMAKE_SYSTEM_PATH].\n";
collectPathsForDebug(debugBuffer, paths); collectPathsForDebug(debugBuffer, paths);
@@ -2694,7 +2694,7 @@ void cmFindPackageCommand::FillPrefixesUserGuess()
for (std::string const& p : this->UserGuessArgs) { for (std::string const& p : this->UserGuessArgs) {
paths.AddUserPath(p); paths.AddUserPath(p);
} }
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string debugBuffer = std::string debugBuffer =
"Paths specified by the find_package PATHS option.\n"; "Paths specified by the find_package PATHS option.\n";
collectPathsForDebug(debugBuffer, paths); collectPathsForDebug(debugBuffer, paths);
@@ -2709,7 +2709,7 @@ void cmFindPackageCommand::FillPrefixesUserHints()
for (std::string const& p : this->UserHintsArgs) { for (std::string const& p : this->UserHintsArgs) {
paths.AddUserPath(p); paths.AddUserPath(p);
} }
if (this->DebugMode) { if (this->DebugModeEnabled()) {
std::string debugBuffer = std::string debugBuffer =
"Paths specified by the find_package HINTS option.\n"; "Paths specified by the find_package HINTS option.\n";
collectPathsForDebug(debugBuffer, paths); collectPathsForDebug(debugBuffer, paths);
@@ -2764,7 +2764,7 @@ bool cmFindPackageCommand::FindConfigFile(std::string const& dir,
continue; continue;
} }
file = cmStrCat(dir, '/', config.Name); file = cmStrCat(dir, '/', config.Name);
if (this->DebugMode) { if (this->DebugModeEnabled()) {
this->DebugBuffer = cmStrCat(this->DebugBuffer, " ", file, '\n'); this->DebugBuffer = cmStrCat(this->DebugBuffer, " ", file, '\n');
} }
if (cmSystemTools::FileExists(file, true) && this->CheckVersion(file)) { if (cmSystemTools::FileExists(file, true) && this->CheckVersion(file)) {