From 025edea019fa95581045ad6b83e7556a83d15f69 Mon Sep 17 00:00:00 2001 From: James Touton Date: Fri, 3 Jun 2016 16:38:52 -0700 Subject: [PATCH 1/6] Xcode: Add const qualifiers --- Source/cmXCodeObject.h | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h index d2f7cb712..1502c2785 100644 --- a/Source/cmXCodeObject.h +++ b/Source/cmXCodeObject.h @@ -59,11 +59,11 @@ public: static const char* PBXTypeNames[]; virtual ~cmXCodeObject(); cmXCodeObject(PBXType ptype, Type type); - Type GetType() { return this->TypeValue; } - PBXType GetIsA() { return this->IsA; } + Type GetType() const { return this->TypeValue; } + PBXType GetIsA() const { return this->IsA; } void SetString(const std::string& s); - const std::string& GetString() { return this->String; } + const std::string& GetString() const { return this->String; } void AddAttribute(const std::string& name, cmXCodeObject* value) { @@ -73,7 +73,7 @@ public: void SetObject(cmXCodeObject* value) { this->Object = value; } cmXCodeObject* GetObject() { return this->Object; } void AddObject(cmXCodeObject* value) { this->List.push_back(value); } - bool HasObject(cmXCodeObject* o) + bool HasObject(cmXCodeObject* o) const { return !(std::find(this->List.begin(), this->List.end(), o) == this->List.end()); @@ -94,23 +94,25 @@ public: virtual void PrintComment(std::ostream&) {} static void PrintList(std::vector const&, std::ostream& out); - const std::string& GetId() { return this->Id; } + const std::string& GetId() const { return this->Id; } void SetId(const std::string& id) { this->Id = id; } - cmGeneratorTarget* GetTarget() { return this->Target; } + cmGeneratorTarget* GetTarget() const { return this->Target; } void SetTarget(cmGeneratorTarget* t) { this->Target = t; } - const std::string& GetComment() { return this->Comment; } - bool HasComment() { return (!this->Comment.empty()); } - cmXCodeObject* GetObject(const char* name) + const std::string& GetComment() const { return this->Comment; } + bool HasComment() const { return (!this->Comment.empty()); } + cmXCodeObject* GetObject(const char* name) const { - if (this->ObjectAttributes.count(name)) { - return this->ObjectAttributes[name]; + std::map::const_iterator i = + this->ObjectAttributes.find(name); + if (i != this->ObjectAttributes.end()) { + return i->second; } return 0; } // search the attribute list for an object of the specified type - cmXCodeObject* GetObject(cmXCodeObject::PBXType t) + cmXCodeObject* GetObject(cmXCodeObject::PBXType t) const { - for (std::vector::iterator i = this->List.begin(); + for (std::vector::const_iterator i = this->List.begin(); i != this->List.end(); ++i) { cmXCodeObject* o = *i; if (o->IsA == t) { @@ -126,7 +128,7 @@ public: { this->DependLibraries[configName].push_back(l); } - std::map const& GetDependLibraries() + std::map const& GetDependLibraries() const { return this->DependLibraries; } @@ -134,11 +136,14 @@ public: { this->DependTargets[configName].push_back(tName); } - std::map const& GetDependTargets() + std::map const& GetDependTargets() const { return this->DependTargets; } - std::vector const& GetObjectList() { return this->List; } + std::vector const& GetObjectList() const + { + return this->List; + } void SetComment(const std::string& c) { this->Comment = c; } static void PrintString(std::ostream& os, std::string String); From 82ebbf683e201af7b9bb493a221804992abf5a4a Mon Sep 17 00:00:00 2001 From: Gregor Jasny Date: Sun, 12 Jun 2016 21:39:16 +0200 Subject: [PATCH 2/6] Xcode: Add function to conditionally add Xcode Attributes --- Source/cmXCodeObject.cxx | 16 ++++++++++++++++ Source/cmXCodeObject.h | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/Source/cmXCodeObject.cxx b/Source/cmXCodeObject.cxx index 3d3134339..fabf097ad 100644 --- a/Source/cmXCodeObject.cxx +++ b/Source/cmXCodeObject.cxx @@ -83,6 +83,22 @@ cmXCodeObject::cmXCodeObject(PBXType ptype, Type type) } } +bool cmXCodeObject::IsEmpty() const +{ + switch (this->TypeValue) { + case OBJECT_LIST: + return this->List.empty(); + case STRING: + return this->String.empty(); + case ATTRIBUTE_GROUP: + return this->ObjectAttributes.empty(); + case OBJECT_REF: + case OBJECT: + return this->Object == 0; + } + return true; // unreachable, but quiets warnings +} + void cmXCodeObject::Indent(int level, std::ostream& out) { while (level) { diff --git a/Source/cmXCodeObject.h b/Source/cmXCodeObject.h index 1502c2785..ed917aff4 100644 --- a/Source/cmXCodeObject.h +++ b/Source/cmXCodeObject.h @@ -62,6 +62,8 @@ public: Type GetType() const { return this->TypeValue; } PBXType GetIsA() const { return this->IsA; } + bool IsEmpty() const; + void SetString(const std::string& s); const std::string& GetString() const { return this->String; } @@ -70,6 +72,13 @@ public: this->ObjectAttributes[name] = value; } + void AddAttributeIfNotEmpty(const std::string& name, cmXCodeObject* value) + { + if (value && !value->IsEmpty()) { + AddAttribute(name, value); + } + } + void SetObject(cmXCodeObject* value) { this->Object = value; } cmXCodeObject* GetObject() { return this->Object; } void AddObject(cmXCodeObject* value) { this->List.push_back(value); } From ef494edf766d622f87b82e601bf6ef7405bf29d0 Mon Sep 17 00:00:00 2001 From: James Touton Date: Fri, 3 Jun 2016 18:32:38 -0700 Subject: [PATCH 3/6] Xcode: Don't emit empty settings blocks. --- Source/cmGlobalXCodeGenerator.cxx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 4d778ee17..b43901849 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -689,7 +689,8 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile( cmXCodeObject* fileRef = buildFile->GetObject("fileRef")->GetObject(); cmXCodeObject* settings = this->CreateObject(cmXCodeObject::ATTRIBUTE_GROUP); - settings->AddAttribute("COMPILER_FLAGS", this->CreateString(flags)); + settings->AddAttributeIfNotEmpty("COMPILER_FLAGS", + this->CreateString(flags)); // Is this a resource file in this target? Add it to the resources group... // @@ -698,23 +699,23 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile( gtgt->GetTargetSourceFileFlags(sf); bool isResource = tsFlags.Type == cmGeneratorTarget::SourceFileTypeResource; + cmXCodeObject* attrs = this->CreateObject(cmXCodeObject::OBJECT_LIST); + // Is this a "private" or "public" framework header file? // Set the ATTRIBUTES attribute appropriately... // if (gtgt->IsFrameworkOnApple()) { if (tsFlags.Type == cmGeneratorTarget::SourceFileTypePrivateHeader) { - cmXCodeObject* attrs = this->CreateObject(cmXCodeObject::OBJECT_LIST); attrs->AddObject(this->CreateString("Private")); - settings->AddAttribute("ATTRIBUTES", attrs); isResource = true; } else if (tsFlags.Type == cmGeneratorTarget::SourceFileTypePublicHeader) { - cmXCodeObject* attrs = this->CreateObject(cmXCodeObject::OBJECT_LIST); attrs->AddObject(this->CreateString("Public")); - settings->AddAttribute("ATTRIBUTES", attrs); isResource = true; } } + settings->AddAttributeIfNotEmpty("ATTRIBUTES", attrs); + // Add the fileRef to the top level Resources group/folder if it is not // already there. // @@ -723,7 +724,7 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile( this->ResourcesGroupChildren->AddObject(fileRef); } - buildFile->AddAttribute("settings", settings); + buildFile->AddAttributeIfNotEmpty("settings", settings); return buildFile; } From 811f6c825271320259ed0ccdbe3c2d577ccbdcd4 Mon Sep 17 00:00:00 2001 From: James Touton Date: Fri, 3 Jun 2016 18:51:18 -0700 Subject: [PATCH 4/6] Xcode: Add XCODE_FILE_ATTRIBUTES source file property This adds values to the ATTRIBUTES list in PBXBuildFile settings. --- Help/manual/cmake-properties.7.rst | 1 + Help/prop_sf/XCODE_FILE_ATTRIBUTES.rst | 11 +++++++++++ Source/cmGlobalXCodeGenerator.cxx | 14 ++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 Help/prop_sf/XCODE_FILE_ATTRIBUTES.rst diff --git a/Help/manual/cmake-properties.7.rst b/Help/manual/cmake-properties.7.rst index 3403dcd86..1c64d6363 100644 --- a/Help/manual/cmake-properties.7.rst +++ b/Help/manual/cmake-properties.7.rst @@ -344,6 +344,7 @@ Properties on Source Files /prop_sf/VS_XAML_TYPE /prop_sf/WRAP_EXCLUDE /prop_sf/XCODE_EXPLICIT_FILE_TYPE + /prop_sf/XCODE_FILE_ATTRIBUTES /prop_sf/XCODE_LAST_KNOWN_FILE_TYPE .. _`Cache Entry Properties`: diff --git a/Help/prop_sf/XCODE_FILE_ATTRIBUTES.rst b/Help/prop_sf/XCODE_FILE_ATTRIBUTES.rst new file mode 100644 index 000000000..39e69665a --- /dev/null +++ b/Help/prop_sf/XCODE_FILE_ATTRIBUTES.rst @@ -0,0 +1,11 @@ +XCODE_FILE_ATTRIBUTES +--------------------- + +Add values to the Xcode ``ATTRIBUTES`` setting on its reference to a +source file. Among other things, this can be used to set the role on +a mig file:: + + set_source_files_properties(defs.mig + PROPERTIES + XCODE_FILE_ATTRIBUTES "Client;Server" + ) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index b43901849..8eefb196b 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -714,6 +714,20 @@ cmXCodeObject* cmGlobalXCodeGenerator::CreateXCodeSourceFile( } } + // Add user-specified file attributes. + const char* extraFileAttributes = sf->GetProperty("XCODE_FILE_ATTRIBUTES"); + if (extraFileAttributes) { + // Expand the list of attributes. + std::vector attributes; + cmSystemTools::ExpandListArgument(extraFileAttributes, attributes); + + // Store the attributes. + for (std::vector::const_iterator ai = attributes.begin(); + ai != attributes.end(); ++ai) { + attrs->AddObject(this->CreateString(*ai)); + } + } + settings->AddAttributeIfNotEmpty("ATTRIBUTES", attrs); // Add the fileRef to the top level Resources group/folder if it is not From 27eb657d110123ee22b87fad1df7ebf64ecb47ba Mon Sep 17 00:00:00 2001 From: James Touton Date: Fri, 3 Jun 2016 18:27:39 -0700 Subject: [PATCH 5/6] Xcode: Add support for mig files --- Source/cmGlobalXCodeGenerator.cxx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Source/cmGlobalXCodeGenerator.cxx b/Source/cmGlobalXCodeGenerator.cxx index 8eefb196b..d30830a46 100644 --- a/Source/cmGlobalXCodeGenerator.cxx +++ b/Source/cmGlobalXCodeGenerator.cxx @@ -787,6 +787,8 @@ std::string GetSourcecodeValueFromFileExtension(const std::string& _ext, sourcecode += ".asm"; } else if (ext == "metal") { sourcecode += ".metal"; + } else if (ext == "mig") { + sourcecode += ".mig"; } // else // { From 8be00e443ff4ad6795ddd90d0f6d6873623aa1b3 Mon Sep 17 00:00:00 2001 From: Brad King Date: Fri, 17 Jun 2016 10:53:59 -0400 Subject: [PATCH 6/6] Help: Add release note about XCODE_FILE_ATTRIBUTES source file property --- Help/release/dev/xcode-file-attributes.rst | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Help/release/dev/xcode-file-attributes.rst diff --git a/Help/release/dev/xcode-file-attributes.rst b/Help/release/dev/xcode-file-attributes.rst new file mode 100644 index 000000000..35824fa6c --- /dev/null +++ b/Help/release/dev/xcode-file-attributes.rst @@ -0,0 +1,6 @@ +xcode-file-attributes +--------------------- + +* A :prop_sf:`XCODE_FILE_ATTRIBUTES` source file property was + added to tell the :generator:`Xcode` generator to generate + custom content in the Xcode project attributes for the file.