Merge topic 'xcode-enhance-schemes'

54a48c67 Xcode: Use proper buildable name for schema
f4977d05 Xcode: Select executable target for execution in schema
7202db5d Xcode: Fix schema container location calculation
59950821 Xcode: Do not autocreate schemes
6a54d28e Xcode: Use proper indentation for schemes
This commit is contained in:
Brad King
2017-03-02 09:25:54 -05:00
committed by CMake Topic Stage
6 changed files with 92 additions and 24 deletions

View File

@@ -3344,7 +3344,8 @@ void cmGlobalXCodeGenerator::OutputXCodeProject(
if (this->GetCMakeInstance()->GetState()->GetGlobalPropertyAsBool(
"XCODE_GENERATE_SCHEME") &&
this->XcodeVersion >= 70) {
this->OutputXCodeSharedSchemes(xcodeDir, root);
this->OutputXCodeSharedSchemes(xcodeDir);
this->OutputXCodeWorkspaceSettings(xcodeDir);
}
this->ClearXCodeObjects();
@@ -3356,7 +3357,7 @@ void cmGlobalXCodeGenerator::OutputXCodeProject(
}
void cmGlobalXCodeGenerator::OutputXCodeSharedSchemes(
const std::string& xcProjDir, cmLocalGenerator* root)
const std::string& xcProjDir)
{
for (std::vector<cmXCodeObject*>::const_iterator i =
this->XCodeObjects.begin();
@@ -3368,11 +3369,41 @@ void cmGlobalXCodeGenerator::OutputXCodeSharedSchemes(
cmXCodeScheme schm(obj, this->CurrentConfigurationTypes,
this->XcodeVersion);
schm.WriteXCodeSharedScheme(xcProjDir,
root->GetCurrentSourceDirectory());
this->RelativeToSource(xcProjDir.c_str()));
}
}
}
void cmGlobalXCodeGenerator::OutputXCodeWorkspaceSettings(
const std::string& xcProjDir)
{
std::string xcodeSharedDataDir = xcProjDir;
xcodeSharedDataDir += "/project.xcworkspace/xcshareddata";
cmSystemTools::MakeDirectory(xcodeSharedDataDir);
std::string workspaceSettingsFile = xcodeSharedDataDir;
workspaceSettingsFile += "/WorkspaceSettings.xcsettings";
cmGeneratedFileStream fout(workspaceSettingsFile.c_str());
fout.SetCopyIfDifferent(true);
if (!fout) {
return;
}
cmXMLWriter xout(fout);
xout.StartDocument();
xout.Doctype("plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\""
"\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\"");
xout.StartElement("plist");
xout.Attribute("version", "1.0");
xout.StartElement("dict");
xout.Element("key", "IDEWorkspaceSharedSettings_AutocreateContextsIfNeeded");
xout.Element("false");
xout.EndElement(); // dict
xout.EndElement(); // plist
xout.EndDocument();
}
void cmGlobalXCodeGenerator::WriteXCodePBXProj(std::ostream& fout,
cmLocalGenerator*,
std::vector<cmLocalGenerator*>&)

View File

@@ -166,8 +166,8 @@ private:
void OutputXCodeProject(cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
// Write shared scheme files for all the native targets
void OutputXCodeSharedSchemes(const std::string& xcProjDir,
cmLocalGenerator* root);
void OutputXCodeSharedSchemes(const std::string& xcProjDir);
void OutputXCodeWorkspaceSettings(const std::string& xcProjDir);
void WriteXCodePBXProj(std::ostream& fout, cmLocalGenerator* root,
std::vector<cmLocalGenerator*>& generators);
cmXCodeObject* CreateXCodeFileReferenceFromPath(const std::string& fullpath,

View File

@@ -3,6 +3,7 @@
#include "cmXCodeScheme.h"
#include <iomanip>
#include <iostream>
#include <sstream>
#include "cmGeneratedFileStream.h"
@@ -12,7 +13,9 @@
cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj,
const std::vector<std::string>& configList,
unsigned int xcVersion)
: TargetName(xcObj->GetTarget()->GetName())
: Target(xcObj)
, TargetName(xcObj->GetTarget()->GetName())
, BuildableName(xcObj->GetTarget()->GetFullName())
, TargetId(xcObj->GetId())
, ConfigList(configList)
, XcodeVersion(xcVersion)
@@ -20,7 +23,7 @@ cmXCodeScheme::cmXCodeScheme(cmXCodeObject* xcObj,
}
void cmXCodeScheme::WriteXCodeSharedScheme(const std::string& xcProjDir,
const std::string sourceRoot)
const std::string& container)
{
// Create shared scheme sub-directory tree
//
@@ -39,14 +42,14 @@ void cmXCodeScheme::WriteXCodeSharedScheme(const std::string& xcProjDir,
return;
}
std::string xcProjRelDir = xcProjDir.substr(sourceRoot.size() + 1);
WriteXCodeXCScheme(fout, xcProjRelDir);
WriteXCodeXCScheme(fout, container);
}
void cmXCodeScheme::WriteXCodeXCScheme(std::ostream& fout,
const std::string& xcProjDir)
const std::string& container)
{
cmXMLWriter xout(fout);
xout.SetIndentationElement(std::string(3, ' '));
xout.StartDocument();
xout.StartElement("Scheme");
@@ -54,9 +57,9 @@ void cmXCodeScheme::WriteXCodeXCScheme(std::ostream& fout,
xout.Attribute("LastUpgradeVersion", WriteVersionString());
xout.Attribute("version", "1.3");
WriteBuildAction(xout, xcProjDir);
WriteBuildAction(xout, container);
WriteTestAction(xout, FindConfiguration("Debug"));
WriteLaunchAction(xout, FindConfiguration("Debug"), xcProjDir);
WriteLaunchAction(xout, FindConfiguration("Debug"), container);
WriteProfileAction(xout, FindConfiguration("Release"));
WriteAnalyzeAction(xout, FindConfiguration("Debug"));
WriteArchiveAction(xout, FindConfiguration("Release"));
@@ -65,7 +68,7 @@ void cmXCodeScheme::WriteXCodeXCScheme(std::ostream& fout,
}
void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout,
const std::string& xcProjDir)
const std::string& container)
{
xout.StartElement("BuildAction");
xout.BreakAttributes();
@@ -85,9 +88,9 @@ void cmXCodeScheme::WriteBuildAction(cmXMLWriter& xout,
xout.BreakAttributes();
xout.Attribute("BuildableIdentifier", "primary");
xout.Attribute("BlueprintIdentifier", this->TargetId);
xout.Attribute("BuildableName", this->TargetName);
xout.Attribute("BuildableName", this->BuildableName);
xout.Attribute("BlueprintName", this->TargetName);
xout.Attribute("ReferencedContainer", "container:" + xcProjDir);
xout.Attribute("ReferencedContainer", "container:" + container);
xout.EndElement();
xout.EndElement(); // BuildActionEntry
@@ -118,7 +121,7 @@ void cmXCodeScheme::WriteTestAction(cmXMLWriter& xout,
void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
std::string configuration,
const std::string& xcProjDir)
const std::string& container)
{
xout.StartElement("LaunchAction");
xout.BreakAttributes();
@@ -134,15 +137,22 @@ void cmXCodeScheme::WriteLaunchAction(cmXMLWriter& xout,
xout.Attribute("debugServiceExtension", "internal");
xout.Attribute("allowLocationSimulation", "YES");
xout.StartElement("MacroExpansion");
if (IsExecutable(this->Target)) {
xout.StartElement("BuildableProductRunnable");
xout.BreakAttributes();
xout.Attribute("runnableDebuggingMode", "0");
} else {
xout.StartElement("MacroExpansion");
}
xout.StartElement("BuildableReference");
xout.BreakAttributes();
xout.Attribute("BuildableIdentifier", "primary");
xout.Attribute("BlueprintIdentifier", this->TargetId);
xout.Attribute("BuildableName", this->TargetName);
xout.Attribute("BuildableName", this->BuildableName);
xout.Attribute("BlueprintName", this->TargetName);
xout.Attribute("ReferencedContainer", "container:" + xcProjDir);
xout.Attribute("ReferencedContainer", "container:" + container);
xout.EndElement();
xout.EndElement(); // MacroExpansion
@@ -204,3 +214,14 @@ std::string cmXCodeScheme::FindConfiguration(const std::string& name)
return name;
}
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;
}

View File

@@ -21,26 +21,30 @@ public:
unsigned int xcVersion);
void WriteXCodeSharedScheme(const std::string& xcProjDir,
const std::string sourceRoot);
const std::string& container);
private:
const cmXCodeObject* const Target;
const std::string& TargetName;
const std::string BuildableName;
const std::string& TargetId;
const std::vector<std::string>& ConfigList;
const unsigned int XcodeVersion;
void WriteXCodeXCScheme(std::ostream& fout, const std::string& xcProjDir);
void WriteXCodeXCScheme(std::ostream& fout, const std::string& container);
void WriteBuildAction(cmXMLWriter& xout, const std::string& xcProjDir);
void WriteBuildAction(cmXMLWriter& xout, const std::string& container);
void WriteTestAction(cmXMLWriter& xout, std::string configuration);
void WriteLaunchAction(cmXMLWriter& xout, std::string configuration,
const std::string& xcProjDir);
const std::string& container);
void WriteProfileAction(cmXMLWriter& xout, std::string configuration);
void WriteAnalyzeAction(cmXMLWriter& xout, std::string configuration);
void WriteArchiveAction(cmXMLWriter& xout, std::string configuration);
std::string WriteVersionString();
std::string FindConfiguration(const std::string& name);
static bool IsExecutable(const cmXCodeObject* target);
};
#endif

View File

@@ -7,6 +7,7 @@
cmXMLWriter::cmXMLWriter(std::ostream& output, std::size_t level)
: Output(output)
, IndentationElement(1, '\t')
, Level(level)
, ElementOpen(false)
, BreakAttrib(false)
@@ -100,10 +101,18 @@ void cmXMLWriter::FragmentFile(const char* fname)
this->Output << fin.rdbuf();
}
void cmXMLWriter::SetIndentationElement(std::string const& element)
{
this->IndentationElement = element;
}
void cmXMLWriter::ConditionalLineBreak(bool condition, std::size_t indent)
{
if (condition) {
this->Output << '\n' << std::string(indent + this->Level, '\t');
this->Output << '\n';
for (std::size_t i = 0; i < indent + this->Level; ++i) {
this->Output << this->IndentationElement;
}
}
}

View File

@@ -60,6 +60,8 @@ public:
void FragmentFile(const char* fname);
void SetIndentationElement(std::string const& element);
private:
cmXMLWriter(const cmXMLWriter&);
cmXMLWriter& operator=(const cmXMLWriter&);
@@ -107,6 +109,7 @@ private:
private:
std::ostream& Output;
std::stack<std::string, std::vector<std::string> > Elements;
std::string IndentationElement;
std::size_t Level;
bool ElementOpen;
bool BreakAttrib;