cmBuildCommand.cxx 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmBuildCommand.h"
  11. #include "cmGlobalGenerator.h"
  12. bool cmBuildCommand::InitialPass(std::vector<std::string> const& args,
  13. cmExecutionStatus&)
  14. {
  15. // Support the legacy signature of the command:
  16. //
  17. if (2 == args.size()) {
  18. return this->TwoArgsSignature(args);
  19. }
  20. return this->MainSignature(args);
  21. }
  22. bool cmBuildCommand::MainSignature(std::vector<std::string> const& args)
  23. {
  24. if (args.size() < 1) {
  25. this->SetError("requires at least one argument naming a CMake variable");
  26. return false;
  27. }
  28. // The cmake variable in which to store the result.
  29. const char* variable = args[0].c_str();
  30. // Parse remaining arguments.
  31. const char* configuration = CM_NULLPTR;
  32. const char* project_name = CM_NULLPTR;
  33. std::string target;
  34. enum Doing
  35. {
  36. DoingNone,
  37. DoingConfiguration,
  38. DoingProjectName,
  39. DoingTarget
  40. };
  41. Doing doing = DoingNone;
  42. for (unsigned int i = 1; i < args.size(); ++i) {
  43. if (args[i] == "CONFIGURATION") {
  44. doing = DoingConfiguration;
  45. } else if (args[i] == "PROJECT_NAME") {
  46. doing = DoingProjectName;
  47. } else if (args[i] == "TARGET") {
  48. doing = DoingTarget;
  49. } else if (doing == DoingConfiguration) {
  50. doing = DoingNone;
  51. configuration = args[i].c_str();
  52. } else if (doing == DoingProjectName) {
  53. doing = DoingNone;
  54. project_name = args[i].c_str();
  55. } else if (doing == DoingTarget) {
  56. doing = DoingNone;
  57. target = args[i];
  58. } else {
  59. std::ostringstream e;
  60. e << "unknown argument \"" << args[i] << "\"";
  61. this->SetError(e.str());
  62. return false;
  63. }
  64. }
  65. // If null/empty CONFIGURATION argument, cmake --build uses 'Debug'
  66. // in the currently implemented multi-configuration global generators...
  67. // so we put this code here to end up with the same default configuration
  68. // as the original 2-arg build_command signature:
  69. //
  70. if (!configuration || !*configuration) {
  71. configuration = getenv("CMAKE_CONFIG_TYPE");
  72. }
  73. if (!configuration || !*configuration) {
  74. configuration = "Release";
  75. }
  76. if (project_name && *project_name) {
  77. this->Makefile->IssueMessage(
  78. cmake::AUTHOR_WARNING,
  79. "Ignoring PROJECT_NAME option because it has no effect.");
  80. }
  81. std::string makecommand =
  82. this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand(
  83. target, configuration, "", this->Makefile->IgnoreErrorsCMP0061());
  84. this->Makefile->AddDefinition(variable, makecommand.c_str());
  85. return true;
  86. }
  87. bool cmBuildCommand::TwoArgsSignature(std::vector<std::string> const& args)
  88. {
  89. if (args.size() < 2) {
  90. this->SetError("called with less than two arguments");
  91. return false;
  92. }
  93. const char* define = args[0].c_str();
  94. const char* cacheValue = this->Makefile->GetDefinition(define);
  95. std::string configType = "Release";
  96. const char* cfg = getenv("CMAKE_CONFIG_TYPE");
  97. if (cfg && *cfg) {
  98. configType = cfg;
  99. }
  100. std::string makecommand =
  101. this->Makefile->GetGlobalGenerator()->GenerateCMakeBuildCommand(
  102. "", configType, "", this->Makefile->IgnoreErrorsCMP0061());
  103. if (cacheValue) {
  104. return true;
  105. }
  106. this->Makefile->AddCacheDefinition(define, makecommand.c_str(),
  107. "Command used to build entire project "
  108. "from the command line.",
  109. cmState::STRING);
  110. return true;
  111. }