* Add custom-settings to an exported XCode-project to make it possible to compile for iOS _and_ the Simulator

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2647 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
loesje_
2013-02-03 01:39:54 +00:00
parent 5e40fc3cfa
commit ca1f5066e7
2 changed files with 36 additions and 22 deletions

View File

@ -20,7 +20,7 @@ interface
uses
Unix, BaseUnix, process,
Classes, SysUtils,
Classes, SysUtils, contnrs,
Graphics, Controls, Forms, Dialogs, FileUtil,
{Lazarus Interface}
LazIDEIntf, MenuIntf, ProjectIntf, IDEOptionsIntf, IDEMsgIntf,
@ -352,7 +352,7 @@ end;
procedure TiPhoneExtension.UpdateXcode(Sender: TObject);
var
templates : TStringList;
build : TStringList;
build : TFPStringHashTable;
dir : string;
projdir : string;
proj : TStringList;
@ -366,36 +366,46 @@ var
name : string;
opt : string;
optSim: string;
begin
FillBunldeInfo(false, Info);
// the create .plist would be used by XCode project
// the simulator .plist in created with InstallAppToSim.
// they differ with SDKs used
build := TStringList.Create;
build := TFPStringHashTable.Create;
tname:=ExtractFileName( LazarusIDE.ActiveProject.MainFile.Filename);
tname:=ChangeFileExt(tname, '');
plistname:=tname+'.plist';
build.Values['INFOPLIST_FILE'] := '"'+plistname+'"';
build.Values['PRODUCT_NAME'] := '"'+tname+'"';
build.Values['SDKROOT'] := EnvOptions.GetSDKName(ProjOptions.SDK, false);
build.Values['FPC_COMPILER_PATH'] := '"'+EnvOptions.CompilerPath+'"';
build.Values['FPC_MAIN_FILE'] := '"'+LazarusIDE.ActiveProject.MainFile.Filename+'"';
build.Add('INFOPLIST_FILE','"'+plistname+'"');
build.Add('PRODUCT_NAME','"'+tname+'"');
build.Add('SDKROOT',EnvOptions.GetSDKName(ProjOptions.SDK, false));
build.Add('FPC_COMPILER_PATH','"'+EnvOptions.CompilerPath+'"');
build.Add('FPC_MAIN_FILE','"'+LazarusIDE.ActiveProject.MainFile.Filename+'"');
opt :=
' -XR'+EnvOptions.GetSDKFullPath(ProjOptions.SDK, false)+' ' +
' -FD'+IncludeTrailingPathDelimiter(EnvOptions.PlatformsBaseDir)+'iPhoneOS.platform/Developer/usr/bin ' +
EnvOptions.CommonOpt;
optSim :=
' -XR'+EnvOptions.GetSDKFullPath(ProjOptions.SDK, true)+' ' +
' -FD'+IncludeTrailingPathDelimiter(EnvOptions.PlatformsBaseDir)+'iPhoneSimulator.platform/Developer/usr/bin ' +
EnvOptions.CommonOpt;
with LazarusIDE.ActiveProject.LazCompilerOptions do begin
opt:=opt + ' ' +BreakPathsStringToOption(OtherUnitFiles, '-Fu', '\"');
opt:=opt + ' ' +BreakPathsStringToOption(IncludePath, '-Fi', '\"');
opt:=opt + ' ' +BreakPathsStringToOption(ObjectPath, '-Fo', '\"');
opt:=opt + ' ' +BreakPathsStringToOption(Libraries, '-Fl', '\"');
optSim:=optSim + ' ' +BreakPathsStringToOption(OtherUnitFiles, '-Fu', '\"');
optSim:=optSim + ' ' +BreakPathsStringToOption(IncludePath, '-Fi', '\"');
optSim:=optSim + ' ' +BreakPathsStringToOption(ObjectPath, '-Fo', '\"');
optSim:=optSim + ' ' +BreakPathsStringToOption(Libraries, '-Fl', '\"');
end;
build.Values['FPC_CUSTOM_OPTIONS'] :='"'+opt+'"';
build.Add('FPC_CUSTOM_OPTIONS','"'+opt+'"');
build.Add('"FPC_CUSTOM_OPTIONS[sdk=iphonesimulator*]"','"'+optSim+'"');
dir:=ResolveProjectPath('xcode');
dir:=dir+'/';

View File

@ -21,7 +21,7 @@ interface
uses
Classes, SysUtils, contnrs;
procedure PrepareTemplateFile(Src, TemplateValues, BuildSettings: TStrings);
procedure PrepareTemplateFile(Src, TemplateValues: TStrings; BuildSettings: TFPStringHashTable);
const
XCodeProjectTemplateIconID : AnsiString ='0AE3FFA610F3C9AF00A9B007,';
@ -137,11 +137,14 @@ const
' isa = XCBuildConfiguration;'#10+
' buildSettings = {'#10+
' ARCHS = "$(ARCHS_STANDARD_32_BIT)";'#10+
' "ARCHS[sdk=iphonesimulator*]" = "$(ARCHS_STANDARD_32_BIT)";'#10+
' COPY_PHASE_STRIP = YES;'#10+
' FPC_OUTPUT_FILE = $BUILT_PRODUCTS_DIR/$EXECUTABLE_PATH;'#10+
' FPC_COMPILER_OPTIONS = "-Parm -o$FPC_OUTPUT_FILE $FPC_CUSTOM_OPTIONS";'#10+
' "FPC_COMPILER_OPTIONS[sdk=iphonesimulator*]" = "-Tiphonesim -Pi386 -o$FPC_OUTPUT_FILE $FPC_CUSTOM_OPTIONS";'#10+
' FPC_COMPILER_PATH = ;'#10+
' FPC_CUSTOM_OPTIONS = ;'#10+
' "FPC_CUSTOM_OPTIONS[sdk=iphonesimulator*]" = ;'#10+
' FPC_MAIN_FILE = ;'#10+
' SDKROOT = iphoneos2.0;'#10+
' VALID_ARCHS = "armv6 armv7";'#10+
@ -201,17 +204,24 @@ implementation
function GetValueName(const Source: String; idx: Integer): String;
var
i : integer;
InQuote: boolean;
const
//todo: expand symbols charset
Symbols: set of char = [#9, #32, #10,#13,
'=',':',';','-','+','*','/','\','!','@','#',
'$','%','^','&','(',')','~','`','''','"' ];
'$','%','^','&','(',')','~','`',''''];
begin
for i:=idx to length(Source) do
if Source[i] in Symbols then begin
InQuote:=false;
for i:=idx to length(Source) do begin
if InQuote then begin
if Source[i]='"' then InQuote := false;
end else if Source[i] = '"' then
InQuote := true
else if Source[i] in Symbols then begin
Result:=Copy(Source, idx, i-idx);
Exit;
end;
end;
Result:=Copy(Source, idx, length(Source)-idx+1);
end;
@ -234,13 +244,12 @@ begin
end;
end;
procedure PrepareTemplateFile(Src, TemplateValues, BuildSettings: TStrings);
procedure PrepareTemplateFile(Src, TemplateValues: TStrings; BuildSettings: TFPStringHashTable);
//todo: Better code to update XCode project file!
var
i, j : Integer;
nm, s, v : String;
isSettings : Boolean;
buildhash : TFPStringHashTable;
begin
if not Assigned(Src) then Exit;
@ -252,10 +261,6 @@ begin
isSettings:=false;
if Assigned(BuildSettings) and (BuildSettings.Count>0) then begin
buildhash := TFPStringHashTable.Create;
for i :=0 to BuildSettings.Count-1 do
buildhash.Add(BuildSettings.Names[i], BuildSettings.ValueFromIndex[i]);
for i:=0 to Src.Count-1 do begin
if not isSettings then
@ -271,14 +276,13 @@ begin
nm:=GetValueName(s, j);
if Assigned(buildhash.Find(nm)) then begin
v:=buildhash.Items[nm];
if Assigned(BuildSettings.Find(nm)) then begin
v:=BuildSettings.Items[nm];
Src[i]:=Copy(Src[i], 1, j-1)+nm+ ' = ' + v + ';';
end;
end;
end; {of else}
end;
buildhash.Free;
end;
end;