Created
May 28, 2019 09:24
-
-
Save industriousonesoft/877a0c5fbe064d920a7d3b4dfec9e787 to your computer and use it in GitHub Desktop.
Add libs using xcodeproj in Ruby script
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
require 'xcodeproj' | |
require 'find' | |
#Helper Documents | |
#https://www.rubydoc.info/gems/xcodeproj/Xcodeproj/Project/ | |
project_path = "/Users/iceberg/Documents/ZDSourceCode/Product/Mac/Media/ZDMirrorCast-Test/V20/ZDMirrorCast.xcodeproj"; | |
# Create project object | |
project = Xcodeproj::Project.open(project_path); | |
#Add Lib to Frameworks BuildPhase | |
lib_path_dir = "/Users/iceberg/Documents/ZDSourceCode/Frameworks/OSX/GarbageCodesLibs"; | |
isStaticLib = false; | |
isDylib = false; | |
isFrameWork = false; | |
#Add lib/dylib/framework Reference | |
Find.find(lib_path_dir) do |lib_path| | |
isStaticLib = File.extname(lib_path) == '.a'; | |
isDylib = File.extname(lib_path) == '.dylib'; | |
isFrameWork = File.extname(lib_path) == '.framework'; | |
if isStaticLib || isDylib || isFrameWork | |
puts File.dirname(lib_path); | |
# Add the lib file to Frameworks group as a reference | |
libRef = project['Frameworks'].new_file(lib_path); | |
# Get the build phase | |
framework_buildphase = project.objects.select{|x| x.class == Xcodeproj::Project::Object::PBXFrameworksBuildPhase}[0]; | |
puts framework_buildphase | |
# Add it to the build phase | |
framework_buildphase.add_file_reference(libRef); | |
end | |
end | |
#Modify Search Paths | |
build_Configurations = project.objects.select{|x| x.class == Xcodeproj::Project::Object::XCBuildConfiguration}; | |
build_Configurations.each do |build_Configuration| | |
# framework_search_paths = build_Configuration.build_settings['FRAMEWORK_SEARCH_PATHS'] | |
# if framework_search_paths | |
# puts framework_search_paths; | |
# end | |
# header_search_paths = build_Configuration.build_settings['HEADER_SEARCH_PATHS'] | |
# if header_search_paths | |
# puts header_search_paths; | |
# end | |
library_search_paths = build_Configuration.build_settings['LIBRARY_SEARCH_PATHS'] | |
if library_search_paths.class == String | |
puts library_search_paths.class; | |
new_library_search_paths = Array.new; | |
new_library_search_paths.push(library_search_paths); | |
new_library_search_paths.push("$(SRCROOT)/../../../../../Frameworks/OSX/GarbageCodesLibs/"); | |
build_Configuration.build_settings['LIBRARY_SEARCH_PATHS'] = new_library_search_paths; | |
elsif library_search_paths.class == Array | |
puts library_search_paths.class; | |
end | |
end | |
# # Save the project | |
project.save(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment