From bdbff87c7615a983e4376efe899b77c451b7fb9e Mon Sep 17 00:00:00 2001 From: skalogryz Date: Sun, 20 Dec 2015 06:04:33 +0000 Subject: [PATCH] iphonelazext: adding resource files list support. todo: detect file type of a resource file. Currently Xcode identifies each file as mach-o binary git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4405 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/iphonelazext/ideext.pas | 3 +-- components/iphonelazext/xcodetemplate.pas | 32 ++++++++++++++++++++--- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/components/iphonelazext/ideext.pas b/components/iphonelazext/ideext.pas index 1188dcb85..ff4f5621b 100644 --- a/components/iphonelazext/ideext.pas +++ b/components/iphonelazext/ideext.pas @@ -427,8 +427,7 @@ begin templates.Values['mainfile']:=LazarusIDE.ActiveProject.MainFile.Filename; templates.Values['projoptions']:=opt; - // Xcode project updated (/Users/dmitry/FPC_Laz/iphonelazext/tests/xcode/test_xcodetemplate.xcodeproj) - PrepareTemplateFile(proj, templates); + PrepareTemplateFile(proj, templates, ProjOptions.ResFiles); proj.SaveToFile(projname); except on e: exception do diff --git a/components/iphonelazext/xcodetemplate.pas b/components/iphonelazext/xcodetemplate.pas index bdf8e2757..2aceef0e9 100644 --- a/components/iphonelazext/xcodetemplate.pas +++ b/components/iphonelazext/xcodetemplate.pas @@ -22,7 +22,7 @@ uses Classes, SysUtils, contnrs, xcodeproj; procedure PrepareTemplateFile_(Src, TemplateValues: TStrings; BuildSettings: TFPStringHashTable); -procedure PrepareTemplateFile(Src, TemplateValues: TStrings); +procedure PrepareTemplateFile(Src, TemplateValues, ResFiles: TStrings); procedure UpdateBldConfig(const proj: PBXProject; optName, optVal: string); procedure UpdateMainFile(const proj: PBXProject; mainfile: string); procedure UpdateCompileOpts(const proj: PBXProject; options: string); @@ -365,19 +365,23 @@ begin UpdateBldConfig(proj, 'FPC_MAIN_DIR', ExtractFileDir(mainfile)); end; -procedure PrepareTemplateFile(Src, TemplateValues: TStrings); +procedure PrepareTemplateFile(Src, TemplateValues, ResFiles: TStrings); var prj : PBXProject; trg : PBXNativeTarget; cfg : XCBuildConfiguration; fr : PBXFileReference; + fbld : PBXBuildFile; grp : PBXGroup; + pgrp : PBXGroup; scr : PBXShellScriptBuildPhase; + res : PBXResourcesBuildPhase; i : integer; plist : string; targetName : string; bundle : string; main : string; + fnm : string; begin prj:=ProjectCreate3_2; @@ -418,8 +422,8 @@ begin trg.productReference:=fr; // Creating "content" for the directory. It should also contain .plist - grp:=prj.mainGroup.addSubGroup(targetName); // name must match to the target name! - grp:=grp.addSubGroup('Supporting Files'); // name must match! + pgrp:=prj.mainGroup.addSubGroup(targetName); // name must match to the target name! + grp:=pgrp.addSubGroup('Supporting Files'); // name must match! // creating a reference to info.plist. It's located at "xcode" folder. // Thus at the same directar as .xcodeproj dir @@ -433,6 +437,26 @@ begin scr.shellScript:=BuildScript; scr.showEnvVarsInLog:=true; + if Assigned(ResFiles) and (ResFiles.Count>0) then begin + grp:=prj.mainGroup.addSubGroup('Resources'); // name must match to the target name! + //grp:=pgrp.addSubGroup('Supporting Files'); // name must match! + + res := PBXResourcesBuildPhase.Create; + res.buildActionMask:=2147483647; + //res.name:='Resources'; + trg.buildPhases.Add(res); + for i:=0 to ResFiles.Count-1 do begin + fnm:='../'+ResFiles[i]; + fr:=FileRefCreate(fnm, FILETYPE_MACHO); + fr.sourceTree:=SRCTREE_PROJECT; + grp.children.add(fr); + + fbld := PBXBuildFile.Create; + fbld.fileRef:=fr; + res.files.Add(fbld); + end; + end; + UpdateMainFile(prj, main); UpdateCompileOpts(prj, TemplateValues.Values['projoptions']);