cmake/Source/cmLocalVisualStudio10Generator.cxx

103 lines
2.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
2020-08-30 11:54:41 +02:00
#include <cm3p/expat.h>
2022-03-29 21:10:50 +02:00
#include "cmGlobalGenerator.h"
2016-07-09 11:21:54 +02:00
#include "cmGlobalVisualStudio10Generator.h"
2022-03-29 21:10:50 +02:00
#include "cmGlobalVisualStudioGenerator.h"
#include "cmStateTypes.h"
#include "cmStringAlgorithms.h"
2009-10-04 10:30:41 +03:00
#include "cmVisualStudio10TargetGenerator.h"
#include "cmXMLParser.h"
2019-11-11 23:01:05 +01:00
#include "cmake.h"
2016-10-30 18:24:19 +01:00
2022-03-29 21:10:50 +02:00
class cmGeneratorTarget;
2009-10-04 10:30:41 +03:00
class cmVS10XMLParser : public cmXMLParser
{
2016-07-09 11:21:54 +02:00
public:
2023-05-23 16:38:00 +02:00
void EndElement(const std::string& /* name */) override {}
void CharacterDataHandler(const char* data, int length) override
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
}
2023-05-23 16:38:00 +02:00
void StartElement(const std::string& name, const char**) override
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
}
2023-05-23 16:38:00 +02:00
int InitializeParser() override
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
{
}
2023-05-23 16:38:00 +02:00
cmLocalVisualStudio10Generator::~cmLocalVisualStudio10Generator() = default;
2009-10-04 10:30:41 +03:00
2021-09-14 00:13:48 +02:00
void cmLocalVisualStudio10Generator::GenerateTarget(cmGeneratorTarget* target)
2018-08-09 18:06:22 +02:00
{
if (static_cast<cmGlobalVisualStudioGenerator*>(this->GlobalGenerator)
->TargetIsFortranOnly(target)) {
2021-09-14 00:13:48 +02:00
this->cmLocalVisualStudio7Generator::GenerateTarget(target);
2018-08-09 18:06:22 +02:00
} else {
cmVisualStudio10TargetGenerator tg(
target,
static_cast<cmGlobalVisualStudio10Generator*>(
this->GetGlobalGenerator()));
tg.Generate();
}
}
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
2020-02-01 23:06:01 +01:00
std::string guidStoreName = cmStrCat(name, "_GUID_CMAKE");
2009-10-04 10:30:41 +03:00
// save the GUID in the cache
2016-07-09 11:21:54 +02:00
this->GlobalGenerator->GetCMakeInstance()->AddCacheEntry(
2020-08-30 11:54:41 +02:00
guidStoreName, parser.GUID.c_str(), "Stored GUID", 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
}