summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorJohn Parent <john.parent@kitware.com>2021-12-07 19:43:30 (GMT)
committerBrad King <brad.king@kitware.com>2021-12-17 13:55:21 (GMT)
commitd7b18895bcc707ed58beed9e17434341e60a6060 (patch)
tree9c4dfc589a843668d2d642a864f7002060a6822f /Source
parent029c8f50652415baf4aa3dd96c9a8dc9626ae4ec (diff)
downloadCMake-d7b18895bcc707ed58beed9e17434341e60a6060.zip
CMake-d7b18895bcc707ed58beed9e17434341e60a6060.tar.gz
CMake-d7b18895bcc707ed58beed9e17434341e60a6060.tar.bz2
cmake: Add filtered debug-find options
Add a `--debug-find-pkg=` option to debug find calls for specific packages. Add a `--debug-find-var=` option to debug find calls for specific return variables. Fixes: #21880
Diffstat (limited to 'Source')
-rw-r--r--Source/cmFindCommon.cxx6
-rw-r--r--Source/cmFindCommon.h3
-rw-r--r--Source/cmFindLibraryCommand.cxx3
-rw-r--r--Source/cmFindPackageCommand.cxx14
-rw-r--r--Source/cmFindPackageCommand.h2
-rw-r--r--Source/cmFindPathCommand.cxx3
-rw-r--r--Source/cmFindProgramCommand.cxx3
-rw-r--r--Source/cmake.cxx51
-rw-r--r--Source/cmake.h9
-rw-r--r--Source/cmakemain.cxx4
10 files changed, 88 insertions, 10 deletions
diff --git a/Source/cmFindCommon.cxx b/Source/cmFindCommon.cxx
index 70d59c2..7631583 100644
--- a/Source/cmFindCommon.cxx
+++ b/Source/cmFindCommon.cxx
@@ -77,6 +77,12 @@ bool cmFindCommon::ComputeIfDebugModeWanted()
this->Makefile->GetCMakeInstance()->GetDebugFindOutput();
}
+bool cmFindCommon::ComputeIfDebugModeWanted(std::string const& var)
+{
+ return this->ComputeIfDebugModeWanted() ||
+ this->Makefile->GetCMakeInstance()->GetDebugFindOutput(var);
+}
+
void cmFindCommon::InitializeSearchPathGroups()
{
std::vector<PathLabel>* labels;
diff --git a/Source/cmFindCommon.h b/Source/cmFindCommon.h
index f84242e..1a49aff 100644
--- a/Source/cmFindCommon.h
+++ b/Source/cmFindCommon.h
@@ -99,8 +99,9 @@ protected:
void SelectDefaultSearchModes();
/** The `InitialPass` functions of the child classes should set
- this->DebugMode to the result of this. */
+ this->DebugMode to the result of these. */
bool ComputeIfDebugModeWanted();
+ bool ComputeIfDebugModeWanted(std::string const& var);
// Path arguments prior to path manipulation routines
std::vector<std::string> UserHintsArgs;
diff --git a/Source/cmFindLibraryCommand.cxx b/Source/cmFindLibraryCommand.cxx
index ff04bab..1c4039b 100644
--- a/Source/cmFindLibraryCommand.cxx
+++ b/Source/cmFindLibraryCommand.cxx
@@ -32,13 +32,14 @@ cmFindLibraryCommand::cmFindLibraryCommand(cmExecutionStatus& status)
// cmFindLibraryCommand
bool cmFindLibraryCommand::InitialPass(std::vector<std::string> const& argsIn)
{
- this->DebugMode = this->ComputeIfDebugModeWanted();
this->CMakePathName = "LIBRARY";
if (!this->ParseArguments(argsIn)) {
return false;
}
+ this->DebugMode = this->ComputeIfDebugModeWanted(this->VariableName);
+
if (this->AlreadyDefined) {
this->NormalizeFindResult();
return true;
diff --git a/Source/cmFindPackageCommand.cxx b/Source/cmFindPackageCommand.cxx
index 694eb0f..6d788e4 100644
--- a/Source/cmFindPackageCommand.cxx
+++ b/Source/cmFindPackageCommand.cxx
@@ -33,6 +33,7 @@
#include "cmSystemTools.h"
#include "cmValue.h"
#include "cmVersion.h"
+#include "cmake.h"
#if defined(__HAIKU__)
# include <FindDirectory.h>
@@ -144,9 +145,6 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
this->RequiredCMakeVersion = CMake_VERSION_ENCODE(v[0], v[1], v[2]);
}
- this->DebugMode = this->ComputeIfDebugModeWanted();
- this->DebugBuffer.clear();
-
// Lookup target architecture, if any.
if (cmValue arch =
this->Makefile->GetDefinition("CMAKE_LIBRARY_ARCHITECTURE")) {
@@ -236,6 +234,10 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
// Always search directly in a generated path.
this->SearchPathSuffixes.emplace_back();
+ // Process debug mode
+ this->DebugMode = this->ComputeIfDebugModeWanted(this->Name);
+ this->DebugBuffer.clear();
+
// Parse the arguments.
enum Doing
{
@@ -619,6 +621,12 @@ bool cmFindPackageCommand::InitialPass(std::vector<std::string> const& args)
return loadedPackage;
}
+bool cmFindPackageCommand::ComputeIfDebugModeWanted(std::string const& var)
+{
+ return this->ComputeIfDebugModeWanted() ||
+ this->Makefile->GetCMakeInstance()->GetDebugFindPkgOutput(var);
+}
+
bool cmFindPackageCommand::FindPackageUsingModuleMode()
{
bool foundModule = false;
diff --git a/Source/cmFindPackageCommand.h b/Source/cmFindPackageCommand.h
index edf32d4..9d6eddf 100644
--- a/Source/cmFindPackageCommand.h
+++ b/Source/cmFindPackageCommand.h
@@ -40,6 +40,7 @@ class cmSearchPath;
class cmFindPackageCommand : public cmFindCommon
{
public:
+ using cmFindCommon::ComputeIfDebugModeWanted;
/*! A sorting order strategy to be applied to recovered package folders (see
* FIND_PACKAGE_SORT_ORDER)*/
enum /*class*/ SortOrderType
@@ -120,6 +121,7 @@ private:
bool ReadListFile(const std::string& f, PolicyScopeRule psr);
void StoreVersionFound();
+ bool ComputeIfDebugModeWanted(std::string const& var);
void ComputePrefixes();
void FillPrefixesPackageRoot();
void FillPrefixesCMakeEnvironment();
diff --git a/Source/cmFindPathCommand.cxx b/Source/cmFindPathCommand.cxx
index 3d21167..a0a8570 100644
--- a/Source/cmFindPathCommand.cxx
+++ b/Source/cmFindPathCommand.cxx
@@ -29,13 +29,14 @@ cmFindPathCommand::cmFindPathCommand(cmExecutionStatus& status)
// cmFindPathCommand
bool cmFindPathCommand::InitialPass(std::vector<std::string> const& argsIn)
{
- this->DebugMode = this->ComputeIfDebugModeWanted();
this->CMakePathName = "INCLUDE";
if (!this->ParseArguments(argsIn)) {
return false;
}
+ this->DebugMode = this->ComputeIfDebugModeWanted(this->VariableName);
+
if (this->AlreadyDefined) {
this->NormalizeFindResult();
return true;
diff --git a/Source/cmFindProgramCommand.cxx b/Source/cmFindProgramCommand.cxx
index 9a4b063..780b256 100644
--- a/Source/cmFindProgramCommand.cxx
+++ b/Source/cmFindProgramCommand.cxx
@@ -177,13 +177,14 @@ cmFindProgramCommand::cmFindProgramCommand(cmExecutionStatus& status)
// cmFindProgramCommand
bool cmFindProgramCommand::InitialPass(std::vector<std::string> const& argsIn)
{
- this->DebugMode = this->ComputeIfDebugModeWanted();
+
this->CMakePathName = "PROGRAM";
// call cmFindBase::ParseArguments
if (!this->ParseArguments(argsIn)) {
return false;
}
+ this->DebugMode = this->ComputeIfDebugModeWanted(this->VariableName);
if (this->AlreadyDefined) {
this->NormalizeFindResult();
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index 9efdb54..2a3ef9b 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -968,7 +968,34 @@ void cmake::SetArgs(const std::vector<std::string>& args)
"--debug-find", CommandArgument::Values::Zero,
[](std::string const&, cmake* state) -> bool {
std::cout << "Running with debug output on for the `find` commands.\n";
- state->SetDebugFindOutputOn(true);
+ state->SetDebugFindOutput(true);
+ return true;
+ } },
+ CommandArgument{
+ "--debug-find-pkg", "Provide a package argument for --debug-find-pkg",
+ CommandArgument::Values::One, CommandArgument::RequiresSeparator::Yes,
+ [](std::string const& value, cmake* state) -> bool {
+ std::vector<std::string> find_pkgs(cmTokenize(value, ","));
+ std::cout << "Running with debug output on for the 'find' commands "
+ "for package(s)";
+ for (auto const& v : find_pkgs) {
+ std::cout << " " << v;
+ state->SetDebugFindOutputPkgs(v);
+ }
+ std::cout << ".\n";
+ return true;
+ } },
+ CommandArgument{
+ "--debug-find-var", CommandArgument::Values::One,
+ CommandArgument::RequiresSeparator::Yes,
+ [](std::string const& value, cmake* state) -> bool {
+ std::vector<std::string> find_vars(cmTokenize(value, ","));
+ std::cout << "Running with debug output on for the variable(s)";
+ for (auto const& v : find_vars) {
+ std::cout << " " << v;
+ state->SetDebugFindOutputVars(v);
+ }
+ std::cout << ".\n";
return true;
} },
CommandArgument{ "--trace-expand", CommandArgument::Values::Zero,
@@ -1325,7 +1352,7 @@ void cmake::SetArgs(const std::vector<std::string>& args)
this->DebugTryCompileOn();
}
if (expandedPreset->DebugFind == true) {
- this->SetDebugFindOutputOn(true);
+ this->SetDebugFindOutput(true);
}
}
#endif
@@ -3619,6 +3646,26 @@ void cmake::SetDeprecatedWarningsAsErrors(bool b)
cmStateEnums::INTERNAL);
}
+void cmake::SetDebugFindOutputPkgs(std::string const& args)
+{
+ this->DebugFindPkgs.emplace(args);
+}
+
+void cmake::SetDebugFindOutputVars(std::string const& args)
+{
+ this->DebugFindVars.emplace(args);
+}
+
+bool cmake::GetDebugFindOutput(std::string const& var) const
+{
+ return this->DebugFindVars.count(var);
+}
+
+bool cmake::GetDebugFindPkgOutput(std::string const& pkg) const
+{
+ return this->DebugFindPkgs.count(pkg);
+}
+
#if !defined(CMAKE_BOOTSTRAP)
cmMakefileProfilingData& cmake::GetProfilingOutput()
{
diff --git a/Source/cmake.h b/Source/cmake.h
index 3f2b2ed..a356e65 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -486,7 +486,11 @@ public:
//! Do we want debug output from the find commands during the cmake run.
bool GetDebugFindOutput() const { return this->DebugFindOutput; }
- void SetDebugFindOutputOn(bool b) { this->DebugFindOutput = b; }
+ bool GetDebugFindOutput(std::string const& var) const;
+ bool GetDebugFindPkgOutput(std::string const& var) const;
+ void SetDebugFindOutput(bool b) { this->DebugFindOutput = b; }
+ void SetDebugFindOutputPkgs(std::string const& args);
+ void SetDebugFindOutputVars(std::string const& args);
//! Do we want trace output during the cmake run.
bool GetTrace() const { return this->Trace; }
@@ -704,6 +708,9 @@ private:
std::vector<std::string> TraceOnlyThisSources;
+ std::set<std::string> DebugFindPkgs;
+ std::set<std::string> DebugFindVars;
+
LogLevel MessageLogLevel = LogLevel::LOG_STATUS;
bool LogLevelWasSetViaCLI = false;
bool LogContext = false;
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 61d4ae4..00aafdc 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -90,6 +90,10 @@ const char* cmDocumentationOptions[][2] = {
"useful on one try_compile at a time." },
{ "--debug-output", "Put cmake in a debug mode." },
{ "--debug-find", "Put cmake find in a debug mode." },
+ { "--debug-find-pkg=<pkg-name>[,...]",
+ "Limit cmake debug-find to the comma-separated list of packages" },
+ { "--debug-find-var=<var-name>[,...]",
+ "Limit cmake debug-find to the comma-separated list of result variables" },
{ "--trace", "Put cmake in trace mode." },
{ "--trace-expand", "Put cmake in trace mode with variable expansion." },
{ "--trace-format=<human|json-v1>", "Set the output format of the trace." },