ProjectBuilderWorker_mac.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include <ProjectBuilderWorker.h>
  9. #include <ProjectManagerDefs.h>
  10. #include <ProjectUtils.h>
  11. #include <QDir>
  12. #include <QString>
  13. namespace O3DE::ProjectManager
  14. {
  15. namespace Internal
  16. {
  17. AZ::Outcome<QString, QString> QueryInstalledCmakeFullPath()
  18. {
  19. auto environmentRequest = ProjectUtils::SetupCommandLineProcessEnvironment();
  20. if (!environmentRequest.IsSuccess())
  21. {
  22. return AZ::Failure(environmentRequest.GetError());
  23. }
  24. auto queryCmakeInstalled = ProjectUtils::ExecuteCommandResult("which",
  25. QStringList{ProjectCMakeCommand});
  26. if (!queryCmakeInstalled.IsSuccess())
  27. {
  28. return AZ::Failure(QObject::tr("Unable to detect CMake on this host."));
  29. }
  30. QString cmakeInstalledPath = queryCmakeInstalled.GetValue().split("\n")[0];
  31. return AZ::Success(cmakeInstalledPath);
  32. }
  33. }
  34. AZ::Outcome<QStringList, QString> ProjectBuilderWorker::ConstructCmakeGenerateProjectArguments(const QString& thirdPartyPath) const
  35. {
  36. // For Mac, we need to resolve the full path of cmake and use that in the process request. For
  37. // some reason, 'which' will resolve the full path, but when you just specify cmake with the same
  38. // environment, it is unable to resolve. To work around this, we will use 'which' to resolve the
  39. // full path and then use it as the command argument
  40. auto cmakeInstalledPathQuery = Internal::QueryInstalledCmakeFullPath();
  41. if (!cmakeInstalledPathQuery.IsSuccess())
  42. {
  43. return AZ::Failure(cmakeInstalledPathQuery.GetError());
  44. }
  45. QString cmakeInstalledPath = cmakeInstalledPathQuery.GetValue();
  46. QString targetBuildPath = QDir(m_projectInfo.m_path).filePath(ProjectBuildPathPostfix);
  47. return AZ::Success(QStringList{cmakeInstalledPath,
  48. "-B", targetBuildPath,
  49. "-S", m_projectInfo.m_path,
  50. "-GXcode"});
  51. }
  52. AZ::Outcome<QStringList, QString> ProjectBuilderWorker::ConstructCmakeBuildCommandArguments() const
  53. {
  54. // For Mac, we need to resolve the full path of cmake and use that in the process request. For
  55. // some reason, 'which' will resolve the full path, but when you just specify cmake with the same
  56. // environment, it is unable to resolve. To work around this, we will use 'which' to resolve the
  57. // full path and then use it as the command argument
  58. auto cmakeInstalledPathQuery = Internal::QueryInstalledCmakeFullPath();
  59. if (!cmakeInstalledPathQuery.IsSuccess())
  60. {
  61. return AZ::Failure(cmakeInstalledPathQuery.GetError());
  62. }
  63. QString cmakeInstalledPath = cmakeInstalledPathQuery.GetValue();
  64. QString targetBuildPath = QDir(m_projectInfo.m_path).filePath(ProjectBuildPathPostfix);
  65. QString launcherTargetName = m_projectInfo.m_projectName + ".GameLauncher";
  66. return AZ::Success(QStringList{cmakeInstalledPath,
  67. "--build", targetBuildPath,
  68. "--config", "profile",
  69. "--target", launcherTargetName, ProjectCMakeBuildTargetEditor});
  70. }
  71. AZ::Outcome<QStringList, QString> ProjectBuilderWorker::ConstructKillProcessCommandArguments(const QString& pidToKill) const
  72. {
  73. return AZ::Success(QStringList{"kill", "-9", pidToKill});
  74. }
  75. } // namespace O3DE::ProjectManager