mirror of
https://github.com/Kitware/CMake.git
synced 2025-10-22 16:07:49 +08:00
Use std::function
for callbacks
This commit is contained in:
@@ -43,12 +43,6 @@ cmCPackGenerator::~cmCPackGenerator()
|
|||||||
this->MakefileMap = nullptr;
|
this->MakefileMap = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmCPackGeneratorProgress(const char* msg, float prog, void* ptr)
|
|
||||||
{
|
|
||||||
cmCPackGenerator* self = static_cast<cmCPackGenerator*>(ptr);
|
|
||||||
self->DisplayVerboseOutput(msg, prog);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmCPackGenerator::DisplayVerboseOutput(const char* msg, float progress)
|
void cmCPackGenerator::DisplayVerboseOutput(const char* msg, float progress)
|
||||||
{
|
{
|
||||||
(void)progress;
|
(void)progress;
|
||||||
@@ -696,7 +690,9 @@ int cmCPackGenerator::InstallCMakeProject(
|
|||||||
cm.SetHomeOutputDirectory("");
|
cm.SetHomeOutputDirectory("");
|
||||||
cm.GetCurrentSnapshot().SetDefaultDefinitions();
|
cm.GetCurrentSnapshot().SetDefaultDefinitions();
|
||||||
cm.AddCMakePaths();
|
cm.AddCMakePaths();
|
||||||
cm.SetProgressCallback(cmCPackGeneratorProgress, this);
|
cm.SetProgressCallback([this](const char* msg, float prog) {
|
||||||
|
this->DisplayVerboseOutput(msg, prog);
|
||||||
|
});
|
||||||
cm.SetTrace(this->Trace);
|
cm.SetTrace(this->Trace);
|
||||||
cm.SetTraceExpand(this->TraceExpand);
|
cm.SetTraceExpand(this->TraceExpand);
|
||||||
cmGlobalGenerator gg(&cm);
|
cmGlobalGenerator gg(&cm);
|
||||||
|
@@ -90,12 +90,8 @@ int cpackDefinitionArgument(const char* argument, const char* cValue,
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cpackProgressCallback(const char* message, float progress,
|
static void cpackProgressCallback(const char* message, float /*unused*/)
|
||||||
void* clientdata)
|
|
||||||
{
|
{
|
||||||
(void)progress;
|
|
||||||
(void)clientdata;
|
|
||||||
|
|
||||||
std::cout << "-- " << message << std::endl;
|
std::cout << "-- " << message << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +208,7 @@ int main(int argc, char const* const* argv)
|
|||||||
cmake cminst(cmake::RoleScript, cmState::CPack);
|
cmake cminst(cmake::RoleScript, cmState::CPack);
|
||||||
cminst.SetHomeDirectory("");
|
cminst.SetHomeDirectory("");
|
||||||
cminst.SetHomeOutputDirectory("");
|
cminst.SetHomeOutputDirectory("");
|
||||||
cminst.SetProgressCallback(cpackProgressCallback, nullptr);
|
cminst.SetProgressCallback(cpackProgressCallback);
|
||||||
cminst.GetCurrentSnapshot().SetDefaultDefinitions();
|
cminst.GetCurrentSnapshot().SetDefaultDefinitions();
|
||||||
cmGlobalGenerator cmgg(&cminst);
|
cmGlobalGenerator cmgg(&cminst);
|
||||||
cmMakefile globalMF(&cmgg, cminst.GetCurrentSnapshot());
|
cmMakefile globalMF(&cmgg, cminst.GetCurrentSnapshot());
|
||||||
|
@@ -109,27 +109,6 @@ int cmCTestBuildAndTestHandler::RunCMake(std::string* outstring,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeMessageCallback(const char* m, const char* /*unused*/,
|
|
||||||
bool& /*unused*/, void* s)
|
|
||||||
{
|
|
||||||
std::string* out = static_cast<std::string*>(s);
|
|
||||||
*out += m;
|
|
||||||
*out += "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMakeProgressCallback(const char* msg, float /*unused*/, void* s)
|
|
||||||
{
|
|
||||||
std::string* out = static_cast<std::string*>(s);
|
|
||||||
*out += msg;
|
|
||||||
*out += "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
void CMakeOutputCallback(const char* m, size_t len, void* s)
|
|
||||||
{
|
|
||||||
std::string* out = static_cast<std::string*>(s);
|
|
||||||
out->append(m, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
class cmCTestBuildAndTestCaptureRAII
|
class cmCTestBuildAndTestCaptureRAII
|
||||||
{
|
{
|
||||||
cmake& CM;
|
cmake& CM;
|
||||||
@@ -138,17 +117,30 @@ public:
|
|||||||
cmCTestBuildAndTestCaptureRAII(cmake& cm, std::string& s)
|
cmCTestBuildAndTestCaptureRAII(cmake& cm, std::string& s)
|
||||||
: CM(cm)
|
: CM(cm)
|
||||||
{
|
{
|
||||||
cmSystemTools::SetMessageCallback(CMakeMessageCallback, &s);
|
cmSystemTools::SetMessageCallback(
|
||||||
cmSystemTools::SetStdoutCallback(CMakeOutputCallback, &s);
|
[&s](const char* msg, const char* /*unused*/, bool& /*unused*/) {
|
||||||
cmSystemTools::SetStderrCallback(CMakeOutputCallback, &s);
|
s += msg;
|
||||||
this->CM.SetProgressCallback(CMakeProgressCallback, &s);
|
s += "\n";
|
||||||
|
});
|
||||||
|
|
||||||
|
cmSystemTools::SetStdoutCallback(
|
||||||
|
[&s](const char* m, size_t len) { s.append(m, len); });
|
||||||
|
|
||||||
|
cmSystemTools::SetStderrCallback(
|
||||||
|
[&s](const char* m, size_t len) { s.append(m, len); });
|
||||||
|
|
||||||
|
this->CM.SetProgressCallback([&s](const char* msg, float /*unused*/) {
|
||||||
|
s += msg;
|
||||||
|
s += "\n";
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
~cmCTestBuildAndTestCaptureRAII()
|
~cmCTestBuildAndTestCaptureRAII()
|
||||||
{
|
{
|
||||||
this->CM.SetProgressCallback(nullptr, nullptr);
|
this->CM.SetProgressCallback(nullptr);
|
||||||
cmSystemTools::SetStderrCallback(nullptr, nullptr);
|
cmSystemTools::SetStderrCallback(nullptr);
|
||||||
cmSystemTools::SetStdoutCallback(nullptr, nullptr);
|
cmSystemTools::SetStdoutCallback(nullptr);
|
||||||
cmSystemTools::SetMessageCallback(nullptr, nullptr);
|
cmSystemTools::SetMessageCallback(nullptr);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -265,15 +265,6 @@ int cmCTestScriptHandler::ExecuteScript(const std::string& total_script_arg)
|
|||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ctestScriptProgressCallback(const char* m, float /*unused*/,
|
|
||||||
void* cd)
|
|
||||||
{
|
|
||||||
cmCTest* ctest = static_cast<cmCTest*>(cd);
|
|
||||||
if (m && *m) {
|
|
||||||
cmCTestLog(ctest, HANDLER_OUTPUT, "-- " << m << std::endl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void cmCTestScriptHandler::CreateCMake()
|
void cmCTestScriptHandler::CreateCMake()
|
||||||
{
|
{
|
||||||
// create a cmake instance to read the configuration script
|
// create a cmake instance to read the configuration script
|
||||||
@@ -299,7 +290,11 @@ void cmCTestScriptHandler::CreateCMake()
|
|||||||
this->ParentMakefile->GetRecursionDepth());
|
this->ParentMakefile->GetRecursionDepth());
|
||||||
}
|
}
|
||||||
|
|
||||||
this->CMake->SetProgressCallback(ctestScriptProgressCallback, this->CTest);
|
this->CMake->SetProgressCallback([this](const char* m, float /*unused*/) {
|
||||||
|
if (m && *m) {
|
||||||
|
cmCTestLog(this->CTest, HANDLER_OUTPUT, "-- " << m << std::endl);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
this->AddCTestCommand("ctest_build", new cmCTestBuildCommand);
|
this->AddCTestCommand("ctest_build", new cmCTestBuildCommand);
|
||||||
this->AddCTestCommand("ctest_configure", new cmCTestConfigureCommand);
|
this->AddCTestCommand("ctest_configure", new cmCTestConfigureCommand);
|
||||||
|
@@ -65,13 +65,6 @@ void onsig(int /*unused*/)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMakeMessageHandler(const char* message, const char* title,
|
|
||||||
bool& /*unused*/, void* clientData)
|
|
||||||
{
|
|
||||||
cmCursesForm* self = static_cast<cmCursesForm*>(clientData);
|
|
||||||
self->AddError(message, title);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char const* const* argv)
|
int main(int argc, char const* const* argv)
|
||||||
{
|
{
|
||||||
cmsys::Encoding::CommandLineArguments encoding_args =
|
cmsys::Encoding::CommandLineArguments encoding_args =
|
||||||
@@ -156,7 +149,10 @@ int main(int argc, char const* const* argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmSystemTools::SetMessageCallback(CMakeMessageHandler, myform);
|
cmSystemTools::SetMessageCallback(
|
||||||
|
[myform](const char* message, const char* title, bool& /*unused*/) {
|
||||||
|
myform->AddError(message, title);
|
||||||
|
});
|
||||||
|
|
||||||
cmCursesForm::CurrentForm = myform;
|
cmCursesForm::CurrentForm = myform;
|
||||||
|
|
||||||
|
@@ -506,12 +506,8 @@ void cmCursesMainForm::UpdateStatusBar(const char* message)
|
|||||||
pos_form_cursor(this->Form);
|
pos_form_cursor(this->Form);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmCursesMainForm::UpdateProgress(const char* msg, float prog, void* vp)
|
void cmCursesMainForm::UpdateProgress(const char* msg, float prog)
|
||||||
{
|
{
|
||||||
cmCursesMainForm* cm = static_cast<cmCursesMainForm*>(vp);
|
|
||||||
if (!cm) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
char tmp[1024];
|
char tmp[1024];
|
||||||
const char* cmsg = tmp;
|
const char* cmsg = tmp;
|
||||||
if (prog >= 0) {
|
if (prog >= 0) {
|
||||||
@@ -519,8 +515,8 @@ void cmCursesMainForm::UpdateProgress(const char* msg, float prog, void* vp)
|
|||||||
} else {
|
} else {
|
||||||
cmsg = msg;
|
cmsg = msg;
|
||||||
}
|
}
|
||||||
cm->UpdateStatusBar(cmsg);
|
this->UpdateStatusBar(cmsg);
|
||||||
cm->PrintKeys(1);
|
this->PrintKeys(1);
|
||||||
curses_move(1, 1);
|
curses_move(1, 1);
|
||||||
touchwin(stdscr);
|
touchwin(stdscr);
|
||||||
refresh();
|
refresh();
|
||||||
@@ -536,8 +532,8 @@ int cmCursesMainForm::Configure(int noconfigure)
|
|||||||
this->PrintKeys(1);
|
this->PrintKeys(1);
|
||||||
touchwin(stdscr);
|
touchwin(stdscr);
|
||||||
refresh();
|
refresh();
|
||||||
this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress,
|
this->CMakeInstance->SetProgressCallback(
|
||||||
this);
|
[this](const char* msg, float prog) { this->UpdateProgress(msg, prog); });
|
||||||
|
|
||||||
// always save the current gui values to disk
|
// always save the current gui values to disk
|
||||||
this->FillCacheManagerFromUI();
|
this->FillCacheManagerFromUI();
|
||||||
@@ -560,7 +556,7 @@ int cmCursesMainForm::Configure(int noconfigure)
|
|||||||
} else {
|
} else {
|
||||||
retVal = this->CMakeInstance->Configure();
|
retVal = this->CMakeInstance->Configure();
|
||||||
}
|
}
|
||||||
this->CMakeInstance->SetProgressCallback(nullptr, nullptr);
|
this->CMakeInstance->SetProgressCallback(nullptr);
|
||||||
|
|
||||||
keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
|
keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
|
||||||
|
|
||||||
@@ -606,8 +602,8 @@ int cmCursesMainForm::Generate()
|
|||||||
this->PrintKeys(1);
|
this->PrintKeys(1);
|
||||||
touchwin(stdscr);
|
touchwin(stdscr);
|
||||||
refresh();
|
refresh();
|
||||||
this->CMakeInstance->SetProgressCallback(cmCursesMainForm::UpdateProgress,
|
this->CMakeInstance->SetProgressCallback(
|
||||||
this);
|
[this](const char* msg, float prog) { this->UpdateProgress(msg, prog); });
|
||||||
|
|
||||||
// Get rid of previous errors
|
// Get rid of previous errors
|
||||||
this->Errors = std::vector<std::string>();
|
this->Errors = std::vector<std::string>();
|
||||||
@@ -615,7 +611,7 @@ int cmCursesMainForm::Generate()
|
|||||||
// run the generate process
|
// run the generate process
|
||||||
int retVal = this->CMakeInstance->Generate();
|
int retVal = this->CMakeInstance->Generate();
|
||||||
|
|
||||||
this->CMakeInstance->SetProgressCallback(nullptr, nullptr);
|
this->CMakeInstance->SetProgressCallback(nullptr);
|
||||||
keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
|
keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
|
||||||
|
|
||||||
if (retVal != 0 || !this->Errors.empty()) {
|
if (retVal != 0 || !this->Errors.empty()) {
|
||||||
|
@@ -101,8 +101,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Progress callback
|
* Progress callback
|
||||||
*/
|
*/
|
||||||
static void UpdateProgressOld(const char* msg, float prog, void*);
|
void UpdateProgress(const char* msg, float prog);
|
||||||
static void UpdateProgress(const char* msg, float prog, void*);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Copy the cache values from the user interface to the actual
|
// Copy the cache values from the user interface to the actual
|
||||||
|
@@ -23,16 +23,26 @@ QCMake::QCMake(QObject* p)
|
|||||||
|
|
||||||
cmSystemTools::DisableRunCommandOutput();
|
cmSystemTools::DisableRunCommandOutput();
|
||||||
cmSystemTools::SetRunCommandHideConsole(true);
|
cmSystemTools::SetRunCommandHideConsole(true);
|
||||||
cmSystemTools::SetMessageCallback(QCMake::messageCallback, this);
|
|
||||||
cmSystemTools::SetStdoutCallback(QCMake::stdoutCallback, this);
|
cmSystemTools::SetMessageCallback(
|
||||||
cmSystemTools::SetStderrCallback(QCMake::stderrCallback, this);
|
[this](const char* msg, const char* title, bool& cancel) {
|
||||||
|
this->messageCallback(msg, title, cancel);
|
||||||
|
});
|
||||||
|
cmSystemTools::SetStdoutCallback(
|
||||||
|
[this](const char* msg, size_t len) { this->stdoutCallback(msg, len); });
|
||||||
|
cmSystemTools::SetStderrCallback(
|
||||||
|
[this](const char* msg, size_t len) { this->stderrCallback(msg, len); });
|
||||||
|
|
||||||
this->CMakeInstance = new cmake(cmake::RoleProject, cmState::Project);
|
this->CMakeInstance = new cmake(cmake::RoleProject, cmState::Project);
|
||||||
this->CMakeInstance->SetCMakeEditCommand(
|
this->CMakeInstance->SetCMakeEditCommand(
|
||||||
cmSystemTools::GetCMakeGUICommand());
|
cmSystemTools::GetCMakeGUICommand());
|
||||||
this->CMakeInstance->SetProgressCallback(QCMake::progressCallback, this);
|
this->CMakeInstance->SetProgressCallback(
|
||||||
|
[this](const char* msg, float percent) {
|
||||||
|
this->progressCallback(msg, percent);
|
||||||
|
});
|
||||||
|
|
||||||
cmSystemTools::SetInterruptCallback(QCMake::interruptCallback, this);
|
cmSystemTools::SetInterruptCallback(
|
||||||
|
[this] { return this->interruptCallback(); });
|
||||||
|
|
||||||
std::vector<cmake::GeneratorInfo> generators;
|
std::vector<cmake::GeneratorInfo> generators;
|
||||||
this->CMakeInstance->GetRegisteredGenerators(
|
this->CMakeInstance->GetRegisteredGenerators(
|
||||||
@@ -330,46 +340,41 @@ void QCMake::interrupt()
|
|||||||
this->InterruptFlag.ref();
|
this->InterruptFlag.ref();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QCMake::interruptCallback(void* cd)
|
bool QCMake::interruptCallback()
|
||||||
{
|
{
|
||||||
QCMake* self = reinterpret_cast<QCMake*>(cd);
|
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||||
return self->InterruptFlag;
|
return this->InterruptFlag;
|
||||||
#else
|
#else
|
||||||
return self->InterruptFlag.load();
|
return this->InterruptFlag.load();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCMake::progressCallback(const char* msg, float percent, void* cd)
|
void QCMake::progressCallback(const char* msg, float percent)
|
||||||
{
|
{
|
||||||
QCMake* self = reinterpret_cast<QCMake*>(cd);
|
|
||||||
if (percent >= 0) {
|
if (percent >= 0) {
|
||||||
emit self->progressChanged(QString::fromLocal8Bit(msg), percent);
|
emit this->progressChanged(QString::fromLocal8Bit(msg), percent);
|
||||||
} else {
|
} else {
|
||||||
emit self->outputMessage(QString::fromLocal8Bit(msg));
|
emit this->outputMessage(QString::fromLocal8Bit(msg));
|
||||||
}
|
}
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCMake::messageCallback(const char* msg, const char* /*title*/,
|
void QCMake::messageCallback(const char* msg, const char* /*title*/,
|
||||||
bool& /*stop*/, void* cd)
|
bool& /*stop*/)
|
||||||
{
|
{
|
||||||
QCMake* self = reinterpret_cast<QCMake*>(cd);
|
emit this->errorMessage(QString::fromLocal8Bit(msg));
|
||||||
emit self->errorMessage(QString::fromLocal8Bit(msg));
|
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCMake::stdoutCallback(const char* msg, size_t len, void* cd)
|
void QCMake::stdoutCallback(const char* msg, size_t len)
|
||||||
{
|
{
|
||||||
QCMake* self = reinterpret_cast<QCMake*>(cd);
|
emit this->outputMessage(QString::fromLocal8Bit(msg, int(len)));
|
||||||
emit self->outputMessage(QString::fromLocal8Bit(msg, int(len)));
|
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
void QCMake::stderrCallback(const char* msg, size_t len, void* cd)
|
void QCMake::stderrCallback(const char* msg, size_t len)
|
||||||
{
|
{
|
||||||
QCMake* self = reinterpret_cast<QCMake*>(cd);
|
emit this->outputMessage(QString::fromLocal8Bit(msg, int(len)));
|
||||||
emit self->outputMessage(QString::fromLocal8Bit(msg, int(len)));
|
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -167,12 +167,12 @@ signals:
|
|||||||
protected:
|
protected:
|
||||||
cmake* CMakeInstance;
|
cmake* CMakeInstance;
|
||||||
|
|
||||||
static bool interruptCallback(void*);
|
bool interruptCallback();
|
||||||
static void progressCallback(const char* msg, float percent, void* cd);
|
void progressCallback(const char* msg, float percent);
|
||||||
static void messageCallback(const char* msg, const char* title, bool&,
|
void messageCallback(const char* msg, const char* title, bool&);
|
||||||
void* cd);
|
void stdoutCallback(const char* msg, size_t len);
|
||||||
static void stdoutCallback(const char* msg, size_t len, void* cd);
|
void stderrCallback(const char* msg, size_t len);
|
||||||
static void stderrCallback(const char* msg, size_t len, void* cd);
|
|
||||||
bool WarnUninitializedMode;
|
bool WarnUninitializedMode;
|
||||||
bool WarnUnusedMode;
|
bool WarnUnusedMode;
|
||||||
bool WarnUnusedAllMode;
|
bool WarnUnusedAllMode;
|
||||||
|
@@ -96,11 +96,16 @@ void cmServer::ProcessRequest(cmConnection* connection,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
cmSystemTools::SetMessageCallback(reportMessage,
|
cmSystemTools::SetMessageCallback(
|
||||||
const_cast<cmServerRequest*>(&request));
|
[&request](const char* msg, const char* title, bool& cancel) {
|
||||||
|
reportMessage(msg, title, cancel, request);
|
||||||
|
});
|
||||||
|
|
||||||
if (this->Protocol) {
|
if (this->Protocol) {
|
||||||
this->Protocol->CMakeInstance()->SetProgressCallback(
|
this->Protocol->CMakeInstance()->SetProgressCallback(
|
||||||
reportProgress, const_cast<cmServerRequest*>(&request));
|
[&request](const char* msg, float prog) {
|
||||||
|
reportProgress(msg, prog, request);
|
||||||
|
});
|
||||||
this->WriteResponse(connection, this->Protocol->Process(request),
|
this->WriteResponse(connection, this->Protocol->Process(request),
|
||||||
debug.get());
|
debug.get());
|
||||||
} else {
|
} else {
|
||||||
@@ -150,28 +155,25 @@ void cmServer::PrintHello(cmConnection* connection) const
|
|||||||
this->WriteJsonObject(connection, hello, nullptr);
|
this->WriteJsonObject(connection, hello, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmServer::reportProgress(const char* msg, float progress, void* data)
|
void cmServer::reportProgress(const char* msg, float progress,
|
||||||
|
const cmServerRequest& request)
|
||||||
{
|
{
|
||||||
const cmServerRequest* request = static_cast<const cmServerRequest*>(data);
|
|
||||||
assert(request);
|
|
||||||
if (progress < 0.0f || progress > 1.0f) {
|
if (progress < 0.0f || progress > 1.0f) {
|
||||||
request->ReportMessage(msg, "");
|
request.ReportMessage(msg, "");
|
||||||
} else {
|
} else {
|
||||||
request->ReportProgress(0, static_cast<int>(progress * 1000), 1000, msg);
|
request.ReportProgress(0, static_cast<int>(progress * 1000), 1000, msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmServer::reportMessage(const char* msg, const char* title,
|
void cmServer::reportMessage(const char* msg, const char* title,
|
||||||
bool& /* cancel */, void* data)
|
bool& /*cancel*/, const cmServerRequest& request)
|
||||||
{
|
{
|
||||||
const cmServerRequest* request = static_cast<const cmServerRequest*>(data);
|
|
||||||
assert(request);
|
|
||||||
assert(msg);
|
assert(msg);
|
||||||
std::string titleString;
|
std::string titleString;
|
||||||
if (title) {
|
if (title) {
|
||||||
titleString = title;
|
titleString = title;
|
||||||
}
|
}
|
||||||
request->ReportMessage(std::string(msg), titleString);
|
request.ReportMessage(std::string(msg), titleString);
|
||||||
}
|
}
|
||||||
|
|
||||||
cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request)
|
cmServerResponse cmServer::SetProtocolVersion(const cmServerRequest& request)
|
||||||
|
@@ -118,9 +118,10 @@ public:
|
|||||||
void OnConnected(cmConnection* connection) override;
|
void OnConnected(cmConnection* connection) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void reportProgress(const char* msg, float progress, void* data);
|
static void reportProgress(const char* msg, float progress,
|
||||||
|
const cmServerRequest& request);
|
||||||
static void reportMessage(const char* msg, const char* title, bool& cancel,
|
static void reportMessage(const char* msg, const char* title, bool& cancel,
|
||||||
void* data);
|
const cmServerRequest& request);
|
||||||
|
|
||||||
// Handle requests:
|
// Handle requests:
|
||||||
cmServerResponse SetProtocolVersion(const cmServerRequest& request);
|
cmServerResponse SetProtocolVersion(const cmServerRequest& request);
|
||||||
|
@@ -76,6 +76,15 @@
|
|||||||
# include <malloc.h> /* for malloc/free on QNX */
|
# include <malloc.h> /* for malloc/free on QNX */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
cmSystemTools::InterruptCallback s_InterruptCallback;
|
||||||
|
cmSystemTools::MessageCallback s_MessageCallback;
|
||||||
|
cmSystemTools::OutputCallback s_StderrCallback;
|
||||||
|
cmSystemTools::OutputCallback s_StdoutCallback;
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
static bool cm_isspace(char c)
|
static bool cm_isspace(char c)
|
||||||
{
|
{
|
||||||
return ((c & 0x80) == 0) && isspace(c);
|
return ((c & 0x80) == 0) && isspace(c);
|
||||||
@@ -161,15 +170,6 @@ bool cmSystemTools::s_FatalErrorOccured = false;
|
|||||||
bool cmSystemTools::s_DisableMessages = false;
|
bool cmSystemTools::s_DisableMessages = false;
|
||||||
bool cmSystemTools::s_ForceUnixPaths = false;
|
bool cmSystemTools::s_ForceUnixPaths = false;
|
||||||
|
|
||||||
cmSystemTools::MessageCallback cmSystemTools::s_MessageCallback;
|
|
||||||
cmSystemTools::OutputCallback cmSystemTools::s_StdoutCallback;
|
|
||||||
cmSystemTools::OutputCallback cmSystemTools::s_StderrCallback;
|
|
||||||
cmSystemTools::InterruptCallback cmSystemTools::s_InterruptCallback;
|
|
||||||
void* cmSystemTools::s_MessageCallbackClientData;
|
|
||||||
void* cmSystemTools::s_StdoutCallbackClientData;
|
|
||||||
void* cmSystemTools::s_StderrCallbackClientData;
|
|
||||||
void* cmSystemTools::s_InterruptCallbackClientData;
|
|
||||||
|
|
||||||
// replace replace with with as many times as it shows up in source.
|
// replace replace with with as many times as it shows up in source.
|
||||||
// write the result into source.
|
// write the result into source.
|
||||||
#if defined(_WIN32) && !defined(__CYGWIN__)
|
#if defined(_WIN32) && !defined(__CYGWIN__)
|
||||||
@@ -277,42 +277,38 @@ void cmSystemTools::Error(const std::string& m)
|
|||||||
cmSystemTools::Message(message, "Error");
|
cmSystemTools::Message(message, "Error");
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmSystemTools::SetInterruptCallback(InterruptCallback f, void* clientData)
|
void cmSystemTools::SetInterruptCallback(InterruptCallback f)
|
||||||
{
|
{
|
||||||
s_InterruptCallback = f;
|
s_InterruptCallback = std::move(f);
|
||||||
s_InterruptCallbackClientData = clientData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cmSystemTools::GetInterruptFlag()
|
bool cmSystemTools::GetInterruptFlag()
|
||||||
{
|
{
|
||||||
if (s_InterruptCallback) {
|
if (s_InterruptCallback) {
|
||||||
return (*s_InterruptCallback)(s_InterruptCallbackClientData);
|
return s_InterruptCallback();
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmSystemTools::SetMessageCallback(MessageCallback f, void* clientData)
|
void cmSystemTools::SetMessageCallback(MessageCallback f)
|
||||||
{
|
{
|
||||||
s_MessageCallback = f;
|
s_MessageCallback = std::move(f);
|
||||||
s_MessageCallbackClientData = clientData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmSystemTools::SetStdoutCallback(OutputCallback f, void* clientData)
|
void cmSystemTools::SetStdoutCallback(OutputCallback f)
|
||||||
{
|
{
|
||||||
s_StdoutCallback = f;
|
s_StdoutCallback = std::move(f);
|
||||||
s_StdoutCallbackClientData = clientData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmSystemTools::SetStderrCallback(OutputCallback f, void* clientData)
|
void cmSystemTools::SetStderrCallback(OutputCallback f)
|
||||||
{
|
{
|
||||||
s_StderrCallback = f;
|
s_StderrCallback = std::move(f);
|
||||||
s_StderrCallbackClientData = clientData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmSystemTools::Stderr(const std::string& s)
|
void cmSystemTools::Stderr(const std::string& s)
|
||||||
{
|
{
|
||||||
if (s_StderrCallback) {
|
if (s_StderrCallback) {
|
||||||
(*s_StderrCallback)(s.c_str(), s.length(), s_StderrCallbackClientData);
|
s_StderrCallback(s.c_str(), s.length());
|
||||||
} else {
|
} else {
|
||||||
std::cerr << s << std::flush;
|
std::cerr << s << std::flush;
|
||||||
}
|
}
|
||||||
@@ -321,7 +317,7 @@ void cmSystemTools::Stderr(const std::string& s)
|
|||||||
void cmSystemTools::Stdout(const std::string& s)
|
void cmSystemTools::Stdout(const std::string& s)
|
||||||
{
|
{
|
||||||
if (s_StdoutCallback) {
|
if (s_StdoutCallback) {
|
||||||
(*s_StdoutCallback)(s.c_str(), s.length(), s_StdoutCallbackClientData);
|
s_StdoutCallback(s.c_str(), s.length());
|
||||||
} else {
|
} else {
|
||||||
std::cout << s << std::flush;
|
std::cout << s << std::flush;
|
||||||
}
|
}
|
||||||
@@ -333,8 +329,7 @@ void cmSystemTools::Message(const char* m1, const char* title)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (s_MessageCallback) {
|
if (s_MessageCallback) {
|
||||||
(*s_MessageCallback)(m1, title, s_DisableMessages,
|
s_MessageCallback(m1, title, s_DisableMessages);
|
||||||
s_MessageCallbackClientData);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::cerr << m1 << std::endl << std::flush;
|
std::cerr << m1 << std::endl << std::flush;
|
||||||
|
@@ -10,6 +10,7 @@
|
|||||||
#include "cmProcessOutput.h"
|
#include "cmProcessOutput.h"
|
||||||
#include "cmsys/Process.h"
|
#include "cmsys/Process.h"
|
||||||
#include "cmsys/SystemTools.hxx" // IWYU pragma: export
|
#include "cmsys/SystemTools.hxx" // IWYU pragma: export
|
||||||
|
#include <functional>
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@@ -55,15 +56,14 @@ public:
|
|||||||
*/
|
*/
|
||||||
static std::string TrimWhitespace(const std::string& s);
|
static std::string TrimWhitespace(const std::string& s);
|
||||||
|
|
||||||
typedef void (*MessageCallback)(const char*, const char*, bool&, void*);
|
using MessageCallback = std::function<void(const char*, const char*, bool&)>;
|
||||||
/**
|
/**
|
||||||
* Set the function used by GUIs to display error messages
|
* Set the function used by GUIs to display error messages
|
||||||
* Function gets passed: message as a const char*,
|
* Function gets passed: message as a const char*,
|
||||||
* title as a const char*, and a reference to bool that when
|
* title as a const char*, and a reference to bool that when
|
||||||
* set to false, will disable further messages (cancel).
|
* set to false, will disable further messages (cancel).
|
||||||
*/
|
*/
|
||||||
static void SetMessageCallback(MessageCallback f,
|
static void SetMessageCallback(MessageCallback f);
|
||||||
void* clientData = nullptr);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display an error message.
|
* Display an error message.
|
||||||
@@ -81,19 +81,18 @@ public:
|
|||||||
Message(m.c_str(), title);
|
Message(m.c_str(), title);
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef void (*OutputCallback)(const char*, size_t length, void*);
|
using OutputCallback = std::function<void(const char*, size_t)>;
|
||||||
|
|
||||||
///! Send a string to stdout
|
///! Send a string to stdout
|
||||||
static void Stdout(const std::string& s);
|
static void Stdout(const std::string& s);
|
||||||
static void SetStdoutCallback(OutputCallback, void* clientData = nullptr);
|
static void SetStdoutCallback(OutputCallback f);
|
||||||
|
|
||||||
///! Send a string to stderr
|
///! Send a string to stderr
|
||||||
static void Stderr(const std::string& s);
|
static void Stderr(const std::string& s);
|
||||||
static void SetStderrCallback(OutputCallback, void* clientData = nullptr);
|
static void SetStderrCallback(OutputCallback f);
|
||||||
|
|
||||||
typedef bool (*InterruptCallback)(void*);
|
using InterruptCallback = std::function<bool()>;
|
||||||
static void SetInterruptCallback(InterruptCallback f,
|
static void SetInterruptCallback(InterruptCallback f);
|
||||||
void* clientData = nullptr);
|
|
||||||
static bool GetInterruptFlag();
|
static bool GetInterruptFlag();
|
||||||
|
|
||||||
///! Return true if there was an error at any point.
|
///! Return true if there was an error at any point.
|
||||||
@@ -548,14 +547,6 @@ private:
|
|||||||
static bool s_FatalErrorOccured;
|
static bool s_FatalErrorOccured;
|
||||||
static bool s_DisableMessages;
|
static bool s_DisableMessages;
|
||||||
static bool s_DisableRunCommandOutput;
|
static bool s_DisableRunCommandOutput;
|
||||||
static MessageCallback s_MessageCallback;
|
|
||||||
static OutputCallback s_StdoutCallback;
|
|
||||||
static OutputCallback s_StderrCallback;
|
|
||||||
static InterruptCallback s_InterruptCallback;
|
|
||||||
static void* s_MessageCallbackClientData;
|
|
||||||
static void* s_StdoutCallbackClientData;
|
|
||||||
static void* s_StderrCallbackClientData;
|
|
||||||
static void* s_InterruptCallbackClientData;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -157,8 +157,6 @@ cmake::cmake(Role role, cmState::Mode mode)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
this->GlobalGenerator = nullptr;
|
this->GlobalGenerator = nullptr;
|
||||||
this->ProgressCallback = nullptr;
|
|
||||||
this->ProgressCallbackClientData = nullptr;
|
|
||||||
this->CurrentWorkingMode = NORMAL_MODE;
|
this->CurrentWorkingMode = NORMAL_MODE;
|
||||||
|
|
||||||
#ifdef CMAKE_BUILD_WITH_CMAKE
|
#ifdef CMAKE_BUILD_WITH_CMAKE
|
||||||
@@ -1922,17 +1920,15 @@ bool cmake::DeleteCache(const std::string& path)
|
|||||||
return this->State->DeleteCache(path);
|
return this->State->DeleteCache(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmake::SetProgressCallback(ProgressCallbackType f, void* cd)
|
void cmake::SetProgressCallback(ProgressCallbackType f)
|
||||||
{
|
{
|
||||||
this->ProgressCallback = f;
|
this->ProgressCallback = std::move(f);
|
||||||
this->ProgressCallbackClientData = cd;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cmake::UpdateProgress(const char* msg, float prog)
|
void cmake::UpdateProgress(const char* msg, float prog)
|
||||||
{
|
{
|
||||||
if (this->ProgressCallback && !this->State->GetIsInTryCompile()) {
|
if (this->ProgressCallback && !this->State->GetIsInTryCompile()) {
|
||||||
(*this->ProgressCallback)(msg, prog, this->ProgressCallbackClientData);
|
this->ProgressCallback(msg, prog);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include "cmConfigure.h" // IWYU pragma: keep
|
#include "cmConfigure.h" // IWYU pragma: keep
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <memory> // IWYU pragma: keep
|
#include <memory> // IWYU pragma: keep
|
||||||
#include <set>
|
#include <set>
|
||||||
@@ -271,7 +272,7 @@ public:
|
|||||||
///! Parse command line arguments that might set cache values
|
///! Parse command line arguments that might set cache values
|
||||||
bool SetCacheArgs(const std::vector<std::string>&);
|
bool SetCacheArgs(const std::vector<std::string>&);
|
||||||
|
|
||||||
typedef void (*ProgressCallbackType)(const char* msg, float progress, void*);
|
using ProgressCallbackType = std::function<void(const char*, float)>;
|
||||||
/**
|
/**
|
||||||
* Set the function used by GUIs to receive progress updates
|
* Set the function used by GUIs to receive progress updates
|
||||||
* Function gets passed: message as a const char*, a progress
|
* Function gets passed: message as a const char*, a progress
|
||||||
@@ -279,7 +280,7 @@ public:
|
|||||||
* number provided may be negative in cases where a message is
|
* number provided may be negative in cases where a message is
|
||||||
* to be displayed without any progress percentage.
|
* to be displayed without any progress percentage.
|
||||||
*/
|
*/
|
||||||
void SetProgressCallback(ProgressCallbackType f, void* clientData = nullptr);
|
void SetProgressCallback(ProgressCallbackType f);
|
||||||
|
|
||||||
///! this is called by generators to update the progress
|
///! this is called by generators to update the progress
|
||||||
void UpdateProgress(const char* msg, float prog);
|
void UpdateProgress(const char* msg, float prog);
|
||||||
@@ -485,7 +486,6 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ProgressCallbackType ProgressCallback;
|
ProgressCallbackType ProgressCallback;
|
||||||
void* ProgressCallbackClientData;
|
|
||||||
bool InTryCompile;
|
bool InTryCompile;
|
||||||
WorkingMode CurrentWorkingMode;
|
WorkingMode CurrentWorkingMode;
|
||||||
bool DebugOutput;
|
bool DebugOutput;
|
||||||
|
@@ -117,9 +117,8 @@ int do_cmake(int ac, char const* const* av);
|
|||||||
static int do_build(int ac, char const* const* av);
|
static int do_build(int ac, char const* const* av);
|
||||||
static int do_open(int ac, char const* const* av);
|
static int do_open(int ac, char const* const* av);
|
||||||
|
|
||||||
static cmMakefile* cmakemainGetMakefile(void* clientdata)
|
static cmMakefile* cmakemainGetMakefile(cmake* cm)
|
||||||
{
|
{
|
||||||
cmake* cm = static_cast<cmake*>(clientdata);
|
|
||||||
if (cm && cm->GetDebugOutput()) {
|
if (cm && cm->GetDebugOutput()) {
|
||||||
cmGlobalGenerator* gg = cm->GetGlobalGenerator();
|
cmGlobalGenerator* gg = cm->GetGlobalGenerator();
|
||||||
if (gg) {
|
if (gg) {
|
||||||
@@ -129,10 +128,10 @@ static cmMakefile* cmakemainGetMakefile(void* clientdata)
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string cmakemainGetStack(void* clientdata)
|
static std::string cmakemainGetStack(cmake* cm)
|
||||||
{
|
{
|
||||||
std::string msg;
|
std::string msg;
|
||||||
cmMakefile* mf = cmakemainGetMakefile(clientdata);
|
cmMakefile* mf = cmakemainGetMakefile(cm);
|
||||||
if (mf) {
|
if (mf) {
|
||||||
msg = mf->FormatListFileStack();
|
msg = mf->FormatListFileStack();
|
||||||
if (!msg.empty()) {
|
if (!msg.empty()) {
|
||||||
@@ -144,15 +143,14 @@ static std::string cmakemainGetStack(void* clientdata)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void cmakemainMessageCallback(const char* m, const char* /*unused*/,
|
static void cmakemainMessageCallback(const char* m, const char* /*unused*/,
|
||||||
bool& /*unused*/, void* clientdata)
|
bool& /*unused*/, cmake* cm)
|
||||||
{
|
{
|
||||||
std::cerr << m << cmakemainGetStack(clientdata) << std::endl << std::flush;
|
std::cerr << m << cmakemainGetStack(cm) << std::endl << std::flush;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmakemainProgressCallback(const char* m, float prog,
|
static void cmakemainProgressCallback(const char* m, float prog, cmake* cm)
|
||||||
void* clientdata)
|
|
||||||
{
|
{
|
||||||
cmMakefile* mf = cmakemainGetMakefile(clientdata);
|
cmMakefile* mf = cmakemainGetMakefile(cm);
|
||||||
std::string dir;
|
std::string dir;
|
||||||
if ((mf) && (strstr(m, "Configuring") == m) && (prog < 0)) {
|
if ((mf) && (strstr(m, "Configuring") == m) && (prog < 0)) {
|
||||||
dir = " ";
|
dir = " ";
|
||||||
@@ -163,8 +161,7 @@ static void cmakemainProgressCallback(const char* m, float prog,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ((prog < 0) || (!dir.empty())) {
|
if ((prog < 0) || (!dir.empty())) {
|
||||||
std::cout << "-- " << m << dir << cmakemainGetStack(clientdata)
|
std::cout << "-- " << m << dir << cmakemainGetStack(cm) << std::endl;
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
@@ -322,8 +319,13 @@ int do_cmake(int ac, char const* const* av)
|
|||||||
cmake cm(role, mode);
|
cmake cm(role, mode);
|
||||||
cm.SetHomeDirectory("");
|
cm.SetHomeDirectory("");
|
||||||
cm.SetHomeOutputDirectory("");
|
cm.SetHomeOutputDirectory("");
|
||||||
cmSystemTools::SetMessageCallback(cmakemainMessageCallback, &cm);
|
cmSystemTools::SetMessageCallback(
|
||||||
cm.SetProgressCallback(cmakemainProgressCallback, &cm);
|
[&cm](const char* msg, const char* title, bool& cancel) {
|
||||||
|
cmakemainMessageCallback(msg, title, cancel, &cm);
|
||||||
|
});
|
||||||
|
cm.SetProgressCallback([&cm](const char* msg, float prog) {
|
||||||
|
cmakemainProgressCallback(msg, prog, &cm);
|
||||||
|
});
|
||||||
cm.SetWorkingMode(workingMode);
|
cm.SetWorkingMode(workingMode);
|
||||||
|
|
||||||
int res = cm.Run(args, view_only);
|
int res = cm.Run(args, view_only);
|
||||||
@@ -498,8 +500,13 @@ static int do_build(int ac, char const* const* av)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmake cm(cmake::RoleInternal, cmState::Unknown);
|
cmake cm(cmake::RoleInternal, cmState::Unknown);
|
||||||
cmSystemTools::SetMessageCallback(cmakemainMessageCallback, &cm);
|
cmSystemTools::SetMessageCallback(
|
||||||
cm.SetProgressCallback(cmakemainProgressCallback, &cm);
|
[&cm](const char* msg, const char* title, bool& cancel) {
|
||||||
|
cmakemainMessageCallback(msg, title, cancel, &cm);
|
||||||
|
});
|
||||||
|
cm.SetProgressCallback([&cm](const char* msg, float prog) {
|
||||||
|
cmakemainProgressCallback(msg, prog, &cm);
|
||||||
|
});
|
||||||
return cm.Build(jobs, dir, target, config, nativeOptions, clean, verbose);
|
return cm.Build(jobs, dir, target, config, nativeOptions, clean, verbose);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -536,8 +543,13 @@ static int do_open(int ac, char const* const* av)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmake cm(cmake::RoleInternal, cmState::Unknown);
|
cmake cm(cmake::RoleInternal, cmState::Unknown);
|
||||||
cmSystemTools::SetMessageCallback(cmakemainMessageCallback, &cm);
|
cmSystemTools::SetMessageCallback(
|
||||||
cm.SetProgressCallback(cmakemainProgressCallback, &cm);
|
[&cm](const char* msg, const char* title, bool& cancel) {
|
||||||
|
cmakemainMessageCallback(msg, title, cancel, &cm);
|
||||||
|
});
|
||||||
|
cm.SetProgressCallback([&cm](const char* msg, float prog) {
|
||||||
|
cmakemainProgressCallback(msg, prog, &cm);
|
||||||
|
});
|
||||||
return cm.Open(dir, false) ? 0 : 1;
|
return cm.Open(dir, false) ? 0 : 1;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user