Created
December 29, 2011 15:28
-
-
Save kizzx2/1534572 to your computer and use it in GitHub Desktop.
Use premake4 to generate iOS .xcodeproj files
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
solution "example" | |
language "C++" | |
configurations { "Debug", "Release" } | |
flags { "ExtraWarnings", "StaticRuntime" } | |
-- if you used Homebrew to install boost to these locations... | |
if _ACTION == "xcode3" then | |
includedirs { "/usr/local/include" } | |
libdirs { "/usr/local/lib" } | |
end | |
configuration "Debug" | |
defines { "DEBUG" } | |
flags { "Symbols" } | |
targetdir "build/Debug" | |
configuration "Release" | |
defines { "NDEBUG" } | |
flags { "Optimize" } | |
targetdir "build/Release" | |
project "lib" | |
kind "StaticLib" | |
files { "lib/**.cpp", "lib/**.h", "lib/**.hpp" } | |
project "app" | |
kind "ConsoleApp" | |
files { "app/*" } | |
files { "app/en.lproj" } | |
includedirs { "lib" } | |
links { "lib" } | |
linkoptions | |
{ "-framework OpenGLES" | |
, "-framework QuartzCore" | |
, "-framework UIKit" | |
, "-framework Foundation" | |
, "-framework CoreGraphics" | |
} |
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
# Usage: | |
# In premake4.lua use StaticLib for libraries; ConsoleApp for applications. | |
# Then run `rake xcode && rake xcodebuild` | |
ENV_DEFAULTS = { | |
'CONFIGURATION' => "Debug", | |
'SDK' => "iphonesimulator", | |
} | |
SDK_TO_ARCH = { | |
"iphonesimulator" => "i386", | |
"iphoneos" => "armv7", | |
} | |
# These projects will be converted to iOS applications. These | |
# should be the ones you specified ConsoleApp in premake4.lua | |
APP_PROJECTS = %w(app1 app2) | |
APP_XCODEPROJS = APP_PROJECTS.map { |x| "#{x}.xcodeproj" } | |
ENV_DEFAULTS.each {|k, v| ENV[k] = v if !ENV[k] } | |
def xcode_to_ios pbxproj | |
lines = IO.readlines(pbxproj).select do |l| | |
not l =~ /PREBINDING =/ and not l =~ /GCC_ENABLE_FIX_AND_CONTINUE =/ | |
end.map do |l| | |
l. | |
gsub("$(NATIVE_ARCH_ACTUAL)", "$(ARCHS_STANDARD_32_BIT)"). | |
gsub("objectVersion = 45", "objectVersion = 46") | |
end.map do |l| | |
l =~ /PRODUCT_NAME =/ ? [l, | |
%(CODE_SIGN_IDENTITY = "iPhone Developer";), | |
%(PROVISIONING_PROFILE = "";), | |
%(SDKROOT = iphoneos;)] : l | |
end.flatten | |
open(pbxproj, 'w') {|f| f.puts lines } | |
end | |
def xcode_to_app pbxproj | |
lines = IO.readlines(pbxproj).map do |l| | |
l.gsub("com.apple.product-type.tool", "com.apple.product-type.application") | |
end | |
open(pbxproj, 'w') {|f| f.puts lines } | |
end | |
def run cmd | |
puts cmd | |
system cmd | |
end | |
desc "Create Xcode build files." | |
task :xcode do | |
run "premake4 clean" | |
run "premake4 xcode3" | |
Dir["*.xcodeproj"].each { |xc| xcode_to_ios "#{xc}/project.pbxproj" } | |
APP_XCODEPROJS.each { |xc| xcode_to_app "#{xc}/project.pbxproj" } | |
end | |
desc "Run xcodebuild command. See ENV_DEFAULTS for a list." | |
task :xcodebuild do | |
APP_XCODEPROJS.each do |xc| | |
run(%(xcodebuild -project #{xc} -configuration #{ENV['CONFIGURATION']} ) + | |
%(-sdk #{ENV['SDK']} -arch #{SDK_TO_ARCH[ENV['SDK']]})) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment