Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add custom path to HEADER_SEARCH_PATHS using CocoaPods post install hook

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!

like image 675
StalkerRus Avatar asked Oct 08 '14 15:10

StalkerRus


1 Answers

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
like image 185
Lizhen Hu Avatar answered Oct 31 '22 12:10

Lizhen Hu