1
0

cmIncludeExternalMSProjectCommand.cxx 2.8 KB

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