1
0

cmIncludeExternalMSProjectCommand.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. #include "cmExecutionStatus.h"
  5. #ifdef _WIN32
  6. # include "cmGlobalGenerator.h"
  7. # include "cmMakefile.h"
  8. # include "cmStateTypes.h"
  9. # include "cmSystemTools.h"
  10. # include "cmTarget.h"
  11. # include "cmake.h"
  12. #endif
  13. bool cmIncludeExternalMSProjectCommand(std::vector<std::string> const& args,
  14. cmExecutionStatus& status)
  15. {
  16. if (args.size() < 2) {
  17. status.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. cmMakefile& mf = status.GetMakefile();
  24. if (mf.GetDefinition("WIN32") ||
  25. mf.GetGlobalGenerator()->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. mf.GetCMakeInstance()->AddCacheEntry(guidVariable.c_str(),
  71. customGuid.c_str(), "Stored GUID",
  72. cmStateEnums::INTERNAL);
  73. }
  74. // Create a target instance for this utility.
  75. cmTarget* target =
  76. mf.AddNewTarget(cmStateEnums::UTILITY, utility_name.c_str());
  77. if (mf.GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
  78. target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
  79. }
  80. target->SetProperty("GENERATOR_FILE_NAME", utility_name.c_str());
  81. target->SetProperty("EXTERNAL_MSPROJECT", path.c_str());
  82. if (!customType.empty())
  83. target->SetProperty("VS_PROJECT_TYPE", customType.c_str());
  84. if (!platformMapping.empty())
  85. target->SetProperty("VS_PLATFORM_MAPPING", platformMapping.c_str());
  86. for (std::string const& d : depends) {
  87. target->AddUtility(d.c_str());
  88. }
  89. }
  90. #endif
  91. return true;
  92. }