Created
October 7, 2015 03:30
-
-
Save gunyarakun/c587f9d07ced70db6fdb to your computer and use it in GitHub Desktop.
Add compiler flags for specific files in Xcode project with Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# -*- coding: utf-8 -*- | |
require 'xcodeproj' | |
# Add compiler flags to "Build Phases > Compile Sources" | |
def add_compiler_flags(xcproj, flags) | |
xcproj.targets.each do |target| | |
target.source_build_phase.files_references.each do |fileref| | |
# You can check fileref with fileref.path or fileref.parent | |
# fileref.parent is PBXGroup or PBXProject | |
# In this sample, we check if any parent group has "WinObjC/Frameworks" path | |
add_flags = false | |
r = fileref | |
loop { | |
if r.kind_of?(Xcodeproj::Project::Object::PBXProject) || r.source_tree != '<group>' | |
break | |
elsif r.path == 'WinObjC/Frameworks' | |
add_flags = true | |
break | |
end | |
r = r.parent | |
} | |
next unless add_flags | |
fileref.build_files.each do |bf| | |
# TODO: merge settings with original COMPILER_FLAGS | |
bf.settings = {'COMPILER_FLAGS' => flags} | |
end | |
end | |
end | |
end | |
def main | |
xcproj_path = ARGV.shift | |
flags = ARGV.shift | |
xcproj = Xcodeproj::Project.new(xcproj_path) | |
xcproj.initialize_from_file | |
add_compiler_flags(xcproj, flags) | |
xcproj.save | |
end | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment