201 lines
5.3 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2020-02-01 23:06:01 +01:00
#include <csignal>
2021-09-14 00:13:48 +02:00
#include <cstdio>
#include <cstdlib>
2020-02-01 23:06:01 +01:00
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
#include "cmsys/Encoding.hxx"
2020-08-30 11:54:41 +02:00
#include "cmCursesColor.h"
2016-10-30 18:24:19 +01:00
#include "cmCursesForm.h"
#include "cmCursesMainForm.h"
2016-07-09 11:21:54 +02:00
#include "cmCursesStandardIncludes.h"
2016-10-30 18:24:19 +01:00
#include "cmDocumentation.h"
2019-11-11 23:01:05 +01:00
#include "cmDocumentationEntry.h" // IWYU pragma: keep
2021-09-14 00:13:48 +02:00
#include "cmMessageMetadata.h"
2019-11-11 23:01:05 +01:00
#include "cmState.h"
2020-08-30 11:54:41 +02:00
#include "cmStringAlgorithms.h"
2016-10-30 18:24:19 +01:00
#include "cmSystemTools.h"
#include "cmake.h"
2016-07-09 11:21:54 +02:00
static const char* cmDocumentationName[][2] = {
2018-01-26 17:06:56 +01:00
{ nullptr, " ccmake - Curses Interface for CMake." },
{ nullptr, nullptr }
};
2016-07-09 11:21:54 +02:00
static const char* cmDocumentationUsage[][2] = {
2018-08-09 18:06:22 +02:00
{ nullptr,
" ccmake <path-to-source>\n"
" ccmake <path-to-existing-build>" },
{ nullptr,
"Specify a source directory to (re-)generate a build system for "
"it in the current working directory. Specify an existing build "
"directory to re-generate its build system." },
2018-01-26 17:06:56 +01:00
{ nullptr, nullptr }
2015-04-27 22:25:09 +02:00
};
2016-07-09 11:21:54 +02:00
static const char* cmDocumentationUsageNote[][2] = {
2018-01-26 17:06:56 +01:00
{ nullptr, "Run 'ccmake --help' for more information." },
{ nullptr, nullptr }
};
2018-08-09 18:06:22 +02:00
static const char* cmDocumentationOptions[][2] = {
CMAKE_STANDARD_OPTIONS_TABLE,
{ nullptr, nullptr }
};
2018-01-26 17:06:56 +01:00
cmCursesForm* cmCursesForm::CurrentForm = nullptr;
2022-03-29 21:10:50 +02:00
#ifndef _WIN32
2016-07-09 11:21:54 +02:00
extern "C" {
2022-03-29 21:10:50 +02:00
static void onsig(int /*unused*/)
{
2016-07-09 11:21:54 +02:00
if (cmCursesForm::CurrentForm) {
2022-03-29 21:10:50 +02:00
cmCursesForm::CurrentForm->HandleResize();
2016-07-09 11:21:54 +02:00
}
signal(SIGWINCH, onsig);
}
}
2022-03-29 21:10:50 +02:00
#endif // _WIN32
2014-08-03 19:52:23 +02:00
int main(int argc, char const* const* argv)
{
2019-11-11 23:01:05 +01:00
cmSystemTools::EnsureStdPipes();
2014-08-03 19:52:23 +02:00
cmsys::Encoding::CommandLineArguments encoding_args =
cmsys::Encoding::CommandLineArguments::Main(argc, argv);
argc = encoding_args.argc();
argv = encoding_args.argv();
2018-04-23 21:13:27 +02:00
cmSystemTools::InitializeLibUV();
2014-08-03 19:52:23 +02:00
cmSystemTools::FindCMakeResources(argv[0]);
cmDocumentation doc;
2012-04-19 19:04:21 +03:00
doc.addCMakeStandardDocSections();
2016-07-09 11:21:54 +02:00
if (doc.CheckOptions(argc, argv)) {
2019-11-11 23:01:05 +01:00
cmake hcm(cmake::RoleInternal, cmState::Unknown);
2015-08-17 11:37:30 +02:00
hcm.SetHomeDirectory("");
hcm.SetHomeOutputDirectory("");
2014-08-03 19:52:23 +02:00
hcm.AddCMakePaths();
2019-11-11 23:01:05 +01:00
auto generators = hcm.GetGeneratorsDocumentation();
doc.SetName("ccmake");
2016-07-09 11:21:54 +02:00
doc.SetSection("Name", cmDocumentationName);
doc.SetSection("Usage", cmDocumentationUsage);
if (argc == 1) {
doc.AppendSection("Usage", cmDocumentationUsageNote);
2012-02-18 12:40:36 +02:00
}
2019-11-11 23:01:05 +01:00
doc.AppendSection("Generators", generators);
2016-07-09 11:21:54 +02:00
doc.PrependSection("Options", cmDocumentationOptions);
return doc.PrintRequestedDocumentation(std::cout) ? 0 : 1;
}
2012-02-18 12:40:36 +02:00
bool debug = false;
unsigned int i;
int j;
std::vector<std::string> args;
2016-07-09 11:21:54 +02:00
for (j = 0; j < argc; ++j) {
if (strcmp(argv[j], "-debug") == 0) {
debug = true;
2016-07-09 11:21:54 +02:00
} else {
2019-11-11 23:01:05 +01:00
args.emplace_back(argv[j]);
}
2016-07-09 11:21:54 +02:00
}
std::string cacheDir = cmSystemTools::GetCurrentWorkingDirectory();
2016-07-09 11:21:54 +02:00
for (i = 1; i < args.size(); ++i) {
2020-08-30 11:54:41 +02:00
std::string const& arg = args[i];
if (cmHasPrefix(arg, "-B")) {
cacheDir = arg.substr(2);
}
2016-07-09 11:21:54 +02:00
}
cmSystemTools::DisableRunCommandOutput();
2016-07-09 11:21:54 +02:00
if (debug) {
cmCursesForm::DebugStart();
2016-07-09 11:21:54 +02:00
}
2021-09-14 00:13:48 +02:00
if (initscr() == nullptr) {
fprintf(stderr, "Error: ncurses initialization failed\n");
exit(1);
}
2016-07-09 11:21:54 +02:00
noecho(); /* Echo off */
cbreak(); /* nl- or cr not needed */
2017-04-14 19:02:05 +02:00
keypad(stdscr, true); /* Use key symbols as KEY_DOWN */
2020-08-30 11:54:41 +02:00
cmCursesColor::InitColors();
2022-03-29 21:10:50 +02:00
#ifndef _WIN32
signal(SIGWINCH, onsig);
2022-03-29 21:10:50 +02:00
#endif // _WIN32
2020-02-01 23:06:01 +01:00
int x;
int y;
getmaxyx(stdscr, y, x);
2016-07-09 11:21:54 +02:00
if (x < cmCursesMainForm::MIN_WIDTH || y < cmCursesMainForm::MIN_HEIGHT) {
endwin();
std::cerr << "Window is too small. A size of at least "
2012-02-18 12:40:36 +02:00
<< cmCursesMainForm::MIN_WIDTH << " x "
2016-07-09 11:21:54 +02:00
<< cmCursesMainForm::MIN_HEIGHT << " is required to run ccmake."
<< std::endl;
return 1;
2016-07-09 11:21:54 +02:00
}
cmCursesMainForm* myform;
myform = new cmCursesMainForm(args, x);
2016-07-09 11:21:54 +02:00
if (myform->LoadCache(cacheDir.c_str())) {
curses_clear();
touchwin(stdscr);
endwin();
delete myform;
std::cerr << "Error running cmake::LoadCache(). Aborting.\n";
return 1;
2016-07-09 11:21:54 +02:00
}
2020-08-30 11:54:41 +02:00
/*
* The message is stored in a list by the form which will be
* joined by '\n' before display.
* Removing any trailing '\n' avoid extra empty lines in the final results
*/
auto cleanMessage = [](const std::string& message) -> std::string {
auto msg = message;
if (!msg.empty() && msg.back() == '\n') {
msg.pop_back();
}
return msg;
};
2019-11-11 23:01:05 +01:00
cmSystemTools::SetMessageCallback(
2021-09-14 00:13:48 +02:00
[&](const std::string& message, const cmMessageMetadata& md) {
myform->AddError(cleanMessage(message), md.title);
2019-11-11 23:01:05 +01:00
});
2020-08-30 11:54:41 +02:00
cmSystemTools::SetStderrCallback([&](const std::string& message) {
myform->AddError(cleanMessage(message), "");
});
cmSystemTools::SetStdoutCallback([&](const std::string& message) {
myform->UpdateProgress(cleanMessage(message), -1);
});
cmCursesForm::CurrentForm = myform;
myform->InitializeUI();
2016-07-09 11:21:54 +02:00
if (myform->Configure(1) == 0) {
myform->Render(1, 1, x, y);
myform->HandleInput();
2016-07-09 11:21:54 +02:00
}
2012-02-18 12:40:36 +02:00
// Need to clean-up better
curses_clear();
touchwin(stdscr);
endwin();
delete cmCursesForm::CurrentForm;
2018-01-26 17:06:56 +01:00
cmCursesForm::CurrentForm = nullptr;
std::cout << std::endl << std::endl;
2012-02-18 12:40:36 +02:00
return 0;
}