summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Help/manual/cmake-presets.7.rst49
-rw-r--r--Help/manual/presets/schema.json107
-rw-r--r--Source/cmCMakePresetErrors.h3
-rw-r--r--Source/cmCMakePresetsGraph.h13
-rw-r--r--Source/cmCMakePresetsGraphReadJSON.cxx10
-rw-r--r--Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx68
-rw-r--r--Source/cmMakefile.cxx8
-rw-r--r--Source/cmStateTypes.h11
-rw-r--r--Source/cmake.cxx104
-rw-r--r--Source/cmake.h10
-rw-r--r--Tests/RunCMake/CMakePresets/ExplicitNoTrace.cmake0
-rw-r--r--Tests/RunCMake/CMakePresets/NoTrace.cmake0
-rw-r--r--Tests/RunCMake/CMakePresets/RunCMakeTest.cmake13
-rw-r--r--Tests/RunCMake/CMakePresets/Trace-stderr.txt4
-rw-r--r--Tests/RunCMake/CMakePresets/Trace.cmake0
-rw-r--r--Tests/RunCMake/CMakePresets/Trace.json.in69
-rw-r--r--Tests/RunCMake/CMakePresets/TraceAll.cmake4
-rw-r--r--Tests/RunCMake/CMakePresets/TraceExpand-stderr.txt4
-rw-r--r--Tests/RunCMake/CMakePresets/TraceExpand.cmake0
-rw-r--r--Tests/RunCMake/CMakePresets/TraceFormatHuman-stderr.txt4
-rw-r--r--Tests/RunCMake/CMakePresets/TraceFormatHuman.cmake0
-rw-r--r--Tests/RunCMake/CMakePresets/TraceFormatJSON-stderr.txt3
-rw-r--r--Tests/RunCMake/CMakePresets/TraceFormatJSON.cmake0
-rw-r--r--Tests/RunCMake/CMakePresets/TraceNotSupported-result.txt1
-rw-r--r--Tests/RunCMake/CMakePresets/TraceNotSupported-stderr.txt3
-rw-r--r--Tests/RunCMake/CMakePresets/TraceNotSupported.json.in13
-rw-r--r--Tests/RunCMake/CMakePresets/TraceRedirect.cmake0
-rw-r--r--Tests/RunCMake/CMakePresets/TraceSource.cmake0
28 files changed, 455 insertions, 46 deletions
diff --git a/Help/manual/cmake-presets.7.rst b/Help/manual/cmake-presets.7.rst
index da699d8..7794e45 100644
--- a/Help/manual/cmake-presets.7.rst
+++ b/Help/manual/cmake-presets.7.rst
@@ -63,6 +63,9 @@ The root object recognizes the following fields:
``6``
.. versionadded:: 3.25
+ ``7``
+ .. versionadded:: 3.27
+
``cmakeMinimumRequired``
An optional object representing the minimum version of CMake needed to
build this project. This object consists of the following fields:
@@ -359,6 +362,52 @@ that may contain the following fields:
An optional boolean. Setting this to ``true`` is equivalent to passing
:option:`--debug-find <cmake --debug-find>` on the command line.
+``trace``
+ An optional object specifying trace options. This is allowed in preset
+ files specifying version ``7``. The object may contain the following fields:
+
+ ``mode``
+ An optional string that specifies the trace mode. Valid values are:
+
+ ``on``
+ Causes a trace of all calls made and from where to be printed.
+ Equivalent to passing :option:`--trace <cmake --trace>` on the command
+ line.
+
+ ``off``
+ A trace of all calls will not be printed.
+
+ ``expand``
+ Causes a trace with variables expanded of all calls made and from where
+ to be printed. Equivalent to passing :option:`--trace-expand <cmake --trace-expand>`
+ on the command line.
+
+ ``format``
+ An optional string that specifies the format output of the trace.
+ Valid values are:
+
+ ``human``
+ Prints each trace line in a human-readable format.
+ This is the default format. Equivalent to passing
+ :option:`--trace-format=human <cmake --trace-format>`
+ on the command line.
+
+ ``json-v1``
+ Prints each line as a separate JSON document. Equivalent to passing
+ :option:`--trace-format=json-v1 <cmake --trace-format>`
+ on the command line.
+
+ ``source``
+ An optional array of strings representing the paths of source files to
+ be traced. This field can also be a string, which is equivalent to an
+ array containing one string. Equivalent to passing
+ :option:`--trace-source <cmake --trace-source>` on the command line.
+
+ ``redirect``
+ An optional string specifying a path to a trace output file. Equivalent
+ to passing :option:`--trace-redirect <cmake --trace-redirect>`
+ on the command line.
+
Build Preset
^^^^^^^^^^^^
diff --git a/Help/manual/presets/schema.json b/Help/manual/presets/schema.json
index 348116b..adfb1cb 100644
--- a/Help/manual/presets/schema.json
+++ b/Help/manual/presets/schema.json
@@ -89,6 +89,23 @@
"include": { "$ref": "#/definitions/include"}
},
"additionalProperties": false
+ },
+ {
+ "properties": {
+ "version": {
+ "const": 7,
+ "description": "A required integer representing the version of the JSON schema."
+ },
+ "cmakeMinimumRequired": { "$ref": "#/definitions/cmakeMinimumRequired"},
+ "vendor": { "$ref": "#/definitions/vendor" },
+ "configurePresets": { "$ref": "#/definitions/configurePresetsV7"},
+ "buildPresets": { "$ref": "#/definitions/buildPresetsV4"},
+ "testPresets": { "$ref": "#/definitions/testPresetsV6"},
+ "packagePresets": { "$ref": "#/definitions/packagePresetsV6"},
+ "workflowPresets": { "$ref": "#/definitions/workflowPresetsV6" },
+ "include": { "$ref": "#/definitions/include"}
+ },
+ "additionalProperties": false
}
],
"required": [
@@ -119,6 +136,59 @@
"description": "An optional map containing vendor-specific information. CMake does not interpret the contents of this field except to verify that it is a map if it does exist. However, the keys should be a vendor-specific domain name followed by a /-separated path. For example, the Example IDE 1.0 could use example.com/ExampleIDE/1.0. The value of each field can be anything desired by the vendor, though will typically be a map.",
"properties": {}
},
+ "configurePresetsItemsV7": {
+ "type": "array",
+ "description": "A configure preset object.",
+ "items": {
+ "type": "object",
+ "description": "A configure preset object.",
+ "properties": {
+ "trace": {
+ "type": "object",
+ "description": "An optional object specifying trace options.",
+ "properties": {
+ "mode": {
+ "type": "string",
+ "description": "An optional string that specifies the trace mode.",
+ "enum": [
+ "on", "off", "expand"
+ ]
+ },
+ "format": {
+ "type": "string",
+ "description": "An optional string that specifies the trace output format.",
+ "enum": [
+ "human", "json-v1"
+ ]
+ },
+ "source": {
+ "anyOf": [
+ {
+ "type": "string",
+ "description": "An optional string representing the path to one source file to be traced.",
+ "minLength": 1
+ },
+ {
+ "type": "array",
+ "description": "An optional array of strings representing the paths to source files to be traced.",
+ "items": {
+ "type": "string",
+ "description": "A string representing the path to one source file to be traced.",
+ "minLength": 1
+ }
+ }
+ ]
+ },
+ "redirect": {
+ "type": "string",
+ "description": "An optional string specifying a path to a trace output file."
+ }
+ },
+ "additionalProperties": false
+ }
+ }
+ }
+ },
"configurePresetsItemsV3": {
"type": "array",
"description": "A configure preset object.",
@@ -393,6 +463,43 @@
}
}
},
+ "configurePresetsV7": {
+ "type": "array",
+ "description": "An optional array of configure preset objects.",
+ "allOf": [
+ { "$ref": "#/definitions/configurePresetsItemsV1" },
+ { "$ref": "#/definitions/configurePresetsItemsV3" },
+ { "$ref": "#/definitions/configurePresetsItemsV7" }
+ ],
+ "items": {
+ "properties": {
+ "name": {},
+ "hidden": {},
+ "inherits": {},
+ "vendor": {},
+ "displayName": {},
+ "description": {},
+ "generator": {},
+ "architecture": {},
+ "toolset": {},
+ "toolchainFile": {},
+ "binaryDir": {},
+ "installDir": {},
+ "cmakeExecutable": {},
+ "cacheVariables": {},
+ "environment": {},
+ "warnings": {},
+ "errors": {},
+ "debug": {},
+ "condition": {},
+ "trace": {}
+ },
+ "required": [
+ "name"
+ ],
+ "additionalProperties": false
+ }
+ },
"configurePresetsV3": {
"type": "array",
"description": "An optional array of configure preset objects.",
diff --git a/Source/cmCMakePresetErrors.h b/Source/cmCMakePresetErrors.h
index c669cb1..0db391e 100644
--- a/Source/cmCMakePresetErrors.h
+++ b/Source/cmCMakePresetErrors.h
@@ -176,6 +176,9 @@ const auto CTEST_JUNIT_UNSUPPORTED = [](cmJSONState* state) -> void {
state->AddError(
"File version must be 6 or higher for CTest JUnit output support");
};
+const auto TRACE_UNSUPPORTED = [](cmJSONState* state) -> void {
+ state->AddError("File version must be 7 or higher for trace preset support");
+};
const auto UNRECOGNIZED_CMAKE_VERSION = [](const std::string& version,
int current, int required) {
return [version, current, required](const Json::Value* value,
diff --git a/Source/cmCMakePresetsGraph.h b/Source/cmCMakePresetsGraph.h
index 9d7e5fa..7844624 100644
--- a/Source/cmCMakePresetsGraph.h
+++ b/Source/cmCMakePresetsGraph.h
@@ -15,6 +15,7 @@
#include <cm/optional>
#include "cmJSONState.h"
+#include "cmStateTypes.h"
#include "CTest/cmCTestTypes.h"
@@ -32,6 +33,13 @@ public:
External,
};
+ enum class TraceEnableMode
+ {
+ Disable,
+ Default,
+ Expand,
+ };
+
class CacheVariable
{
public:
@@ -129,6 +137,11 @@ public:
cm::optional<bool> DebugTryCompile;
cm::optional<bool> DebugFind;
+ cm::optional<TraceEnableMode> TraceMode;
+ cm::optional<cmTraceEnums::TraceOutputFormat> TraceFormat;
+ std::vector<std::string> TraceSource;
+ std::string TraceRedirect;
+
bool VisitPresetInherit(const Preset& parent) override;
bool VisitPresetBeforeInherit() override;
bool VisitPresetAfterInherit(int version, cmJSONState* state) override;
diff --git a/Source/cmCMakePresetsGraphReadJSON.cxx b/Source/cmCMakePresetsGraphReadJSON.cxx
index 93c5f7d..bc829f3 100644
--- a/Source/cmCMakePresetsGraphReadJSON.cxx
+++ b/Source/cmCMakePresetsGraphReadJSON.cxx
@@ -35,7 +35,7 @@ using ArchToolsetStrategy = cmCMakePresetsGraph::ArchToolsetStrategy;
using JSONHelperBuilder = cmJSONHelperBuilder;
constexpr int MIN_VERSION = 1;
-constexpr int MAX_VERSION = 6;
+constexpr int MAX_VERSION = 7;
struct CMakeVersion
{
@@ -557,6 +557,14 @@ bool cmCMakePresetsGraph::ReadJSONFile(const std::string& filename,
return false;
}
+ // Support for trace presets added in version 7.
+ if (v < 7 &&
+ (preset.TraceMode.has_value() || preset.TraceFormat.has_value() ||
+ !preset.TraceRedirect.empty() || !preset.TraceSource.empty())) {
+ cmCMakePresetErrors::TRACE_UNSUPPORTED(&this->parseState);
+ return false;
+ }
+
this->ConfigurePresetOrder.push_back(preset.Name);
}
diff --git a/Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx b/Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx
index a1774be..66ec6a4 100644
--- a/Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx
+++ b/Source/cmCMakePresetsGraphReadJSONConfigurePresets.cxx
@@ -17,12 +17,15 @@
#include "cmCMakePresetsGraphInternal.h"
#include "cmJSONHelpers.h"
#include "cmJSONState.h"
+#include "cmStateTypes.h"
namespace {
using CacheVariable = cmCMakePresetsGraph::CacheVariable;
using ConfigurePreset = cmCMakePresetsGraph::ConfigurePreset;
using ArchToolsetStrategy = cmCMakePresetsGraph::ArchToolsetStrategy;
using JSONHelperBuilder = cmJSONHelperBuilder;
+using TraceEnableMode = cmCMakePresetsGraph::TraceEnableMode;
+using TraceOutputFormat = cmTraceEnums::TraceOutputFormat;
bool ArchToolsetStrategyHelper(cm::optional<ArchToolsetStrategy>& out,
const Json::Value* value, cmJSONState* state)
@@ -91,6 +94,58 @@ auto const ArchitectureHelper = ArchToolsetHelper(
auto const ToolsetHelper = ArchToolsetHelper(
&ConfigurePreset::Toolset, &ConfigurePreset::ToolsetStrategy);
+bool TraceEnableModeHelper(cm::optional<TraceEnableMode>& out,
+ const Json::Value* value, cmJSONState* state)
+{
+ if (!value) {
+ out = cm::nullopt;
+ return true;
+ }
+
+ if (!value->isString()) {
+ cmCMakePresetErrors::INVALID_PRESET(value, state);
+ return false;
+ }
+
+ if (value->asString() == "on") {
+ out = TraceEnableMode::Default;
+ } else if (value->asString() == "off") {
+ out = TraceEnableMode::Disable;
+ } else if (value->asString() == "expand") {
+ out = TraceEnableMode::Expand;
+ } else {
+ cmCMakePresetErrors::INVALID_PRESET(value, state);
+ return false;
+ }
+
+ return true;
+}
+
+bool TraceOutputFormatHelper(cm::optional<TraceOutputFormat>& out,
+ const Json::Value* value, cmJSONState* state)
+{
+ if (!value) {
+ out = cm::nullopt;
+ return true;
+ }
+
+ if (!value->isString()) {
+ cmCMakePresetErrors::INVALID_PRESET(value, state);
+ return false;
+ }
+
+ if (value->asString() == "human") {
+ out = TraceOutputFormat::Human;
+ } else if (value->asString() == "json-v1") {
+ out = TraceOutputFormat::JSONv1;
+ } else {
+ cmCMakePresetErrors::INVALID_PRESET(value, state);
+ return false;
+ }
+
+ return true;
+}
+
auto const VariableStringHelper = JSONHelperBuilder::String();
bool VariableValueHelper(std::string& out, const Json::Value* value,
@@ -180,6 +235,18 @@ auto const PresetDebugHelper =
.Bind("find"_s, &ConfigurePreset::DebugFind,
cmCMakePresetsGraphInternal::PresetOptionalBoolHelper, false);
+auto const PresetTraceHelper =
+ JSONHelperBuilder::Object<ConfigurePreset>(
+ cmCMakePresetErrors::INVALID_PRESET_OBJECT, false)
+ .Bind("mode"_s, &ConfigurePreset::TraceMode, TraceEnableModeHelper, false)
+ .Bind("format"_s, &ConfigurePreset::TraceFormat, TraceOutputFormatHelper,
+ false)
+ .Bind("source"_s, &ConfigurePreset::TraceSource,
+ cmCMakePresetsGraphInternal::PresetVectorOneOrMoreStringHelper,
+ false)
+ .Bind("redirect"_s, &ConfigurePreset::TraceRedirect,
+ cmCMakePresetsGraphInternal::PresetStringHelper, false);
+
auto const ConfigurePresetHelper =
JSONHelperBuilder::Object<ConfigurePreset>(
cmCMakePresetErrors::INVALID_PRESET_OBJECT, false)
@@ -217,6 +284,7 @@ auto const ConfigurePresetHelper =
.Bind("warnings"_s, PresetWarningsHelper, false)
.Bind("errors"_s, PresetErrorsHelper, false)
.Bind("debug"_s, PresetDebugHelper, false)
+ .Bind("trace"_s, PresetTraceHelper, false)
.Bind("condition"_s, &ConfigurePreset::ConditionEvaluator,
cmCMakePresetsGraphInternal::PresetConditionHelper, false);
}
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index fc82c14..3a69b2e 100644
--- a/Source/cmMakefile.cxx
+++ b/Source/cmMakefile.cxx
@@ -340,7 +340,7 @@ void cmMakefile::PrintCommandTrace(cmListFileFunction const& lff,
cm::optional<std::string> const& deferId = bt.Top().DeferId;
switch (this->GetCMakeInstance()->GetTraceFormat()) {
- case cmake::TraceFormat::TRACE_JSON_V1: {
+ case cmake::TraceFormat::JSONv1: {
#ifndef CMAKE_BOOTSTRAP
Json::Value val;
Json::StreamWriterBuilder builder;
@@ -367,7 +367,7 @@ void cmMakefile::PrintCommandTrace(cmListFileFunction const& lff,
#endif
break;
}
- case cmake::TraceFormat::TRACE_HUMAN:
+ case cmake::TraceFormat::Human:
msg << full_path << "(" << lff.Line() << "):";
if (deferId) {
msg << "DEFERRED:" << *deferId << ":";
@@ -379,8 +379,8 @@ void cmMakefile::PrintCommandTrace(cmListFileFunction const& lff,
}
msg << ")";
break;
- case cmake::TraceFormat::TRACE_UNDEFINED:
- msg << "INTERNAL ERROR: Trace format is TRACE_UNDEFINED";
+ case cmake::TraceFormat::Undefined:
+ msg << "INTERNAL ERROR: Trace format is Undefined";
break;
}
diff --git a/Source/cmStateTypes.h b/Source/cmStateTypes.h
index 010d7e3..24b809b 100644
--- a/Source/cmStateTypes.h
+++ b/Source/cmStateTypes.h
@@ -60,3 +60,14 @@ enum ArtifactType
ImportLibraryArtifact
};
}
+
+namespace cmTraceEnums {
+
+/** \brief Define supported trace formats **/
+enum class TraceOutputFormat
+{
+ Undefined,
+ Human,
+ JSONv1
+};
+};
diff --git a/Source/cmake.cxx b/Source/cmake.cxx
index f943415..8dee5cc 100644
--- a/Source/cmake.cxx
+++ b/Source/cmake.cxx
@@ -1143,49 +1143,64 @@ void cmake::SetArgs(const std::vector<std::string>& args)
std::cout << ".\n";
return true;
} },
- CommandArgument{ "--trace-expand", CommandArgument::Values::Zero,
+ CommandArgument{ "--trace", CommandArgument::Values::Zero,
[](std::string const&, cmake* state) -> bool {
- std::cout << "Running with expanded trace output on.\n";
+ std::cout << "Put cmake in trace mode.\n";
state->SetTrace(true);
- state->SetTraceExpand(true);
+ state->SetTraceExpand(false);
return true;
} },
- CommandArgument{ "--trace-format", CommandArgument::Values::One,
- [](std::string const& value, cmake* state) -> bool {
+ CommandArgument{ "--trace-expand", CommandArgument::Values::Zero,
+ [](std::string const&, cmake* state) -> bool {
+ std::cout << "Put cmake in trace mode, but with "
+ "variables expanded.\n";
state->SetTrace(true);
- const auto traceFormat = StringToTraceFormat(value);
- if (traceFormat == TraceFormat::TRACE_UNDEFINED) {
- cmSystemTools::Error(
- "Invalid format specified for --trace-format. "
- "Valid formats are human, json-v1.");
- return false;
- }
- state->SetTraceFormat(traceFormat);
+ state->SetTraceExpand(true);
return true;
} },
- CommandArgument{ "--trace-source", CommandArgument::Values::One,
- [](std::string const& value, cmake* state) -> bool {
- std::string file(value);
- cmSystemTools::ConvertToUnixSlashes(file);
- state->AddTraceSource(file);
+ CommandArgument{
+ "--trace-format", "Invalid format specified for --trace-format",
+ CommandArgument::Values::One,
+ [](std::string const& value, cmake* state) -> bool {
+ std::cout << "Put cmake in trace mode and sets the "
+ "trace output format.\n";
+ state->SetTrace(true);
+ const auto traceFormat = StringToTraceFormat(value);
+ if (traceFormat == TraceFormat::Undefined) {
+ cmSystemTools::Error("Invalid format specified for --trace-format. "
+ "Valid formats are human, json-v1.");
+ return false;
+ }
+ state->SetTraceFormat(traceFormat);
+ return true;
+ } },
+ CommandArgument{ "--trace-source", "No file specified for --trace-source",
+ CommandArgument::Values::OneOrMore,
+ [](std::string const& values, cmake* state) -> bool {
+ std::cout << "Put cmake in trace mode, but output only "
+ "lines of a specified file. Multiple "
+ "options are allowed.\n";
+ for (auto file :
+ cmSystemTools::SplitString(values, ';')) {
+ cmSystemTools::ConvertToUnixSlashes(file);
+ state->AddTraceSource(file);
+ }
state->SetTrace(true);
return true;
} },
- CommandArgument{ "--trace-redirect", CommandArgument::Values::One,
+ CommandArgument{ "--trace-redirect",
+ "No file specified for --trace-redirect",
+ CommandArgument::Values::One,
[](std::string const& value, cmake* state) -> bool {
+ std::cout
+ << "Put cmake in trace mode and redirect trace "
+ "output to a file instead of stderr.\n";
std::string file(value);
cmSystemTools::ConvertToUnixSlashes(file);
state->SetTraceFile(file);
state->SetTrace(true);
return true;
} },
- CommandArgument{ "--trace", CommandArgument::Values::Zero,
- [](std::string const&, cmake* state) -> bool {
- std::cout << "Running with trace output on.\n";
- state->SetTrace(true);
- state->SetTraceExpand(false);
- return true;
- } },
CommandArgument{ "--warn-uninitialized", CommandArgument::Values::Zero,
[](std::string const&, cmake* state) -> bool {
std::cout << "Warn about uninitialized values.\n";
@@ -1530,6 +1545,29 @@ void cmake::SetArgs(const std::vector<std::string>& args)
if (expandedPreset->DebugFind == true) {
this->SetDebugFindOutput(true);
}
+ if (expandedPreset->TraceMode &&
+ expandedPreset->TraceMode !=
+ cmCMakePresetsGraph::TraceEnableMode::Disable) {
+ this->SetTrace(true);
+ if (expandedPreset->TraceMode ==
+ cmCMakePresetsGraph::TraceEnableMode::Expand) {
+ this->SetTraceExpand(true);
+ }
+ }
+ if (expandedPreset->TraceFormat) {
+ this->SetTrace(true);
+ this->SetTraceFormat(*expandedPreset->TraceFormat);
+ }
+ if (!expandedPreset->TraceSource.empty()) {
+ this->SetTrace(true);
+ for (std::string const& filePaths : expandedPreset->TraceSource) {
+ this->AddTraceSource(filePaths);
+ }
+ }
+ if (!expandedPreset->TraceRedirect.empty()) {
+ this->SetTrace(true);
+ this->SetTraceFile(expandedPreset->TraceRedirect);
+ }
}
#endif
}
@@ -1586,8 +1624,8 @@ cmake::TraceFormat cmake::StringToTraceFormat(const std::string& traceStr)
{
using TracePair = std::pair<std::string, TraceFormat>;
static const std::vector<TracePair> levels = {
- { "human", TraceFormat::TRACE_HUMAN },
- { "json-v1", TraceFormat::TRACE_JSON_V1 },
+ { "human", TraceFormat::Human },
+ { "json-v1", TraceFormat::JSONv1 },
};
const auto traceStrLowCase = cmSystemTools::LowerCase(traceStr);
@@ -1596,7 +1634,7 @@ cmake::TraceFormat cmake::StringToTraceFormat(const std::string& traceStr)
[&traceStrLowCase](const TracePair& p) {
return p.first == traceStrLowCase;
});
- return (it != levels.cend()) ? it->second : TraceFormat::TRACE_UNDEFINED;
+ return (it != levels.cend()) ? it->second : TraceFormat::Undefined;
}
void cmake::SetTraceFile(const std::string& file)
@@ -1622,7 +1660,7 @@ void cmake::PrintTraceFormatVersion()
std::string msg;
switch (this->GetTraceFormat()) {
- case TraceFormat::TRACE_JSON_V1: {
+ case TraceFormat::JSONv1: {
#ifndef CMAKE_BOOTSTRAP
Json::Value val;
Json::Value version;
@@ -1635,11 +1673,11 @@ void cmake::PrintTraceFormatVersion()
#endif
break;
}
- case TraceFormat::TRACE_HUMAN:
+ case TraceFormat::Human:
msg = "";
break;
- case TraceFormat::TRACE_UNDEFINED:
- msg = "INTERNAL ERROR: Trace format is TRACE_UNDEFINED";
+ case TraceFormat::Undefined:
+ msg = "INTERNAL ERROR: Trace format is Undefined";
break;
}
diff --git a/Source/cmake.h b/Source/cmake.h
index d1f388a..0f8f642 100644
--- a/Source/cmake.h
+++ b/Source/cmake.h
@@ -118,13 +118,7 @@ public:
FIND_PACKAGE_MODE
};
- /** \brief Define supported trace formats **/
- enum TraceFormat
- {
- TRACE_UNDEFINED,
- TRACE_HUMAN,
- TRACE_JSON_V1,
- };
+ using TraceFormat = cmTraceEnums::TraceOutputFormat;
struct GeneratorInfo
{
@@ -719,7 +713,7 @@ private:
bool DebugFindOutput = false;
bool Trace = false;
bool TraceExpand = false;
- TraceFormat TraceFormatVar = TRACE_HUMAN;
+ TraceFormat TraceFormatVar = TraceFormat::Human;
cmGeneratedFileStream TraceFile;
cmake* TraceRedirect = nullptr;
#ifndef CMAKE_BOOTSTRAP
diff --git a/Tests/RunCMake/CMakePresets/ExplicitNoTrace.cmake b/Tests/RunCMake/CMakePresets/ExplicitNoTrace.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/ExplicitNoTrace.cmake
diff --git a/Tests/RunCMake/CMakePresets/NoTrace.cmake b/Tests/RunCMake/CMakePresets/NoTrace.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/NoTrace.cmake
diff --git a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
index efa838e..d67e8b1 100644
--- a/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
+++ b/Tests/RunCMake/CMakePresets/RunCMakeTest.cmake
@@ -150,6 +150,7 @@ run_cmake_presets(InvalidRegex)
set(CMakePresets_SCHEMA_EXPECTED_RESULT 1)
run_cmake_presets(ConditionFuture)
run_cmake_presets(SubConditionNull)
+run_cmake_presets(TraceNotSupported)
# Test cmakeMinimumRequired field
run_cmake_presets(MinimumRequiredInvalid)
@@ -326,6 +327,18 @@ set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/Debug.json.in")
run_cmake_presets(NoDebug)
run_cmake_presets(Debug)
+# Test trace
+set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/Trace.json.in")
+run_cmake_presets(NoTrace)
+run_cmake_presets(ExplicitNoTrace)
+run_cmake_presets(Trace)
+run_cmake_presets(TraceExpand)
+run_cmake_presets(TraceFormatJSON)
+run_cmake_presets(TraceFormatHuman)
+run_cmake_presets(TraceSource)
+run_cmake_presets(TraceRedirect)
+run_cmake_presets(TraceAll)
+
# Test ${hostSystemName} macro
set(CMakePresets_FILE "${RunCMake_SOURCE_DIR}/HostSystemName.json.in")
run_cmake_presets(HostSystemName)
diff --git a/Tests/RunCMake/CMakePresets/Trace-stderr.txt b/Tests/RunCMake/CMakePresets/Trace-stderr.txt
new file mode 100644
index 0000000..5ed769c
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/Trace-stderr.txt
@@ -0,0 +1,4 @@
+^[^
+]*/Tests/RunCMake/CMakePresets/Trace/CMakeLists.txt\(1\): cmake_minimum_required\(VERSION 3.18 \)
+[^
+]*/Tests/RunCMake/CMakePresets/Trace/CMakeLists.txt\(2\): project\(\${RunCMake_TEST} NONE \)
diff --git a/Tests/RunCMake/CMakePresets/Trace.cmake b/Tests/RunCMake/CMakePresets/Trace.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/Trace.cmake
diff --git a/Tests/RunCMake/CMakePresets/Trace.json.in b/Tests/RunCMake/CMakePresets/Trace.json.in
new file mode 100644
index 0000000..f50a6f2
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/Trace.json.in
@@ -0,0 +1,69 @@
+{
+ "version": 7,
+ "configurePresets": [
+ {
+ "name": "NoTrace",
+ "generator": "@RunCMake_GENERATOR@",
+ "binaryDir": "${sourceDir}/build"
+ },
+ {
+ "name": "ExplicitNoTrace",
+ "inherits": "NoTrace",
+ "trace": {
+ "mode": "off"
+ }
+ },
+ {
+ "name": "Trace",
+ "inherits": "NoTrace",
+ "trace": {
+ "mode": "on"
+ }
+ },
+ {
+ "name": "TraceExpand",
+ "inherits": "NoTrace",
+ "trace": {
+ "mode": "expand"
+ }
+ },
+ {
+ "name": "TraceFormatJSON",
+ "inherits": "NoTrace",
+ "trace": {
+ "format": "json-v1"
+ }
+ },
+ {
+ "name": "TraceFormatHuman",
+ "inherits": "NoTrace",
+ "trace": {
+ "format": "human"
+ }
+ },
+ {
+ "name": "TraceSource",
+ "inherits": "NoTrace",
+ "trace": {
+ "source": "TraceSourceFile.txt"
+ }
+ },
+ {
+ "name": "TraceRedirect",
+ "inherits": "NoTrace",
+ "trace": {
+ "redirect": "TraceRedirectFile.txt"
+ }
+ },
+ {
+ "name": "TraceAll",
+ "inherits": "NoTrace",
+ "trace": {
+ "mode": "expand",
+ "format": "json-v1",
+ "source": "TraceSourceFile.txt",
+ "redirect": "TraceRedirectFile.json"
+ }
+ }
+ ]
+}
diff --git a/Tests/RunCMake/CMakePresets/TraceAll.cmake b/Tests/RunCMake/CMakePresets/TraceAll.cmake
new file mode 100644
index 0000000..9896ec0
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceAll.cmake
@@ -0,0 +1,4 @@
+include(${CMAKE_CURRENT_LIST_DIR}/TraceExpand.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/TraceFormatJSON.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/TraceSource.cmake)
+include(${CMAKE_CURRENT_LIST_DIR}/TraceRedirect.cmake)
diff --git a/Tests/RunCMake/CMakePresets/TraceExpand-stderr.txt b/Tests/RunCMake/CMakePresets/TraceExpand-stderr.txt
new file mode 100644
index 0000000..7ee4fea
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceExpand-stderr.txt
@@ -0,0 +1,4 @@
+^[^
+]*/Tests/RunCMake/CMakePresets/TraceExpand/CMakeLists.txt\(1\): cmake_minimum_required\(VERSION 3.18 \)
+[^
+]*/Tests/RunCMake/CMakePresets/TraceExpand/CMakeLists.txt\(2\): project\(TraceExpand NONE \)
diff --git a/Tests/RunCMake/CMakePresets/TraceExpand.cmake b/Tests/RunCMake/CMakePresets/TraceExpand.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceExpand.cmake
diff --git a/Tests/RunCMake/CMakePresets/TraceFormatHuman-stderr.txt b/Tests/RunCMake/CMakePresets/TraceFormatHuman-stderr.txt
new file mode 100644
index 0000000..1d3450d
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceFormatHuman-stderr.txt
@@ -0,0 +1,4 @@
+^[^
+]*/Tests/RunCMake/CMakePresets/TraceFormatHuman/CMakeLists.txt\(1\): cmake_minimum_required\(VERSION 3.18 \)
+[^
+]*/Tests/RunCMake/CMakePresets/TraceFormatHuman/CMakeLists.txt\(2\): project\(\${RunCMake_TEST} NONE \)
diff --git a/Tests/RunCMake/CMakePresets/TraceFormatHuman.cmake b/Tests/RunCMake/CMakePresets/TraceFormatHuman.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceFormatHuman.cmake
diff --git a/Tests/RunCMake/CMakePresets/TraceFormatJSON-stderr.txt b/Tests/RunCMake/CMakePresets/TraceFormatJSON-stderr.txt
new file mode 100644
index 0000000..edf044c
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceFormatJSON-stderr.txt
@@ -0,0 +1,3 @@
+^{"version":{"major":1,"minor":2}}
+{"args":\["VERSION","3\.18"\],"cmd":"cmake_minimum_required","file":"[^"]*/Tests/RunCMake/CMakePresets/TraceFormatJSON/CMakeLists\.txt","frame":1,"global_frame":1,"line":1,"time":[0-9.]+}
+{"args":\["\${RunCMake_TEST}","NONE"\],"cmd":"project","file":"[^"]*/Tests/RunCMake/CMakePresets/TraceFormatJSON/CMakeLists\.txt","frame":1,"global_frame":1,"line":2,"time":[0-9.]+}
diff --git a/Tests/RunCMake/CMakePresets/TraceFormatJSON.cmake b/Tests/RunCMake/CMakePresets/TraceFormatJSON.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceFormatJSON.cmake
diff --git a/Tests/RunCMake/CMakePresets/TraceNotSupported-result.txt b/Tests/RunCMake/CMakePresets/TraceNotSupported-result.txt
new file mode 100644
index 0000000..d00491f
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceNotSupported-result.txt
@@ -0,0 +1 @@
+1
diff --git a/Tests/RunCMake/CMakePresets/TraceNotSupported-stderr.txt b/Tests/RunCMake/CMakePresets/TraceNotSupported-stderr.txt
new file mode 100644
index 0000000..de19a8c
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceNotSupported-stderr.txt
@@ -0,0 +1,3 @@
+^CMake Error: Could not read presets from [^
+]*/Tests/RunCMake/CMakePresets/TraceNotSupported:
+File version must be 7 or higher for trace preset support$
diff --git a/Tests/RunCMake/CMakePresets/TraceNotSupported.json.in b/Tests/RunCMake/CMakePresets/TraceNotSupported.json.in
new file mode 100644
index 0000000..f3d3fbd
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceNotSupported.json.in
@@ -0,0 +1,13 @@
+{
+ "version": 6,
+ "configurePresets": [
+ {
+ "name": "TraceNotSupported",
+ "generator": "@RunCMake_GENERATOR@",
+ "binaryDir": "${sourceDir}/build",
+ "trace": {
+ "mode": "expand"
+ }
+ }
+ ]
+}
diff --git a/Tests/RunCMake/CMakePresets/TraceRedirect.cmake b/Tests/RunCMake/CMakePresets/TraceRedirect.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceRedirect.cmake
diff --git a/Tests/RunCMake/CMakePresets/TraceSource.cmake b/Tests/RunCMake/CMakePresets/TraceSource.cmake
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/Tests/RunCMake/CMakePresets/TraceSource.cmake