Skip to content

Commit

Permalink
Support the setting of file-specific compiler flags when adding sourc…
Browse files Browse the repository at this point in the history
…e files to the project.

We'll need this to support #8.
  • Loading branch information
lukeredpath committed Sep 21, 2011
1 parent 6f5233a commit 10abfd7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/cocoapods/xcode/project.rb
Expand Up @@ -50,14 +50,15 @@ def source_files
end.compact
end

def add_source_file(file)
def add_source_file(file, compiler_flags = nil)
file_ref_uuid = add_file_reference(file, 'SOURCE_ROOT')
add_file_to_group(file_ref_uuid, 'Pods')
if file.extname == '.h'
build_file_uuid = add_build_file(file_ref_uuid, "settings" => { "ATTRIBUTES" => ["Public"] })
add_file_to_list('PBXHeadersBuildPhase', build_file_uuid)
else
build_file_uuid = add_build_file(file_ref_uuid)
extra = compiler_flags ? {"settings" => { "COMPILER_FLAGS" => compiler_flags }} : {}
build_file_uuid = add_build_file(file_ref_uuid, extra)
add_file_to_list('PBXSourcesBuildPhase', build_file_uuid)
end
file_ref_uuid
Expand Down
13 changes: 13 additions & 0 deletions spec/unit/xcode/project_spec.rb
Expand Up @@ -38,6 +38,19 @@
end
end

it "adds custom compiler flags to the PBXBuildFile object if specified" do
build_file_uuids = []
%w{ m mm c cpp }.each do |ext|
path = Pathname.new("path/to/file.#{ext}")
file_ref_uuid = @project.add_source_file(path, '-fno-obj-arc')
@project.find_object({
'isa' => 'PBXBuildFile',
'fileRef' => file_ref_uuid,
'settings' => {'COMPILER_FLAGS' => '-fno-obj-arc' }
}).should.not == nil
end
end

it "adds a `h' file as a build file and adds it to the `headers build' phase list" do
path = Pathname.new("path/to/file.h")
file_ref_uuid = @project.add_source_file(path)
Expand Down

0 comments on commit 10abfd7

Please sign in to comment.