cmake/Source/cmLocalVisualStudio10Generator.cxx

135 lines
3.8 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. */
2009-10-04 10:30:41 +03:00
#include "cmLocalVisualStudio10Generator.h"
2016-07-09 11:21:54 +02:00
2016-10-30 18:24:19 +01:00
#include "cmGeneratorTarget.h"
2016-07-09 11:21:54 +02:00
#include "cmGlobalVisualStudio10Generator.h"
2009-10-04 10:30:41 +03:00
#include "cmMakefile.h"
#include "cmVisualStudio10TargetGenerator.h"
#include "cmXMLParser.h"
2016-10-30 18:24:19 +01:00
2017-07-20 19:35:53 +02:00
#include "cm_expat.h"
2016-07-09 11:21:54 +02:00
2009-10-04 10:30:41 +03:00
class cmVS10XMLParser : public cmXMLParser
{
2016-07-09 11:21:54 +02:00
public:
virtual void EndElement(const std::string& /* name */) {}
2009-10-04 10:30:41 +03:00
virtual void CharacterDataHandler(const char* data, int length)
2016-07-09 11:21:54 +02:00
{
if (this->DoGUID) {
2018-01-26 17:06:56 +01:00
if (data[0] == '{') {
// remove surrounding curly brackets
this->GUID.assign(data + 1, length - 2);
} else {
this->GUID.assign(data, length);
}
2016-07-09 11:21:54 +02:00
this->DoGUID = false;
2009-10-04 10:30:41 +03:00
}
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
virtual void StartElement(const std::string& name, const char**)
2016-07-09 11:21:54 +02:00
{
// once the GUID is found do nothing
if (!this->GUID.empty()) {
return;
}
if ("ProjectGUID" == name || "ProjectGuid" == name) {
this->DoGUID = true;
2009-10-04 10:30:41 +03:00
}
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
int InitializeParser()
2016-07-09 11:21:54 +02:00
{
this->DoGUID = false;
int ret = cmXMLParser::InitializeParser();
if (ret == 0) {
return ret;
2009-10-04 10:30:41 +03:00
}
2016-07-09 11:21:54 +02:00
// visual studio projects have a strange encoding, but it is
// really utf-8
XML_SetEncoding(static_cast<XML_Parser>(this->Parser), "utf-8");
return 1;
}
2009-10-04 10:30:41 +03:00
std::string GUID;
bool DoGUID;
};
2016-07-09 11:21:54 +02:00
cmLocalVisualStudio10Generator::cmLocalVisualStudio10Generator(
cmGlobalGenerator* gg, cmMakefile* mf)
: cmLocalVisualStudio7Generator(gg, mf)
2009-10-04 10:30:41 +03:00
{
}
cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator()
{
}
2018-08-09 18:06:22 +02:00
void cmLocalVisualStudio10Generator::GenerateTargetsDepthFirst(
cmGeneratorTarget* target, std::vector<cmGeneratorTarget*>& remaining)
{
if (target->GetType() == cmStateEnums::INTERFACE_LIBRARY) {
return;
}
// Find this target in the list of remaining targets.
auto it = std::find(remaining.begin(), remaining.end(), target);
if (it == remaining.end()) {
// This target was already handled.
return;
}
// Remove this target from the list of remaining targets because
// we are handling it now.
*it = nullptr;
auto& deps = this->GlobalGenerator->GetTargetDirectDepends(target);
for (auto& d : deps) {
// FIXME: Revise CreateSingleVCProj so we do not have to drop `const` here.
auto dependee = const_cast<cmGeneratorTarget*>(&*d);
GenerateTargetsDepthFirst(dependee, remaining);
// Take the union of visited source files of custom commands
auto visited = GetSourcesVisited(dependee);
GetSourcesVisited(target).insert(visited.begin(), visited.end());
}
if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
->TargetIsFortranOnly(target)) {
this->CreateSingleVCProj(target->GetName(), target);
} else {
cmVisualStudio10TargetGenerator tg(
target,
static_cast<cmGlobalVisualStudio10Generator*>(
this->GetGlobalGenerator()));
tg.Generate();
}
}
2009-10-04 10:30:41 +03:00
void cmLocalVisualStudio10Generator::Generate()
{
2018-08-09 18:06:22 +02:00
std::vector<cmGeneratorTarget*> remaining = this->GetGeneratorTargets();
for (auto& t : remaining) {
if (t) {
GenerateTargetsDepthFirst(t, remaining);
2009-10-04 10:30:41 +03:00
}
2016-07-09 11:21:54 +02:00
}
2009-10-04 10:30:41 +03:00
this->WriteStampFiles();
}
2016-07-09 11:21:54 +02:00
void cmLocalVisualStudio10Generator::ReadAndStoreExternalGUID(
const std::string& name, const char* path)
2009-10-04 10:30:41 +03:00
{
cmVS10XMLParser parser;
2013-03-16 19:13:01 +02:00
parser.ParseFile(path);
2012-06-27 20:52:58 +03:00
2015-11-17 17:22:37 +01:00
// if we can not find a GUID then we will generate one later
2016-07-09 11:21:54 +02:00
if (parser.GUID.empty()) {
2012-06-27 20:52:58 +03:00
return;
2016-07-09 11:21:54 +02:00
}
2012-06-27 20:52:58 +03:00
2009-10-04 10:30:41 +03:00
std::string guidStoreName = name;
guidStoreName += "_GUID_CMAKE";
// save the GUID in the cache
2016-07-09 11:21:54 +02:00
this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
guidStoreName.c_str(), parser.GUID.c_str(), "Stored GUID",
2017-04-14 19:02:05 +02:00
cmStateEnums::INTERNAL);
2009-10-04 10:30:41 +03:00
}
2011-01-16 11:35:12 +01:00
2011-06-19 15:41:06 +03:00
const char* cmLocalVisualStudio10Generator::ReportErrorLabel() const
2011-01-16 11:35:12 +01:00
{
2011-06-19 15:41:06 +03:00
return ":VCEnd";
2011-01-16 11:35:12 +01:00
}