cmake: Infer command set from role

This commit is contained in:
Brad King
2025-10-20 17:10:12 -04:00
parent bfaaec6179
commit e290d4f2a3
19 changed files with 34 additions and 48 deletions
+1 -1
View File
@@ -760,7 +760,7 @@ int cmCPackGenerator::InstallCMakeProject(
"- Install component: " << component << std::endl);
}
cmake cm(cmake::CommandSet::Script, cmState::Role::CPack);
cmake cm(cmState::Role::CPack);
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cm.AddCMakePaths();
cm.SetProgressCallback([this](std::string const& msg, float prog) {
+1 -1
View File
@@ -225,7 +225,7 @@ int main(int argc, char const* const* argv)
} },
};
cmake cminst(cmake::CommandSet::Script, cmState::Role::CPack);
cmake cminst(cmState::Role::CPack);
cminst.SetProgressCallback(cpackProgressCallback);
cminst.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator cmgg(&cminst);
+1 -1
View File
@@ -177,7 +177,7 @@ int cmCTestBuildAndTest::Run()
return 1;
}
cmake cm(cmake::CommandSet::Project, cmState::Role::Project);
cmake cm(cmState::Role::Project);
cmCTestBuildAndTestCaptureRAII captureRAII(cm);
static_cast<void>(captureRAII);
+1 -1
View File
@@ -405,7 +405,7 @@ int cmCTestLaunch::Main(int argc, char const* const argv[], Op operation)
void cmCTestLaunch::LoadConfig()
{
cmake cm(cmake::CommandSet::Script, cmState::Role::CTest);
cmake cm(cmState::Role::CTest);
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm);
cmMakefile mf(&gg, cm.GetCurrentSnapshot());
+1 -2
View File
@@ -172,8 +172,7 @@ int cmCTestScriptHandler::ExecuteScript(std::string const& total_script_arg)
void cmCTestScriptHandler::CreateCMake()
{
// create a cmake instance to read the configuration script
this->CMake =
cm::make_unique<cmake>(cmake::CommandSet::Script, cmState::Role::CTest);
this->CMake = cm::make_unique<cmake>(cmState::Role::CTest);
this->CMake->GetCurrentSnapshot().SetDefaultDefinitions();
this->CMake->AddCMakePaths();
this->CMake->SetWorkingMode(cmake::SCRIPT_MODE,
+1 -1
View File
@@ -1754,7 +1754,7 @@ bool cmCTestTestHandler::GetListOfTests()
}
cmCTestOptionalLog(this->CTest, HANDLER_VERBOSE_OUTPUT,
"Constructing a list of tests" << std::endl, this->Quiet);
cmake cm(cmake::CommandSet::Script, cmState::Role::CTest);
cmake cm(cmState::Role::CTest);
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm);
cmMakefile mf(&gg, cm.GetCurrentSnapshot());
+1 -1
View File
@@ -75,7 +75,7 @@ int main(int argc, char const* const* argv)
cmDocumentation doc;
doc.addCMakeStandardDocSections();
if (doc.CheckOptions(argc, argv)) {
cmake hcm(cmake::CommandSet::None, cmState::Role::Help);
cmake hcm(cmState::Role::Help);
hcm.AddCMakePaths();
auto generators = hcm.GetGeneratorsDocumentation();
doc.SetName("ccmake");
+1 -2
View File
@@ -39,8 +39,7 @@ cmCursesMainForm::cmCursesMainForm(std::vector<std::string> args,
"Welcome to ccmake, curses based user interface for CMake.");
this->HelpMessage.emplace_back();
this->HelpMessage.emplace_back(s_ConstHelpMessage);
this->CMakeInstance =
cm::make_unique<cmake>(cmake::CommandSet::Project, cmState::Role::Project);
this->CMakeInstance = cm::make_unique<cmake>(cmState::Role::Project);
this->CMakeInstance->SetCMakeEditCommand(
cmSystemTools::GetCMakeCursesCommand());
+1 -1
View File
@@ -82,7 +82,7 @@ int main(int argc, char** argv)
doc.addCMakeStandardDocSections();
if (argc2 > 1 && doc.CheckOptions(argc2, argv2)) {
// Construct and print requested documentation.
cmake hcm(cmake::CommandSet::None, cmState::Role::Help);
cmake hcm(cmState::Role::Help);
hcm.AddCMakePaths();
auto generators = hcm.GetGeneratorsDocumentation();
+1 -2
View File
@@ -46,8 +46,7 @@ QCMake::QCMake(QObject* p)
cmSystemTools::SetStderrCallback(
[this](std::string const& msg) { this->stderrCallback(msg); });
this->CMakeInstance =
cm::make_unique<cmake>(cmake::CommandSet::Project, cmState::Role::Project);
this->CMakeInstance = cm::make_unique<cmake>(cmState::Role::Project);
this->CMakeInstance->SetCMakeEditCommand(
cmSystemTools::GetCMakeGUICommand());
this->CMakeInstance->SetProgressCallback(
+1 -1
View File
@@ -2656,7 +2656,7 @@ int cmCTest::ExecuteTests(std::vector<std::string> const& args)
cmCTestTestHandler handler(this);
{
cmake cm(cmake::CommandSet::Script, cmState::Role::CTest);
cmake cm(cmState::Role::CTest);
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm);
cmMakefile mf(&gg, cm.GetCurrentSnapshot());
+1 -1
View File
@@ -3049,7 +3049,7 @@ int cmcmd_cmake_ninja_dyndep(std::vector<std::string>::const_iterator argBeg,
auto export_info = cmDyndepCollation::ParseExportInfo(tdi);
cmake cm(cmake::CommandSet::None, cmState::Role::Internal);
cmake cm(cmState::Role::Internal);
cm.SetHomeDirectory(dir_top_src);
cm.SetHomeOutputDirectory(dir_top_bld);
auto ggd = cm.CreateGlobalGenerator("Ninja");
+1 -1
View File
@@ -195,7 +195,7 @@ void cmGraphVizWriter::ReadSettings(
std::string const& settingsFileName,
std::string const& fallbackSettingsFileName)
{
cmake cm(cmake::CommandSet::Script, cmState::Role::Script);
cmake cm(cmState::Role::Script);
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator ggi(&cm);
cmMakefile mf(&ggi, cm.GetCurrentSnapshot());
+1 -2
View File
@@ -3251,8 +3251,7 @@ int cmMakefile::TryCompile(std::string const& srcdir,
// make sure the same generator is used
// use this program as the cmake to be run, it should not
// be run that way but the cmake object requires a valid path
cmake cm(cmake::CommandSet::Project, cmState::Role::Project,
cmState::TryCompile::Yes);
cmake cm(cmState::Role::Project, cmState::TryCompile::Yes);
auto gg = cm.CreateGlobalGenerator(this->GetGlobalGenerator()->GetName());
if (!gg) {
this->IssueMessage(MessageType::INTERNAL_ERROR,
+6 -5
View File
@@ -297,8 +297,7 @@ cmDocumentationEntry cmake::CMAKE_STANDARD_OPTIONS_TABLE[19] = {
"not errors." }
};
cmake::cmake(CommandSet commandSet, cmState::Role role,
cmState::TryCompile isTryCompile)
cmake::cmake(cmState::Role role, cmState::TryCompile isTryCompile)
: CMakeWorkingDirectory(cmSystemTools::GetLogicalWorkingDirectory())
, FileTimeCache(cm::make_unique<cmFileTimeCache>())
#ifndef CMAKE_BOOTSTRAP
@@ -322,10 +321,12 @@ cmake::cmake(CommandSet commandSet, cmState::Role role,
this->AddDefaultGenerators();
this->AddDefaultExtraGenerators();
if (commandSet == CommandSet::Script || commandSet == CommandSet::Project) {
if (role == cmState::Role::Project || role == cmState::Role::FindPackage ||
role == cmState::Role::Script || role == cmState::Role::CTest ||
role == cmState::Role::CPack) {
this->AddScriptingCommands();
}
if (commandSet == CommandSet::Project) {
if (role == cmState::Role::Project || role == cmState::Role::FindPackage) {
this->AddProjectCommands();
}
@@ -3477,7 +3478,7 @@ int cmake::CheckBuildSystem()
// Read the rerun check file and use it to decide whether to do the
// global generate.
// Actually, all we need is the `set` command.
cmake cm(CommandSet::Script, cmState::Role::Script);
cmake cm(cmState::Role::Script);
cm.GetCurrentSnapshot().SetDefaultDefinitions();
cmGlobalGenerator gg(&cm);
cmMakefile mf(&gg, cm.GetCurrentSnapshot());
+1 -8
View File
@@ -86,13 +86,6 @@ struct cmGlobCacheEntry;
class cmake
{
public:
enum class CommandSet
{
None, // no commands
Script, // script commands
Project, // all commands
};
enum DiagLevel
{
DIAG_IGNORE,
@@ -171,7 +164,7 @@ public:
static int const DEFAULT_BUILD_PARALLEL_LEVEL = 0;
/// Default constructor
cmake(CommandSet commandSet, cmState::Role role,
cmake(cmState::Role role,
cmState::TryCompile isTryCompile = cmState::TryCompile::No);
/// Destructor
~cmake();
+7 -10
View File
@@ -221,7 +221,7 @@ int do_cmake(int ac, char const* const* av)
doc.addCMakeStandardDocSections();
if (doc.CheckOptions(ac, av, "--")) {
// Construct and print requested documentation.
cmake hcm(cmake::CommandSet::None, cmState::Role::Help);
cmake hcm(cmState::Role::Help);
hcm.AddCMakePaths();
// the command line args are processed here so that you can do
@@ -359,13 +359,10 @@ int do_cmake(int ac, char const* const* av)
}
if (sysinfo) {
cmake cm(cmake::CommandSet::Project, cmState::Role::Project);
cmake cm(cmState::Role::Project);
int ret = cm.GetSystemInformation(parsedArgs);
return ret;
}
cmake::CommandSet const commandSet = workingMode == cmake::SCRIPT_MODE
? cmake::CommandSet::Script
: cmake::CommandSet::Project;
cmState::Role role = cmState::Role::Internal;
switch (workingMode) {
case cmake::NORMAL_MODE:
@@ -382,7 +379,7 @@ int do_cmake(int ac, char const* const* av)
auto const failurePolicy = workingMode == cmake::NORMAL_MODE
? cmake::CommandFailureAction::EXIT_CODE
: cmake::CommandFailureAction::FATAL_ERROR;
cmake cm(commandSet, role);
cmake cm(role);
cmSystemTools::SetMessageCallback(
[&cm](std::string const& msg, cmMessageMetadata const& md) {
cmakemainMessageCallback(msg, md, &cm);
@@ -680,7 +677,7 @@ int do_build(int ac, char const* const* av)
return 1;
}
cmake cm(cmake::CommandSet::None, cmState::Role::Internal);
cmake cm(cmState::Role::Internal);
cmSystemTools::SetMessageCallback(
[&cm](std::string const& msg, cmMessageMetadata const& md) {
cmakemainMessageCallback(msg, md, &cm);
@@ -962,7 +959,7 @@ int do_install(int ac, char const* const* av)
} else {
for (auto const& script : handler.GetScripts()) {
std::vector<std::string> cmd = script.command;
cmake cm(cmake::CommandSet::Script, cmState::Role::Script);
cmake cm(cmState::Role::Script);
cmSystemTools::SetMessageCallback(
[&cm](std::string const& msg, cmMessageMetadata const& md) {
cmakemainMessageCallback(msg, md, &cm);
@@ -1065,7 +1062,7 @@ int do_workflow(int ac, char const* const* av)
return 1;
}
cmake cm(cmake::CommandSet::None, cmState::Role::Internal);
cmake cm(cmState::Role::Internal);
cmSystemTools::SetMessageCallback(
[&cm](std::string const& msg, cmMessageMetadata const& md) {
cmakemainMessageCallback(msg, md, &cm);
@@ -1109,7 +1106,7 @@ int do_open(int ac, char const* const* av)
return 1;
}
cmake cm(cmake::CommandSet::None, cmState::Role::Internal);
cmake cm(cmState::Role::Internal);
cmSystemTools::SetMessageCallback(
[&cm](std::string const& msg, cmMessageMetadata const& md) {
cmakemainMessageCallback(msg, md, &cm);
+3 -3
View File
@@ -1150,7 +1150,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
std::cerr << "-E capabilities accepts no additional arguments\n";
return 1;
}
cmake cm(cmake::CommandSet::None, cmState::Role::Internal);
cmake cm(cmState::Role::Internal);
std::cout << cm.ReportCapabilities();
return 0;
}
@@ -1398,7 +1398,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
// Create a cmake object instance to process dependencies.
// All we need is the `set` command.
cmake cm(cmake::CommandSet::Script, cmState::Role::Script);
cmake cm(cmState::Role::Script);
std::string gen;
std::string homeDir;
std::string startDir;
@@ -1752,7 +1752,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string> const& args,
}
// Create a cmake object instance to process dependencies.
// All we need is the `set` command.
cmake cm(cmake::CommandSet::Script, cmState::Role::Script);
cmake cm(cmState::Role::Script);
std::string homeDir;
std::string startDir;
std::string homeOutDir;
@@ -54,8 +54,7 @@ static Dummies CreateDummies(
std::string currentBinaryDirectory = "c:/CurrentBinaryDirectory")
{
Dummies dummies;
dummies.CMake = std::make_shared<cmake>(cmake::CommandSet::Project,
cmState::Role::Project);
dummies.CMake = std::make_shared<cmake>(cmState::Role::Project);
cmState* state = dummies.CMake->GetState();
dummies.GlobalGenerator =
std::make_shared<cmGlobalGenerator>(dummies.CMake.get());
@@ -501,7 +500,7 @@ static bool testCreateFromFileSet()
auto variablesManager =
std::make_shared<cmDebugger::cmDebuggerVariablesManager>();
cmake cm(cmake::CommandSet::None, cmState::Role::Internal);
cmake cm(cmState::Role::Internal);
cmFileSet fileSet(cm, "Foo", "HEADERS", cmFileSetVisibility::Public);
BT<std::string> directory;
directory.Value = "c:/";
@@ -545,7 +544,7 @@ static bool testCreateFromFileSets()
auto variablesManager =
std::make_shared<cmDebugger::cmDebuggerVariablesManager>();
cmake cm(cmake::CommandSet::None, cmState::Role::Internal);
cmake cm(cmState::Role::Internal);
cmFileSet fileSet(cm, "Foo", "HEADERS", cmFileSetVisibility::Public);
BT<std::string> directory;
directory.Value = "c:/";