-- -- xcode_scheme.lua -- local premake = premake local xcode = premake.xcode -- -- Print a BuildableReference element. -- local function buildableref(indent, prj, cfg) cfg = cfg or premake.eachconfig(prj)() _p(indent + 0, '', prj.name) _p(indent + 0, '') end -- -- Print a CommandLineArgs element, if needed by the provided config. -- local function cmdlineargs(indent, cfg) if #cfg.debugargs > 0 then _p(indent, '') for _, arg in ipairs(cfg.debugargs) do _p(indent + 1, '') _p(indent + 1, '') end _p(indent, '') end end -- -- Print an EnvironmentVariables element, if needed by the provided config. local function envvars(indent, cfg) if #cfg.debugenvs > 0 then _p(indent, '') for _, arg in ipairs(cfg.debugenvs) do local eq = arg:find("=") local k = arg:sub(1, eq) local v = arg:sub(eq + 1) _p(indent + 1, '') _p(indent + 1, '') end _p(indent, '') end end -- -- Generate the customWorkingDir path from the given dir. -- local function workingdir(dir) if not path.isabsolute(dir) then dir = "$PROJECT_DIR/" .. dir end return dir end -- -- Determine the best matching configuration. -- -- @param fordebug -- True to find a debug configuration. -- local function bestconfig(prj, fordebug) local bestcfg = nil local bestscore = -1 for cfg in premake.eachconfig(prj) do local score = 0 if cfg.platform == "Native" then score = score + 10 end if fordebug and cfg.name == "Debug" then score = score + 1 end if not fordebug and cfg.name == "Release" then score = score + 1 end if score > bestscore then bestcfg = cfg bestscore = score end end return bestcfg end -- -- Print out an xcscheme file. -- -- @param tobuild -- The list of targets to build. Assumed to be sorted. -- @param primary -- The target to set as test/profile/launch target. -- function xcode.scheme(tobuild, primary, schemecfg) _p('') _p('') _p(1, '') _p(2, '') for _, prj in ipairs(tobuild) do _p(3, '') buildableref(4, prj) _p(3, '') end local debugcfg = schemecfg or bestconfig(primary, true) local releasecfg = schemecfg or bestconfig(primary, false) local debugname = xcode.getconfigname(debugcfg) local releasename = xcode.getconfigname(releasecfg) _p(2, '') _p(1, '') _p(1, '') _p(2, '') _p(2, '') _p(2, '') buildableref(3, primary, debugcfg) _p(2, '') _p(2, '') _p(2, '') _p(1, '') _p(1, '') if debugcfg.debugcmd then _p(2, '', debugcfg.debugcmd) _p(2, '') else _p(2, '') buildableref(3, primary, debugcfg) _p(2, '') end cmdlineargs(2, debugcfg) envvars(2, debugcfg) _p(2, '') _p(2, '') _p(1, '') _p(1, '') _p(2, '') buildableref(3, primary, releasecfg) _p(2, '') cmdlineargs(2, releasecfg) envvars(2, releasecfg) _p(1, '') _p(1, '', debugname) _p(1, '') _p(1, '') _p(1, '') _p('') end -- -- Generate XCode schemes for the given project. -- function xcode.generate_schemes(prj, base_path) if (prj.kind == "ConsoleApp" or prj.kind == "WindowedApp") or (prj.options and prj.options.XcodeLibrarySchemes) then if prj.options and prj.options.XcodeSchemeNoConfigs then premake.generate(prj, path.join(base_path, "%%.xcscheme"), function(prj) xcode.scheme({prj}, prj) end) else for cfg in premake.eachconfig(prj) do premake.generate(prj, path.join(base_path, "%% " .. cfg.name .. ".xcscheme"), function(prj) xcode.scheme({prj}, prj, cfg) end) end end end end