2017-01-18 14:20:09 +00:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
|
|
|
#include "cmXCodeScheme.h"
|
|
|
|
|
|
|
|
#include <iomanip>
|
2017-02-24 16:31:24 +00:00
|
|
|
#include <iostream>
|
2017-01-18 14:20:09 +00:00
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include "cmGeneratedFileStream.h"
|
|
|
|
#include "cmGeneratorTarget.h"
|
|
|
|
#include "cmXMLSafe.h"
|
|
|
|
|
2017-06-28 20:21:01 +00:00
|
|
|
cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj, const TestObjects& tests,
|
2017-01-18 14:20:09 +00:00
|
|
|
const std::vector<std::string>& configList,
|
|
|
|
unsigned int xcVersion)
|
2017-02-24 17:47:58 +00:00
|
|
|
: Target(xcObj)
|
2017-06-28 20:21:01 +00:00
|
|
|
, Tests(tests)
|
2017-02-24 17:47:58 +00:00
|
|
|
, TargetName(xcObj->GetTarget()->GetName())
|
2017-01-18 14:20:09 +00:00
|
|
|
, ConfigList(configList)
|
|
|
|
, XcodeVersion(xcVersion)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmXCodeScheme::WriteXCodeSharedScheme(const std::string& xcProjDir,
|
2017-02-24 16:31:24 +00:00
|
|
|
const std::string& container)
|
2017-01-18 14:20:09 +00:00
|
|
|
{
|
|
|
|
// Create shared scheme sub-directory tree
|
|
|
|
//
|
|
|
|
std::string xcodeSchemeDir = xcProjDir;
|
|
|
|
xcodeSchemeDir += "/xcshareddata/xcschemes";
|
|
|
|
cmSystemTools::MakeDirectory(xcodeSchemeDir.c_str());
|
|
|
|
|
|
|
|
std::string xcodeSchemeFile = xcodeSchemeDir;
|
|
|
|
xcodeSchemeFile += "/";
|
|
|
|
xcodeSchemeFile += this->TargetName;
|
|
|
|
xcodeSchemeFile += ".xcscheme";
|
|
|
|
|
|
|
|
cmGeneratedFileStream fout(xcodeSchemeFile.c_str());
|
|
|
|
fout.SetCopyIfDifferent(true);
|
|
|
|
if (!fout) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-24 16:31:24 +00:00
|
|
|
WriteXCodeXCScheme(fout, container);
|
2017-01-18 14:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void cmXCodeScheme::WriteXCodeXCScheme(std::ostream& fout,
|
2017-02-24 16:31:24 +00:00
|
|
|
const std::string& container)
|
2017-01-18 14:20:09 +00:00
|
|
|
{
|
|
|
|
cmXMLWriter xout(fout);
|
2017-02-24 12:04:21 +00:00
|
|
|
xout.SetIndentationElement(std::string(3, ' '));
|
2017-01-18 14:20:09 +00:00
|
|
|
xout.StartDocument();
|
|
|
|
|
|
|
|
xout.StartElement("Scheme");
|
|
|
|
xout.BreakAttributes();
|
|
|
|
xout.Attribute("LastUpgradeVersion", WriteVersionString());
|
|
|
|
xout.Attribute("version", "1.3");
|
|
|
|
|
2017-02-24 16:31:24 +00:00
|
|
|
WriteBuildAction(xout, container);
|
2017-06-28 20:21:01 +00:00
|
|
|
WriteTestAction(xout, FindConfiguration("Debug"), container);
|
2017-02-24 16:31:24 +00:00
|
|
|
WriteLaunchAction(xout, FindConfiguration("Debug"), container);
|
2017-01-18 14:20:09 +00:00
|
|
|
WriteProfileAction(xout, FindConfiguration("Release"));
|
|
|
|
WriteAnalyzeAction(xout, FindConfiguration("Debug"));
|
|
|
|
WriteArchiveAction(xout, FindConfiguration("Release"));
|
|
|
|
|
|
|
|
xout.EndElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout,
|
2017-02-24 16:31:24 +00:00
|
|
|
const std::string& container)
|
2017-01-18 14:20:09 +00:00
|
|
|
{
|
|
|
|
xout.StartElement("BuildAction");
|
|
|
|
xout.BreakAttributes();
|
|
|
|
xout.Attribute("parallelizeBuildables", "YES");
|
|
|
|
xout.Attribute("buildImplicitDependencies", "YES");
|
|
|
|
|
|
|
|
xout.StartElement("BuildActionEntries");
|
|
|
|
xout.StartElement("BuildActionEntry");
|
|
|
|
xout.BreakAttributes();
|
|
|
|
xout.Attribute("buildForTesting", "YES");
|
|
|
|
xout.Attribute("buildForRunning", "YES");
|
|
|
|
xout.Attribute("buildForProfiling", "YES");
|
|
|
|
xout.Attribute("buildForArchiving", "YES");
|
|
|
|
xout.Attribute("buildForAnalyzing", "YES");
|
|
|
|
|
2017-06-28 20:04:31 +00:00
|
|
|
WriteBuildableReference(xout, this->Target, container);
|
2017-01-18 14:20:09 +00:00
|
|
|
|
|
|
|
xout.EndElement(); // BuildActionEntry
|
|
|
|
xout.EndElement(); // BuildActionEntries
|
|
|
|
xout.EndElement(); // BuildAction
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout,
|
2017-06-28 20:21:01 +00:00
|
|
|
std::string configuration,
|
|
|
|
const std::string& container)
|
2017-01-18 14:20:09 +00:00
|
|
|
{
|
|
|
|
xout.StartElement("TestAction");
|
|
|
|
xout.BreakAttributes();
|
|
|
|
xout.Attribute("buildConfiguration", configuration);
|
|
|
|
xout.Attribute("selectedDebuggerIdentifier",
|
|
|
|
"Xcode.DebuggerFoundation.Debugger.LLDB");
|
|
|
|
xout.Attribute("selectedLauncherIdentifier",
|
|
|
|
"Xcode.DebuggerFoundation.Launcher.LLDB");
|
|
|
|
xout.Attribute("shouldUseLaunchSchemeArgsEnv", "YES");
|
|
|
|
|
|
|
|
xout.StartElement("Testables");
|
2017-06-28 20:21:01 +00:00
|
|
|
for (TestObjects::const_iterator it = this->Tests.begin();
|
|
|
|
it != this->Tests.end(); ++it) {
|
|
|
|
xout.StartElement("TestableReference");
|
|
|
|
xout.BreakAttributes();
|
|
|
|
xout.Attribute("skipped", "NO");
|
|
|
|
WriteBuildableReference(xout, *it, container);
|
|
|
|
xout.EndElement(); // TestableReference
|
|
|
|
}
|
2017-01-18 14:20:09 +00:00
|
|
|
xout.EndElement();
|
|
|
|
|
2017-06-28 20:21:01 +00:00
|
|
|
if (IsTestable()) {
|
|
|
|
xout.StartElement("MacroExpansion");
|
|
|
|
WriteBuildableReference(xout, this->Target, container);
|
|
|
|
xout.EndElement(); // MacroExpansion
|
|
|
|
}
|
|
|
|
|
2017-01-18 14:20:09 +00:00
|
|
|
xout.StartElement("AdditionalOptions");
|
|
|
|
xout.EndElement();
|
|
|
|
|
|
|
|
xout.EndElement(); // TestAction
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
|
|
|
|
std::string configuration,
|
2017-02-24 16:31:24 +00:00
|
|
|
const std::string& container)
|
2017-01-18 14:20:09 +00:00
|
|
|
{
|
|
|
|
xout.StartElement("LaunchAction");
|
|
|
|
xout.BreakAttributes();
|
|
|
|
xout.Attribute("buildConfiguration", configuration);
|
|
|
|
xout.Attribute("selectedDebuggerIdentifier",
|
|
|
|
"Xcode.DebuggerFoundation.Debugger.LLDB");
|
|
|
|
xout.Attribute("selectedLauncherIdentifier",
|
|
|
|
"Xcode.DebuggerFoundation.Launcher.LLDB");
|
|
|
|
xout.Attribute("launchStyle", "0");
|
|
|
|
xout.Attribute("useCustomWorkingDirectory", "NO");
|
|
|
|
xout.Attribute("ignoresPersistentStateOnLaunch", "NO");
|
|
|
|
xout.Attribute("debugDocumentVersioning", "YES");
|
|
|
|
xout.Attribute("debugServiceExtension", "internal");
|
|
|
|
xout.Attribute("allowLocationSimulation", "YES");
|
|
|
|
|
2017-02-24 17:47:58 +00:00
|
|
|
if (IsExecutable(this->Target)) {
|
|
|
|
xout.StartElement("BuildableProductRunnable");
|
|
|
|
xout.BreakAttributes();
|
|
|
|
xout.Attribute("runnableDebuggingMode", "0");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
xout.StartElement("MacroExpansion");
|
|
|
|
}
|
2017-01-18 14:20:09 +00:00
|
|
|
|
2017-06-28 20:04:31 +00:00
|
|
|
WriteBuildableReference(xout, this->Target, container);
|
2017-01-18 14:20:09 +00:00
|
|
|
|
|
|
|
xout.EndElement(); // MacroExpansion
|
|
|
|
|
|
|
|
xout.StartElement("AdditionalOptions");
|
|
|
|
xout.EndElement();
|
|
|
|
|
|
|
|
xout.EndElement(); // LaunchAction
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmXCodeScheme::WriteProfileAction(cmXMLWriter& xout,
|
|
|
|
std::string configuration)
|
|
|
|
{
|
|
|
|
xout.StartElement("ProfileAction");
|
|
|
|
xout.BreakAttributes();
|
|
|
|
xout.Attribute("buildConfiguration", configuration);
|
|
|
|
xout.Attribute("shouldUseLaunchSchemeArgsEnv", "YES");
|
|
|
|
xout.Attribute("savedToolIdentifier", "");
|
|
|
|
xout.Attribute("useCustomWorkingDirectory", "NO");
|
|
|
|
xout.Attribute("debugDocumentVersioning", "YES");
|
|
|
|
xout.EndElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmXCodeScheme::WriteAnalyzeAction(cmXMLWriter& xout,
|
|
|
|
std::string configuration)
|
|
|
|
{
|
|
|
|
xout.StartElement("AnalyzeAction");
|
|
|
|
xout.BreakAttributes();
|
|
|
|
xout.Attribute("buildConfiguration", configuration);
|
|
|
|
xout.EndElement();
|
|
|
|
}
|
|
|
|
|
|
|
|
void cmXCodeScheme::WriteArchiveAction(cmXMLWriter& xout,
|
|
|
|
std::string configuration)
|
|
|
|
{
|
|
|
|
xout.StartElement("ArchiveAction");
|
|
|
|
xout.BreakAttributes();
|
|
|
|
xout.Attribute("buildConfiguration", configuration);
|
|
|
|
xout.Attribute("revealArchiveInOrganizer", "YES");
|
|
|
|
xout.EndElement();
|
|
|
|
}
|
|
|
|
|
2017-06-28 20:04:31 +00:00
|
|
|
void cmXCodeScheme::WriteBuildableReference(cmXMLWriter& xout,
|
|
|
|
const cmXCodeObject* xcObj,
|
|
|
|
const std::string& container)
|
|
|
|
{
|
|
|
|
xout.StartElement("BuildableReference");
|
|
|
|
xout.BreakAttributes();
|
|
|
|
xout.Attribute("BuildableIdentifier", "primary");
|
|
|
|
xout.Attribute("BlueprintIdentifier", xcObj->GetId());
|
|
|
|
xout.Attribute("BuildableName", xcObj->GetTarget()->GetFullName());
|
|
|
|
xout.Attribute("BlueprintName", xcObj->GetTarget()->GetName());
|
|
|
|
xout.Attribute("ReferencedContainer", "container:" + container);
|
|
|
|
xout.EndElement();
|
|
|
|
}
|
|
|
|
|
2017-01-18 14:20:09 +00:00
|
|
|
std::string cmXCodeScheme::WriteVersionString()
|
|
|
|
{
|
|
|
|
std::ostringstream v;
|
|
|
|
v << std::setfill('0') << std::setw(4) << this->XcodeVersion * 10;
|
|
|
|
return v.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string cmXCodeScheme::FindConfiguration(const std::string& name)
|
|
|
|
{
|
|
|
|
// Try to find the desired configuration by name,
|
|
|
|
// and if it's not found return first from the list
|
|
|
|
//
|
|
|
|
if (std::find(this->ConfigList.begin(), this->ConfigList.end(), name) ==
|
|
|
|
this->ConfigList.end() &&
|
2017-09-20 20:50:20 +00:00
|
|
|
!this->ConfigList.empty())
|
2017-01-18 14:20:09 +00:00
|
|
|
return this->ConfigList[0];
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
2017-02-24 17:47:58 +00:00
|
|
|
|
2017-06-28 20:21:01 +00:00
|
|
|
bool cmXCodeScheme::IsTestable() const
|
|
|
|
{
|
|
|
|
return !this->Tests.empty() || IsExecutable(this->Target);
|
|
|
|
}
|
|
|
|
|
2017-02-24 17:47:58 +00:00
|
|
|
bool cmXCodeScheme::IsExecutable(const cmXCodeObject* target)
|
|
|
|
{
|
|
|
|
cmGeneratorTarget* gt = target->GetTarget();
|
|
|
|
if (!gt) {
|
|
|
|
cmSystemTools::Error("Error no target on xobject\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gt->GetType() == cmStateEnums::EXECUTABLE;
|
|
|
|
}
|