cmIncludeExternalMSProjectCommand.cxx 2.9 KB

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