8

How can I automate the creation of XCode projects within a terminal? If you are asking the purpose of this... I wish to create a service that can automatically create multiple different projects for different users.


ApplesScript

I believe this is possible with AppleScript, but this would be a big drain of ressources since it would open XCode. Also, this would most likely take a lot of time to create multiple projects.

*Edit: The use of AppleScript is definitely not what I am searching for in terms of performant solution.


CMake

I have looked into CMake, but I am a bit lost and confused with the documentation given for it...

*Edit: I have found the following for a CMakeLists.txt at https://gist.github.com/740257. Yet, the settings have to be modified.

# See original post at http://stackoverflow.com/questions/822404/how-to-set-up-cmake-to-build-an-app-for-the-iphone

cmake_minimum_required(VERSION 2.8)

cmake_policy(SET CMP0015 NEW)
cmake_policy(SET CMP0016 NEW)

project(test)
set(NAME test)

file(GLOB headers *.h)
file(GLOB sources *.cpp)

SET (SDKVER "4.1")
SET (DEVROOT "/Developer/Platforms/iPhoneOS.platform/Developer")
SET (SDKROOT "${DEVROOT}/SDKs/iPhoneOS${SDKVER}.sdk")
SET (CMAKE_OSX_SYSROOT "${SDKROOT}")
SET (CMAKE_OSX_ARCHITECTURES "$(ARCHS_UNIVERSAL_IPHONE_OS)")

#Other 'CMAKE_OSX_ARCHITECTURES' iPhone/IOS option examples
#SET (CMAKE_OSX_ARCHITECTURES "armv6" "armv7")
#SET (CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD_32_BIT))


set(CMAKE_CXX_FLAGS "-x objective-c++")
set(CMAKE_EXE_LINKER_FLAGS
    "-framework AudioToolbox -framework CoreGraphics -framework QuartzCore -framework UIKit"
)
link_directories(\${HOME}/\${SDKROOT}/lib)

set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.mycompany.\${PRODUCT_NAME:identifier}")
set(APP_TYPE MACOSX_BUNDLE)

add_executable(${NAME}
    ${APP_TYPE}
    ${headers}
    ${sources}
)

target_link_libraries(${NAME}
    # other libraries to link
)

# code signing
set_target_properties(${NAME} PROPERTIES XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer: My Name")

I will build my own solution from that file. For instance, I know that the SDK version is wrong.


Terminal Tools

Are there some Developer Tools (that comes with XCode 4.2.1) for the Terminal that I could leverage for my situation?


Alerty
  • 5,945
  • 7
  • 38
  • 62
  • Xcode projects are simply structured text files, so it is trivial to generate from a template, so what exactly is the problem? How different will they be form each other? If you only change names and add/remove files then it's really easy by creating a text template from a project you created with Xcode and filling in the names with any tool (sed, perl, autoconf, ...) – Simon Urbanek Feb 05 '12 at 21:47
  • Every project will be unique and I am seriously considering CMake. I am missing many important settings for it though. – Alerty Feb 05 '12 at 21:59

1 Answers1

10

Try https://github.com/CocoaPods/Xcodeproj. It's a ruby gem that allows to create and modify xcode projects. You could use it in your scripts.

Example usage:

~/code/temp % irb                                                                                                                                            18:17
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'xcodeproj'
=> true
irb(main):003:0> project = Xcodeproj::Project.new
=> #<Xcodeproj::Project:0x400dfc080 @plist={"archiveVersion"=>"1", "classes"=>{}, "objectVersion"=>"46", "objects"=>{"ED69A76A86EE4CBD96F96E4D"=>{"isa"=>"PBXGroup", "sourceTree"=>"<group>", "children"=>[]}, "17739AA030054D088B3B573E"=>{"attributes"=>{"LastUpgradeCheck"=>"0420"}, "compatibilityVersion"=>"Xcode 3.2", "developmentRegion"=>"English", "hasScannedForEncodings"=>"0", "knownRegions"=>["en"], "mainGroup"=>"ED69A76A86EE4CBD96F96E4D", "projectDirPath"=>"", "projectRoot"=>"", "targets"=>[], "isa"=>"PBXProject"}}, "rootObject"=>"17739AA030054D088B3B573E"} @objects=<PBXObjectList: ["#<PBXGroup UUID: `ED69A76A86EE4CBD96F96E4D', name: `'>", "#<PBXProject UUID: `17739AA030054D088B3B573E', name: `'>"]>>
irb(main):004:0> project.save_as('MyProject')
=> true

See documentation here: http://rubydoc.info/gems/xcodeproj/frames

Hope this will help you!

yas375
  • 3,940
  • 1
  • 24
  • 33
  • 1
    I'll have a look at this ruby gem. Thanks! – Alerty Feb 08 '12 at 04:55
  • Hmm okay.. I seem to have version 1.0.2 of rubygems-compile which needs MacRuby 0.11 which is not out yet. – Alerty Feb 09 '12 at 01:06
  • Finally, I got the right version for rubygems-compile. Now, time to learn a bit of Ruby. – Alerty Feb 09 '12 at 01:10
  • In fact, I am new to Ruby and the documentation given for the Xcodeproj gem is a list of undocumented classes and methods. – Alerty Feb 09 '12 at 01:23
  • 1
    yes, documentation is bad(( I think you should ask the author of xcodeproj gem on github for explaining how to use it in your case. Maybe he will help you... – yas375 Feb 10 '12 at 09:39
  • 1
    Guilty as charged :) What kind of project are you looking to generate? If it's a static library, then take a look at how we use it to do that in CocoaPods. ([here](https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/installer.rb#L32), [here](https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/installer/target_installer.rb#L65), and [here](https://github.com/CocoaPods/CocoaPods/blob/master/lib/cocoapods/xcodeproj_pods.rb)) – alloy Feb 17 '12 at 09:32
  • 2
    Also, it no longer requires MacRuby, you can use it with the system ruby. – alloy Feb 24 '12 at 11:47