cmIncludeExternalMSProjectCommand.cxx 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmIncludeExternalMSProjectCommand.h"
  4. #ifdef _WIN32
  5. #include "cmSystemTools.h"
  6. #endif
  7. class cmExecutionStatus;
  8. // cmIncludeExternalMSProjectCommand
  9. bool cmIncludeExternalMSProjectCommand::InitialPass(
  10. std::vector<std::string> const& args, cmExecutionStatus&)
  11. {
  12. if (args.size() < 2) {
  13. this->SetError("INCLUDE_EXTERNAL_MSPROJECT called with incorrect "
  14. "number of arguments");
  15. return false;
  16. }
  17. // only compile this for win32 to avoid coverage errors
  18. #ifdef _WIN32
  19. if (this->Makefile->GetDefinition("WIN32")) {
  20. enum Doing
  21. {
  22. DoingNone,
  23. DoingType,
  24. DoingGuid,
  25. DoingPlatform
  26. };
  27. Doing doing = DoingNone;
  28. std::string customType;
  29. std::string customGuid;
  30. std::string platformMapping;
  31. std::vector<std::string> depends;
  32. for (unsigned int i = 2; i < args.size(); ++i) {
  33. if (args[i] == "TYPE") {
  34. doing = DoingType;
  35. } else if (args[i] == "GUID") {
  36. doing = DoingGuid;
  37. } else if (args[i] == "PLATFORM") {
  38. doing = DoingPlatform;
  39. } else {
  40. switch (doing) {
  41. case DoingNone:
  42. depends.push_back(args[i]);
  43. break;
  44. case DoingType:
  45. customType = args[i];
  46. break;
  47. case DoingGuid:
  48. customGuid = args[i];
  49. break;
  50. case DoingPlatform:
  51. platformMapping = args[i];
  52. break;
  53. }
  54. doing = DoingNone;
  55. }
  56. }
  57. // Hack together a utility target storing enough information
  58. // to reproduce the target inclusion.
  59. std::string utility_name = args[0];
  60. std::string path = args[1];
  61. cmSystemTools::ConvertToUnixSlashes(path);
  62. if (!customGuid.empty()) {
  63. std::string guidVariable = utility_name + "_GUID_CMAKE";
  64. this->Makefile->GetCMakeInstance()->AddCacheEntry(
  65. guidVariable.c_str(), customGuid.c_str(), "Stored GUID",
  66. cmStateEnums::INTERNAL);
  67. }
  68. // Create a target instance for this utility.
  69. cmTarget* target = this->Makefile->AddNewTarget(cmStateEnums::UTILITY,
  70. utility_name.c_str());
  71. target->SetProperty("GENERATOR_FILE_NAME", utility_name.c_str());
  72. target->SetProperty("EXTERNAL_MSPROJECT", path.c_str());
  73. target->SetProperty("EXCLUDE_FROM_ALL", "FALSE");
  74. if (!customType.empty())
  75. target->SetProperty("VS_PROJECT_TYPE", customType.c_str());
  76. if (!platformMapping.empty())
  77. target->SetProperty("VS_PLATFORM_MAPPING", platformMapping.c_str());
  78. for (std::vector<std::string>::const_iterator it = depends.begin();
  79. it != depends.end(); ++it) {
  80. target->AddUtility(it->c_str());
  81. }
  82. }
  83. #endif
  84. return true;
  85. }