Open CMake GUI from Project Manager (#4360)

This provides a fast way for engineers who want to configure -> generate -> open project in IDE -> build & run to do so without waiting for a potentially lengthy Project Manager build.

Signed-off-by: AMZN-alexpete <26804013+AMZN-alexpete@users.noreply.github.com>
This commit is contained in:
Alex Peterson
2021-10-04 13:20:42 -07:00
committed by GitHub
parent c9608846a1
commit 555e95679d
10 changed files with 190 additions and 19 deletions
@@ -8,6 +8,7 @@
#include <ProjectUtils.h>
#include <ProjectManagerDefs.h>
#include <QProcessEnvironment>
#include <QDir>
namespace O3DE::ProjectManager
{
@@ -18,7 +19,10 @@ namespace O3DE::ProjectManager
AZ::Outcome<QProcessEnvironment, QString> GetCommandLineProcessEnvironment()
{
return AZ::Success(QProcessEnvironment(QProcessEnvironment::systemEnvironment()));
QProcessEnvironment currentEnvironment(QProcessEnvironment::systemEnvironment());
currentEnvironment.insert("CC", "clang-12");
currentEnvironment.insert("CXX", "clang++-12");
return AZ::Success(currentEnvironment);
}
AZ::Outcome<QString, QString> FindSupportedCompilerForPlatform()
@@ -27,7 +31,7 @@ namespace O3DE::ProjectManager
auto whichCMakeResult = ProjectUtils::ExecuteCommandResult("which", QStringList{ProjectCMakeCommand}, QProcessEnvironment::systemEnvironment());
if (!whichCMakeResult.IsSuccess())
{
return AZ::Failure(QObject::tr("CMake not found. \n\n"
return AZ::Failure(QObject::tr("CMake not found. <br><br>"
"Make sure that the minimum version of CMake is installed and available from the command prompt. "
"Refer to the <a href='https://o3de.org/docs/welcome-guide/setup/requirements/#cmake'>O3DE requirements</a> page for more information."));
}
@@ -45,10 +49,42 @@ namespace O3DE::ProjectManager
return AZ::Success(supportClangCommand);
}
}
return AZ::Failure(QObject::tr("Clang not found. \n\n"
return AZ::Failure(QObject::tr("Clang not found. <br><br>"
"Make sure that the clang is installed and available from the command prompt. "
"Refer to the <a href='https://o3de.org/docs/welcome-guide/setup/requirements/#cmake'>O3DE requirements</a> page for more information."));
}
AZ::Outcome<void, QString> OpenCMakeGUI(const QString& projectPath)
{
AZ::Outcome processEnvResult = GetCommandLineProcessEnvironment();
if (!processEnvResult.IsSuccess())
{
return AZ::Failure(processEnvResult.GetError());
}
QString projectBuildPath = QDir(projectPath).filePath(ProjectBuildPathPostfix);
AZ::Outcome projectBuildPathResult = GetProjectBuildPath(projectPath);
if (projectBuildPathResult.IsSuccess())
{
projectBuildPath = projectBuildPathResult.GetValue();
}
QProcess process;
process.setProcessEnvironment(processEnvResult.GetValue());
// if the project build path is relative, it should be relative to the project path
process.setWorkingDirectory(projectPath);
process.setProgram("cmake-gui");
process.setArguments({ "-S", projectPath, "-B", projectBuildPath });
if(!process.startDetached())
{
return AZ::Failure(QObject::tr("Failed to start CMake GUI"));
}
return AZ::Success();
}
} // namespace ProjectUtils
} // namespace O3DE::ProjectManager
@@ -8,6 +8,7 @@
#include <ProjectUtils.h>
#include <QProcess>
#include <QStandardPaths>
namespace O3DE::ProjectManager
{
@@ -61,5 +62,37 @@ namespace O3DE::ProjectManager
return AZ::Success(xcodeBuilderVersionNumber);
}
AZ::Outcome<void, QString> OpenCMakeGUI(const QString& projectPath)
{
const QString cmakeHelp = QObject::tr("Please verify you've installed CMake.app from "
"<a href=\"https://cmake.org\">cmake.org</a> or, if using HomeBrew, "
"have installed it with <pre>brew install --cask cmake</pre>");
QString cmakeAppPath = QStandardPaths::locate(QStandardPaths::ApplicationsLocation, "CMake.app", QStandardPaths::LocateDirectory);
if (cmakeAppPath.isEmpty())
{
return AZ::Failure(QObject::tr("CMake.app not found.") + cmakeHelp);
}
QString projectBuildPath = QDir(projectPath).filePath(ProjectBuildPathPostfix);
AZ::Outcome result = GetProjectBuildPath(projectPath);
if (result.IsSuccess())
{
projectBuildPath = result.GetValue();
}
QProcess process;
// if the project build path is relative, it should be relative to the project path
process.setWorkingDirectory(projectPath);
process.setProgram("open");
process.setArguments({"-a", "CMake", "--args", "-S", projectPath, "-B", projectBuildPath});
if(!process.startDetached())
{
return AZ::Failure(QObject::tr("CMake.app failed to open.") + cmakeHelp);
}
return AZ::Success();
}
} // namespace ProjectUtils
} // namespace O3DE::ProjectManager
@@ -92,12 +92,43 @@ namespace O3DE::ProjectManager
}
}
return AZ::Failure(QObject::tr("Visual Studio 2019 version 16.9.2 or higher not found.\n\n"
return AZ::Failure(QObject::tr("Visual Studio 2019 version 16.9.2 or higher not found.<br><br>"
"Visual Studio 2019 is required to build this project."
" Install any edition of <a href='https://visualstudio.microsoft.com/downloads/'>Visual Studio 2019</a>"
" or update to a newer version before proceeding to the next step."
" While installing configure Visual Studio with these <a href='https://o3de.org/docs/welcome-guide/setup/requirements/#visual-studio-configuration'>workloads</a>."));
}
AZ::Outcome<void, QString> OpenCMakeGUI(const QString& projectPath)
{
AZ::Outcome processEnvResult = GetCommandLineProcessEnvironment();
if (!processEnvResult.IsSuccess())
{
return AZ::Failure(processEnvResult.GetError());
}
QString projectBuildPath = QDir(projectPath).filePath(ProjectBuildPathPostfix);
AZ::Outcome projectBuildPathResult = GetProjectBuildPath(projectPath);
if (projectBuildPathResult.IsSuccess())
{
projectBuildPath = projectBuildPathResult.GetValue();
}
QProcess process;
process.setProcessEnvironment(processEnvResult.GetValue());
// if the project build path is relative, it should be relative to the project path
process.setWorkingDirectory(projectPath);
process.setProgram("cmake-gui");
process.setArguments({ "-S", projectPath, "-B", projectBuildPath });
if(!process.startDetached())
{
return AZ::Failure(QObject::tr("Failed to start CMake GUI"));
}
return AZ::Success();
}
} // namespace ProjectUtils
} // namespace O3DE::ProjectManager