cmake/Source/cmIncludeExternalMSProjectCommand.cxx

105 lines
2.9 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
#include "cmIncludeExternalMSProjectCommand.h"
2020-02-01 23:06:01 +01:00
#include "cmExecutionStatus.h"
2017-04-14 19:02:05 +02:00
#ifdef _WIN32
2018-08-09 18:06:22 +02:00
# include "cmGlobalGenerator.h"
# include "cmMakefile.h"
# include "cmStateTypes.h"
# include "cmSystemTools.h"
# include "cmTarget.h"
2019-11-11 23:01:05 +01:00
# include "cmake.h"
2017-04-14 19:02:05 +02:00
#endif
2020-02-01 23:06:01 +01:00
bool cmIncludeExternalMSProjectCommand(std::vector<std::string> const& args,
cmExecutionStatus& status)
{
2016-07-09 11:21:54 +02:00
if (args.size() < 2) {
2020-02-01 23:06:01 +01:00
status.SetError("INCLUDE_EXTERNAL_MSPROJECT called with incorrect "
"number of arguments");
2016-07-09 11:21:54 +02:00
return false;
}
2020-02-01 23:06:01 +01:00
// only compile this for win32 to avoid coverage errors
#ifdef _WIN32
2020-02-01 23:06:01 +01:00
cmMakefile& mf = status.GetMakefile();
if (mf.GetDefinition("WIN32") ||
mf.GetGlobalGenerator()->IsIncludeExternalMSProjectSupported()) {
2016-07-09 11:21:54 +02:00
enum Doing
{
2016-07-09 11:21:54 +02:00
DoingNone,
DoingType,
DoingGuid,
DoingPlatform
};
2012-06-27 20:52:58 +03:00
Doing doing = DoingNone;
std::string customType;
std::string customGuid;
std::string platformMapping;
std::vector<std::string> depends;
2016-07-09 11:21:54 +02:00
for (unsigned int i = 2; i < args.size(); ++i) {
if (args[i] == "TYPE") {
2012-06-27 20:52:58 +03:00
doing = DoingType;
2016-07-09 11:21:54 +02:00
} else if (args[i] == "GUID") {
2012-06-27 20:52:58 +03:00
doing = DoingGuid;
2016-07-09 11:21:54 +02:00
} else if (args[i] == "PLATFORM") {
2012-06-27 20:52:58 +03:00
doing = DoingPlatform;
2016-07-09 11:21:54 +02:00
} 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;
2012-06-27 20:52:58 +03:00
}
doing = DoingNone;
}
2016-07-09 11:21:54 +02:00
}
2012-06-27 20:52:58 +03:00
// Hack together a utility target storing enough information
// to reproduce the target inclusion.
std::string utility_name = args[0];
std::string path = args[1];
cmSystemTools::ConvertToUnixSlashes(path);
2016-07-09 11:21:54 +02:00
if (!customGuid.empty()) {
2012-06-27 20:52:58 +03:00
std::string guidVariable = utility_name + "_GUID_CMAKE";
2021-11-20 13:41:27 +01:00
mf.GetCMakeInstance()->AddCacheEntry(
guidVariable, customGuid, "Stored GUID", cmStateEnums::INTERNAL);
2016-07-09 11:21:54 +02:00
}
2012-06-27 20:52:58 +03:00
// Create a target instance for this utility.
2020-08-30 11:54:41 +02:00
cmTarget* target = mf.AddNewTarget(cmStateEnums::UTILITY, utility_name);
2020-02-01 23:06:01 +01:00
if (mf.GetPropertyAsBool("EXCLUDE_FROM_ALL")) {
2019-11-11 23:01:05 +01:00
target->SetProperty("EXCLUDE_FROM_ALL", "TRUE");
}
2012-06-27 20:52:58 +03:00
2020-08-30 11:54:41 +02:00
target->SetProperty("GENERATOR_FILE_NAME", utility_name);
target->SetProperty("EXTERNAL_MSPROJECT", path);
2012-06-27 20:52:58 +03:00
if (!customType.empty())
2020-08-30 11:54:41 +02:00
target->SetProperty("VS_PROJECT_TYPE", customType);
2012-06-27 20:52:58 +03:00
if (!platformMapping.empty())
2020-08-30 11:54:41 +02:00
target->SetProperty("VS_PLATFORM_MAPPING", platformMapping);
2012-06-27 20:52:58 +03:00
2018-01-26 17:06:56 +01:00
for (std::string const& d : depends) {
2020-08-30 11:54:41 +02:00
target->AddUtility(d, false);
}
2016-07-09 11:21:54 +02:00
}
#endif
return true;
}