cmIncludeExternalMSProjectCommand.cxx 3.0 KB

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