cmIncludeExternalMSProjectCommand.cxx 2.98 KB
Newer Older
1 2
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
3 4
#include "cmIncludeExternalMSProjectCommand.h"

5
#ifdef _WIN32
6 7 8 9 10
#  include "cmGlobalGenerator.h"
#  include "cmMakefile.h"
#  include "cmStateTypes.h"
#  include "cmSystemTools.h"
#  include "cmTarget.h"
11
#  include "cmake.h"
12 13 14 15
#endif

class cmExecutionStatus;

16
// cmIncludeExternalMSProjectCommand
17 18
bool cmIncludeExternalMSProjectCommand::InitialPass(
  std::vector<std::string> const& args, cmExecutionStatus&)
19
{
20 21 22 23
  if (args.size() < 2) {
    this->SetError("INCLUDE_EXTERNAL_MSPROJECT called with incorrect "
                   "number of arguments");
    return false;
24
  }
Bill Hoffman's avatar
Bill Hoffman committed
25 26
// only compile this for win32 to avoid coverage errors
#ifdef _WIN32
27 28 29
  if (this->Makefile->GetDefinition("WIN32") ||
      this->Makefile->GetGlobalGenerator()
        ->IsIncludeExternalMSProjectSupported()) {
30
    enum Doing
Bill Hoffman's avatar
Bill Hoffman committed
31
    {
32 33 34 35 36
      DoingNone,
      DoingType,
      DoingGuid,
      DoingPlatform
    };
37 38 39 40 41 42 43 44

    Doing doing = DoingNone;

    std::string customType;
    std::string customGuid;
    std::string platformMapping;

    std::vector<std::string> depends;
45 46
    for (unsigned int i = 2; i < args.size(); ++i) {
      if (args[i] == "TYPE") {
47
        doing = DoingType;
48
      } else if (args[i] == "GUID") {
49
        doing = DoingGuid;
50
      } else if (args[i] == "PLATFORM") {
51
        doing = DoingPlatform;
52 53 54 55 56 57 58 59 60 61 62 63 64 65
      } else {
        switch (doing) {
          case DoingNone:
            depends.push_back(args[i]);
            break;
          case DoingType:
            customType = args[i];
            break;
          case DoingGuid:
            customGuid = args[i];
            break;
          case DoingPlatform:
            platformMapping = args[i];
            break;
66 67 68
        }
        doing = DoingNone;
      }
69
    }
70 71 72 73 74

    // Hack together a utility target storing enough information
    // to reproduce the target inclusion.
    std::string utility_name = args[0];

75 76
    std::string path = args[1];
    cmSystemTools::ConvertToUnixSlashes(path);
77

78
    if (!customGuid.empty()) {
79
      std::string guidVariable = utility_name + "_GUID_CMAKE";
80
      this->Makefile->GetCMakeInstance()->AddCacheEntry(
81
        guidVariable.c_str(), customGuid.c_str(), "Stored GUID",
82
        cmStateEnums::INTERNAL);
83
    }
84

85
    // Create a target instance for this utility.
86 87
    cmTarget* target = this->Makefile->AddNewTarget(cmStateEnums::UTILITY,
                                                    utility_name.c_str());
88 89

    target->SetProperty("GENERATOR_FILE_NAME", utility_name.c_str());
90
    target->SetProperty("EXTERNAL_MSPROJECT", path.c_str());
91 92 93
    target->SetProperty("EXCLUDE_FROM_ALL", "FALSE");

    if (!customType.empty())
94
      target->SetProperty("VS_PROJECT_TYPE", customType.c_str());
95
    if (!platformMapping.empty())
96
      target->SetProperty("VS_PLATFORM_MAPPING", platformMapping.c_str());
97

98 99
    for (std::string const& d : depends) {
      target->AddUtility(d.c_str());
Bill Hoffman's avatar
Bill Hoffman committed
100
    }
101
  }
Bill Hoffman's avatar
Bill Hoffman committed
102
#endif
103 104
  return true;
}