summaryrefslogtreecommitdiffstats
path: root/Source/cmakemain.cxx
diff options
context:
space:
mode:
authorRegina Pfeifer <regina@mailbox.org>2019-01-25 20:31:33 (GMT)
committerRegina Pfeifer <regina@mailbox.org>2019-01-29 15:32:52 (GMT)
commitbcee24aecc1eaf6615eac9f24ae06acdf38845d3 (patch)
tree7a5ce493d66e1ff9a154bbd7503bd6e646624444 /Source/cmakemain.cxx
parent9620cb935a49e7b4955f5b1d0ffa2e93b4327591 (diff)
downloadCMake-bcee24aecc1eaf6615eac9f24ae06acdf38845d3.zip
CMake-bcee24aecc1eaf6615eac9f24ae06acdf38845d3.tar.gz
CMake-bcee24aecc1eaf6615eac9f24ae06acdf38845d3.tar.bz2
Use `std::function` for callbacks
Diffstat (limited to 'Source/cmakemain.cxx')
-rw-r--r--Source/cmakemain.cxx46
1 files changed, 29 insertions, 17 deletions
diff --git a/Source/cmakemain.cxx b/Source/cmakemain.cxx
index 0ec2552..f1a223b 100644
--- a/Source/cmakemain.cxx
+++ b/Source/cmakemain.cxx
@@ -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_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()) {
cmGlobalGenerator* gg = cm->GetGlobalGenerator();
if (gg) {
@@ -129,10 +128,10 @@ static cmMakefile* cmakemainGetMakefile(void* clientdata)
return nullptr;
}
-static std::string cmakemainGetStack(void* clientdata)
+static std::string cmakemainGetStack(cmake* cm)
{
std::string msg;
- cmMakefile* mf = cmakemainGetMakefile(clientdata);
+ cmMakefile* mf = cmakemainGetMakefile(cm);
if (mf) {
msg = mf->FormatListFileStack();
if (!msg.empty()) {
@@ -144,15 +143,14 @@ static std::string cmakemainGetStack(void* clientdata)
}
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,
- void* clientdata)
+static void cmakemainProgressCallback(const char* m, float prog, cmake* cm)
{
- cmMakefile* mf = cmakemainGetMakefile(clientdata);
+ cmMakefile* mf = cmakemainGetMakefile(cm);
std::string dir;
if ((mf) && (strstr(m, "Configuring") == m) && (prog < 0)) {
dir = " ";
@@ -163,8 +161,7 @@ static void cmakemainProgressCallback(const char* m, float prog,
}
if ((prog < 0) || (!dir.empty())) {
- std::cout << "-- " << m << dir << cmakemainGetStack(clientdata)
- << std::endl;
+ std::cout << "-- " << m << dir << cmakemainGetStack(cm) << std::endl;
}
std::cout.flush();
@@ -322,8 +319,13 @@ int do_cmake(int ac, char const* const* av)
cmake cm(role, mode);
cm.SetHomeDirectory("");
cm.SetHomeOutputDirectory("");
- cmSystemTools::SetMessageCallback(cmakemainMessageCallback, &cm);
- cm.SetProgressCallback(cmakemainProgressCallback, &cm);
+ cmSystemTools::SetMessageCallback(
+ [&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);
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);
- cmSystemTools::SetMessageCallback(cmakemainMessageCallback, &cm);
- cm.SetProgressCallback(cmakemainProgressCallback, &cm);
+ cmSystemTools::SetMessageCallback(
+ [&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);
#endif
}
@@ -536,8 +543,13 @@ static int do_open(int ac, char const* const* av)
}
cmake cm(cmake::RoleInternal, cmState::Unknown);
- cmSystemTools::SetMessageCallback(cmakemainMessageCallback, &cm);
- cm.SetProgressCallback(cmakemainProgressCallback, &cm);
+ cmSystemTools::SetMessageCallback(
+ [&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;
#endif
}