9

I am trying to add $(PLATFORM_DIR)/Developer/Library/Frameworks path to Specta target Header search paths using post install hook. This obviously is not vital, but it really annoys me to added this path manually each time I do "pod update".

I got to the following script:

post_install do |installer_representation|
  installer_representation.project.targets.each do |target|
      if target.name == 'Specta'
          target.build_configurations.each do |config|
             headers = config.build_settings['HEADER_SEARCH_PATHS']
             if headers
                 config.build_settings['HEADER_SEARCH_PATHS'] += ' $(PLATFORM_DIR)/Developer/Library/Frameworks'
             end
          end
      end
  end
end

I would be really happy if someone could point me to the right direction, because I am really stuck.

P.S. I already noticed that this path is already added by CocoaPods, but still I am highly interested in how this can be done, since this knowledge can be useful later. Thanks!

StalkerRus
  • 411
  • 1
  • 10
  • 20
  • http://stackoverflow.com/questions/30244675/how-can-i-modify-other-ldflags-via-cocoapods-post-install-hook perhaps? – Manav Oct 29 '16 at 02:52

1 Answers1

4

Define a method in your Podfile:

def append_header_search_path(target, path)
    target.build_configurations.each do |config|
        # Note that there's a space character after `$(inherited)`.
        config.build_settings["HEADER_SEARCH_PATHS"] ||= "$(inherited) "
        config.build_settings["HEADER_SEARCH_PATHS"] << path
    end
end

Then call the method in the post_install:

installer.pods_project.targets.each do |target|
    if target.name == "Specta"
        append_header_search_path(target, "$(PLATFORM_DIR)/Developer/Library/Frameworks")
    end
end
Lizhen Hu
  • 814
  • 10
  • 16