Coverage Report

Created: 2026-02-09 06:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/CMake/Source/cmIncludeExternalMSProjectCommand.cxx
Line
Count
Source
1
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
2
   file LICENSE.rst or https://cmake.org/licensing for details.  */
3
#include "cmIncludeExternalMSProjectCommand.h"
4
5
#include "cmExecutionStatus.h"
6
7
#ifdef _WIN32
8
#  include "cmGlobalGenerator.h"
9
#  include "cmMakefile.h"
10
#  include "cmStateTypes.h"
11
#  include "cmSystemTools.h"
12
#  include "cmTarget.h"
13
#  include "cmake.h"
14
#endif
15
16
bool cmIncludeExternalMSProjectCommand(std::vector<std::string> const& args,
17
                                       cmExecutionStatus& status)
18
0
{
19
0
  if (args.size() < 2) {
20
0
    status.SetError("INCLUDE_EXTERNAL_MSPROJECT called with incorrect "
21
0
                    "number of arguments");
22
0
    return false;
23
0
  }
24
25
// only compile this for win32 to avoid coverage errors
26
#ifdef _WIN32
27
  cmMakefile& mf = status.GetMakefile();
28
  if (mf.GetDefinition("WIN32") ||
29
      mf.GetGlobalGenerator()->IsIncludeExternalMSProjectSupported()) {
30
    enum Doing
31
    {
32
      DoingNone,
33
      DoingType,
34
      DoingGuid,
35
      DoingPlatform
36
    };
37
38
    Doing doing = DoingNone;
39
40
    std::string customType;
41
    std::string customGuid;
42
    std::string platformMapping;
43
44
    std::vector<std::string> depends;
45
    for (unsigned int i = 2; i < args.size(); ++i) {
46
      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
      } else {
53
        switch (doing) {
54
          case DoingNone:
55
            depends.push_back(args[i]);
56
            break;
57
          case DoingType:
58
            customType = args[i];
59
            break;
60
          case DoingGuid:
61
            customGuid = args[i];
62
            break;
63
          case DoingPlatform:
64
            platformMapping = args[i];
65
            break;
66
        }
67
        doing = DoingNone;
68
      }
69
    }
70
71
    // Hack together a utility target storing enough information
72
    // to reproduce the target inclusion.
73
    std::string utility_name = args[0];
74
75
    std::string path = args[1];
76
    cmSystemTools::ConvertToUnixSlashes(path);
77
78
    if (!customGuid.empty()) {
79
      std::string guidVariable = utility_name + "_GUID_CMAKE";
80
      mf.GetCMakeInstance()->AddCacheEntry(
81
        guidVariable, customGuid, "Stored GUID", cmStateEnums::INTERNAL);
82
    }
83
84
    // Create a target instance for this utility.
85
    cmTarget* target = mf.AddNewTarget(cmStateEnums::UTILITY, utility_name);
86
    if (mf.GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
87
      target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
88
    }
89
90
    target->SetProperty("GENERATOR_FILE_NAME", utility_name);
91
    target->SetProperty("EXTERNAL_MSPROJECT", path);
92
93
    if (!customType.empty())
94
      target->SetProperty("VS_PROJECT_TYPE", customType);
95
    if (!platformMapping.empty())
96
      target->SetProperty("VS_PLATFORM_MAPPING", platformMapping);
97
98
    for (std::string const& d : depends) {
99
      target->AddUtility(d, false);
100
    }
101
  }
102
#endif
103
0
  return true;
104
0
}