iphonelazext: fixing the warning (ansi to wide, wide to ansi) shown on fpc 3. Updating building script. Forcing to use the script file on Xcode project generation. Using custom options in Xcode project. Fix resolving of project paths

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5045 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
skalogryz
2016-07-29 03:34:23 +00:00
parent 43a1354fe2
commit 70fe3a5109
11 changed files with 224 additions and 88 deletions

View File

@ -1,31 +1,93 @@
## start
## The script builds the project for both 32 and 64-bit architectures
## It's requirement for Apple to support both arm32 and arm64 for a device
## Some Simulators might still be 32-bit (iPhone4, iPads), thus both x86 and x86_64
## are compiled
echo "compiling FPC project"
export RESULT_EXE=${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}
export IOSHEADERS=
cd $FPC_MAIN_DIR
#rm $RESULT_EXE
export TargetCPU=${PLATFORM_PREFERRED_ARCH}
export TargetCPU=${PLATFORM_PREFERRED_ARCH}
## default compile options, assuming ARM
export OPT32=${FPC_OPT_A32}
export OPT64=${FPC_OPT_A64}
export CPU32="arm"
export CPU64="aarch64"
export TargetOS="darwin"
## Simulator has been selected in Xcode project
## switching options to Intel
if [ "${PLATFORM_NAME}" == "iphonesimulator" ]; then
export TargetOS="iphonesim"
export OPT32=${FPC_OPT_I32}
export OPT64=${FPC_OPT_I64}
export CPU32="i386"
export CPU64="x86_64"
export TargetOS="iphonesim"
fi
## 64-bit compilation
export Result64=${RESULT_EXE}_64
export TargetCPU=${CPU64}
export Target=${TargetCPU}-${TargetOS}
pwd
echo ${RESULT_EXE}
## making output directory
export outdir=lib/${Target}
mkdir -p ${outdir}
## debugging echo
echo ${FPC_DIR}fpc -T${TargetOS} -P${TargetCPU} \
${FPC_CUSTOM_OPTIONS} ${OPT64} \
-Filib/${Target} -FUlib/${Target} \
-XR${SDKROOT} -FD${PLATFORM_DEVELOPER_BIN_DIR} $FPC_MAIN_FILE \
-o${Result64}
${FPC_DIR}fpc -T${TargetOS} -P${TargetCPU} \
${FPC_CUSTOM_OPTIONS} ${OPT64} \
-Filib/${Target} -FUlib/${Target} \
-XR${SDKROOT} -FD${PLATFORM_DEVELOPER_BIN_DIR} $FPC_MAIN_FILE \
-o${Result64}
${FPC_DIR}fpc -T${TargetOS} -P${TargetCPU} -MDelphi -Scghi -O1 -l -dIPHONEALL \
${FPC_CUSTOM_OPTIONS} \
-Filib/${Target} -FUlib/${Target} \
-XR${SDKROOT} -FD${PLATFORM_DEVELOPER_BIN_DIR} $FPC_MAIN_FILE \
-o${RESULT_EXE}
export RES=$?
## if compiler returned an error, stop the script and exit with error
if [ $RES != 0 ]; then
exit $RES
fi
echo ${RESULT_EXE}
exit $FPCRES
## 32-bit complication
export Result32=${RESULT_EXE}_32
export TargetCPU=${CPU32}
export Target=${TargetCPU}-${TargetOS}
## making output directory
export outdir=lib/${Target}
mkdir -p ${outdir}
echo ${FPC_DIR}fpc -T${TargetOS} -P${TargetCPU} \
${FPC_CUSTOM_OPTIONS} ${OPT32} \
-Filib/${Target} -FUlib/${Target} \
-XR${SDKROOT} -FD${PLATFORM_DEVELOPER_BIN_DIR} $FPC_MAIN_FILE \
-o${Result32}
${FPC_DIR}fpc -T${TargetOS} -P${TargetCPU} \
${FPC_CUSTOM_OPTIONS} ${OPT32} \
-Filib/${Target} -FUlib/${Target} \
-XR${SDKROOT} -FD${PLATFORM_DEVELOPER_BIN_DIR} $FPC_MAIN_FILE \
-o${Result32}
export RES=$?
## if compiler returned an error, stop the script and exit with error
if [ $RES != 0 ]; then
exit $RES
fi
## both 32 and 64 are done, making the fat binary
lipo -create ${Result32} ${Result64} -output ${RESULT_EXE}
## removing 32 and 64 bit
rm ${Result32}
rm ${Result64}
exit $FPCRES

View File

@ -25,6 +25,7 @@ uses
Graphics, Controls, Forms, Dialogs, LazFileUtils,
{Lazarus Interface}
LazIDEIntf, MenuIntf, ProjectIntf, IDEOptionsIntf, IDEMsgIntf
,CompOptsIntf
,IDEExternToolIntf
,project_iphone_options, xcodetemplate, iphonelog_form,
@ -395,6 +396,7 @@ var
Info : TiPhoneBundleInfo;
opt : string;
prjopt : TLazCompilerOptions;
begin
// the create .plist would be used by XCode project
// the simulator .plist in created with InstallAppToSim.
@ -413,12 +415,12 @@ begin
build.Add('FPC_MAIN_FILE','"'+LazarusIDE.ActiveProject.MainFile.Filename+'"');
opt:='';
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', '\"');
end;
prjopt:=LazarusIDE.ActiveProject.LazCompilerOptions;
opt:=opt + ' ' +BreakPathsStringToOption(prjopt.GetUnitPath(true, coptParsedPlatformIndependent), '-Fu', '\"');
opt:=opt + ' ' +BreakPathsStringToOption(prjopt.GetIncludePath(true, coptParsedPlatformIndependent), '-Fi', '\"');
opt:=opt + ' ' +BreakPathsStringToOption(prjopt.GetObjectPath(true, coptParsedPlatformIndependent), '-Fo', '\"');
opt:=opt + ' ' +BreakPathsStringToOption(prjopt.GetLibraryPath(true, coptParsedPlatformIndependent), '-Fl', '\"');
opt:=opt + ' ' +prjopt.CustomOptions;
dir:=ResolveProjectPath('xcode');
dir:=dir+'/';
@ -469,6 +471,14 @@ begin
templates.Values['mainfile']:=LazarusIDE.ActiveProject.MainFile.Filename;
templates.Values['projoptions']:=opt;
if FileExists(EnvOptions.ScriptTemplate) then begin
try
DefaultBuildScript:=ReadBuildScriptFile( EnvOptions.ScriptTemplate );
except
end;
end;
if not UpdateProject(projName, templates, ProjOptions.ResFiles) then
IDEMsg(Format(strXcodeUpdFailed,[projdir]))
else

View File

@ -61,6 +61,92 @@ function RandomSpaceName: WideString;
implementation
(* Build script:
## start
echo "compiling FPC project"
export RESULT_EXE=${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}
export IOSHEADERS=
cd $FPC_MAIN_DIR
export TargetCPU=${PLATFORM_PREFERRED_ARCH}
export OPT32=${FPC_OPT_A32}
export OPT64=${FPC_OPT_A64}
export CPU32="arm"
export CPU64="aarch64"
export TargetOS="darwin"
if [ "${PLATFORM_NAME}" == "iphonesimulator" ]; then
export OPT32=${FPC_OPT_I32}
export OPT64=${FPC_OPT_I64}
export CPU32="i386"
export CPU64="x86_64"
export TargetOS="iphonesim"
fi
# 64-bit compilation
export Result64=${RESULT_EXE}_64
export TargetCPU=${CPU64}
export Target=${TargetCPU}-${TargetOS}
## making output directory
export outdir=lib/${Target}
mkdir -p ${outdir}
echo ${FPC_DIR}fpc -T${TargetOS} -P${TargetCPU} -MDelphi -Scghi -O3 -l -dIPHONEALL \
${FPC_CUSTOM_OPTIONS} ${OPT64} \
-Filib/${Target} -FUlib/${Target} \
-XR${SDKROOT} -FD${PLATFORM_DEVELOPER_BIN_DIR} $FPC_MAIN_FILE \
-o${Result64}
${FPC_DIR}fpc -T${TargetOS} -P${TargetCPU} -MDelphi -Scghi -O3 -l -dIPHONEALL \
${FPC_CUSTOM_OPTIONS} ${OPT64} \
-Filib/${Target} -FUlib/${Target} \
-XR${SDKROOT} -FD${PLATFORM_DEVELOPER_BIN_DIR} $FPC_MAIN_FILE \
-k-F/Users/dmitry/FPC_laz/paseng/tests/testBomber3UI -k-t \
-o${Result64}
export RES=$?
if [ $RES != 0 ]; then
exit $RES
fi
# 32-bit complication
export Result32=${RESULT_EXE}_32
export TargetCPU=${CPU32}
export Target=${TargetCPU}-${TargetOS}
## making output directory
export outdir=lib/${Target}
mkdir -p ${outdir}
echo ${FPC_DIR}fpc -T${TargetOS} -P${TargetCPU} -MDelphi -Scghi -Cg -O3 -l -dIPHONEALL \
${FPC_CUSTOM_OPTIONS} ${OPT32} \
-Filib/${Target} -FUlib/${Target} \
-XR${SDKROOT} -FD${PLATFORM_DEVELOPER_BIN_DIR} $FPC_MAIN_FILE \
-k-F/Users/dmitry/FPC_laz/paseng/tests/testBomber3UI \
-o${Result32}
${FPC_DIR}fpc -T${TargetOS} -P${TargetCPU} -MDelphi -Scghi -Cg -O3 -l -dIPHONEALL \
${FPC_CUSTOM_OPTIONS} ${OPT32} \
-Filib/${Target} -FUlib/${Target} \
-XR${SDKROOT} -FD${PLATFORM_DEVELOPER_BIN_DIR} $FPC_MAIN_FILE \
-k-F/Users/dmitry/FPC_laz/paseng/tests/testBomber3UI \
-o${Result32}
export RES=$?
if [ $RES != 0 ]; then
exit $RES
fi
lipo -create ${Result32} ${Result64} -output ${RESULT_EXE}
rm ${Result32}
rm ${Result64}
exit $FPCRES
*)
uses
iPhoneExtOptions;
@ -72,7 +158,7 @@ begin
CreateGUID(g);
id:=GUIDToString(g);
id:=Copy(id, 2, length(id)-2);
Result:=id;
Result:=UTF8Decode(id);
end;
@ -119,7 +205,7 @@ begin
if DirectoryExistsUTF8(p) then
Result:=UTF8Decode(p)
else if DirectoryExistsUTF8(path8) then
result:=path8
result:=UTF8Decode(path8)
else
result :='';
end;
@ -145,7 +231,7 @@ var
begin
s := EnvOptions.SimAppsPath;
EnvOptions.SubstituteMacros(s);
result := s;
result := UTF8Decode(s);
end;
{
@ -226,12 +312,13 @@ var
pl : TPListFile;
arr : TPListValue;
begin
Result:=false;
pl := TPListFile.Create;
try
if not FileExists(InfoFileName) then begin
InitDefaultPlist(pl);
end else
LoadFromFile(InfoFileName, pl);
LoadFromFile( UTF8Encode(InfoFileName), pl);
SetStr(pl, 'CFBundleDisplayName', info.DisplayName);
SetStr(pl, 'CFBundleExecutable', ExeName);
SetStr(pl, 'CFBundleIdentifier', info.AppID);
@ -241,7 +328,7 @@ begin
SetStr(pl, 'DTPlatformName', info.iPlatform);
SetStr(pl, 'DTSDKName', info.SDKVersion);
SaveToXMLFile(pl, InfoFileName);
Result:=SaveToXMLFile(pl, UTF8Encode(InfoFileName));
finally
pl.Free;
end;
@ -260,7 +347,7 @@ const
' <key>CFBundleIdentifier</key>'#10+ ' <string>%s</string>'#10+ {company + bundle name}
' <key>CFBundleInfoDictionaryVersion</key>'#10+ ' <string>6.0</string>'#10+
' <key>CFBundleName</key>'#10+ ' <string>%s</string>'#10+ {bundle name}
' <key>CFBundlePackageType</key>'#10+ ' <string>APPL</string>'#10+
' <key>CFBundlePackageType</key>'#10+ ' <string>APPL</string>'#10+ // must be present for AppStore deployment!
' <key>CFBundleSignature</key>'#10+ ' <string>????</string>'#10+
' <key>CFBundleSupportedPlatforms</key>'#10+ ' <array>'#10+' <string>%s</string>'#10+' </array>'#10+ {platform}
'%s'+ // optional MainNib name

View File

@ -21,7 +21,7 @@ interface
uses
Classes, SysUtils, IDEOptionsIntf, LazIDEIntf, ProjectIntf, MacroIntf,
iPhoneBundle, XMLConf, XcodeUtils, PlistFile
iPhoneBundle, XMLConf, XcodeUtils
, LazFileUtils, LazFilesUtils
, iphonesimctrl, xcodeproj;
@ -306,15 +306,15 @@ begin
try
xmlcfg.RootName:='config';
xmlcfg.Filename:=XMLFileName;
fPlatformsBaseDir := UTF8Encode(xmlcfg.GetValue('Platforms', fPlatformsBaseDir ));
fCompilerPath := UTF8Encode(xmlcfg.GetValue('Compiler', fCompilerPath));
fBaseRTLPath := UTF8Encode(xmlcfg.GetValue('RTLPath', fBaseRTLPath));
fCommonOpt := UTF8Encode(xmlcfg.GetValue('CompilerOptions', fCommonOpt));
fSimBundle := UTF8Encode(xmlcfg.GetValue('SimBundle', fSimBundle));
fSimAppsPath := UTF8Encode(xmlcfg.GetValue('SimAppPath', fSimAppsPath));
fDefaultSDK := UTF8Encode(xmlcfg.GetValue('DefaultSDK', fDefaultSDK));
fDefaultDeviceID := UTF8Encode(xmlcfg.GetValue('DefaultDevice', fDefaultDeviceID));
fScriptTemplate := UTF8Encode(xmlcfg.GetValue('ScriptTemplate', fScriptTemplate));
fPlatformsBaseDir := UTF8Encode(xmlcfg.GetValue('Platforms', UTF8Decode(fPlatformsBaseDir) ));
fCompilerPath := UTF8Encode(xmlcfg.GetValue('Compiler', UTF8Decode(fCompilerPath)));
fBaseRTLPath := UTF8Encode(xmlcfg.GetValue('RTLPath', UTF8Decode(fBaseRTLPath)));
fCommonOpt := UTF8Encode(xmlcfg.GetValue('CompilerOptions', UTF8Decode(fCommonOpt)));
fSimBundle := UTF8Encode(xmlcfg.GetValue('SimBundle', UTF8Decode(fSimBundle)));
fSimAppsPath := UTF8Encode(xmlcfg.GetValue('SimAppPath', UTF8Decode(fSimAppsPath)));
fDefaultSDK := UTF8Encode(xmlcfg.GetValue('DefaultSDK', UTF8Decode(fDefaultSDK)));
fDefaultDeviceID := UTF8Encode(xmlcfg.GetValue('DefaultDevice', UTF8Decode(fDefaultDeviceID)));
fScriptTemplate := UTF8Encode(xmlcfg.GetValue('ScriptTemplate', UTF8Decode(fScriptTemplate)));
RefreshVersions;
if (fDefaultSDK = '') and (fVersions.Count>0) then

View File

@ -24,7 +24,7 @@
</CodeGeneration>
<Other>
<CompilerMessages>
<IgnoredMessages idx5091="True" idx5060="True" idx5057="True" idx5024="True" idx4081="True" idx4080="True" idx4079="True" idx4055="True"/>
<IgnoredMessages idx5091="True" idx5060="True" idx5057="True" idx5028="True" idx5024="True" idx4081="True" idx4080="True" idx4079="True" idx4055="True"/>
</CompilerMessages>
</Other>
</CompilerOptions>

View File

@ -267,7 +267,6 @@ var
l : string;
st : TStringList;
i : integer;
j : integer;
ip : string; // install path
fp : string; // content path
begin

View File

@ -711,7 +711,7 @@ const
FlagGet = 3; // 1 + 2 //ptField = 0;
FlagSet = 12; // 4 + 8 , 16 + 32 //ptStatic = 1;
FlagSP = 16 + 32; //ptVirtual = 2;
FlagIdx = 64; //ptConst = 3; }
FlagIdx = 64; //ptConst = 3;
begin
if (not Assigned(obj)) or (not Assigned(srz)) then Exit;

View File

@ -698,7 +698,7 @@ end;
function ProjectCreateMin: PBXProject;
var
p : PBXProject;
cfg : XCBuildConfiguration;
//cfg : XCBuildConfiguration;
begin
// requirements:
// * at least one build configuration
@ -709,8 +709,8 @@ begin
p.buildConfigurationList._headerComment:='Build configuration list for PBXProject';
p.buildConfigurationList.defaultConfigurationIsVisible:='0';
cfg:=p.buildConfigurationList.addConfig('Debug');
cfg:=p.buildConfigurationList.addConfig('Release');
p.buildConfigurationList.addConfig('Debug');
p.buildConfigurationList.addConfig('Release');
// default name must be present
p.buildConfigurationList.defaultConfigurationName:='Release';
Result:=p;

View File

@ -145,7 +145,6 @@ var
res : integer;
{$ifdef darwin}
xs : string;
err : LongWord;
m : TStringStream;
doc : TXMLDocument;
{$endif}
@ -255,7 +254,7 @@ begin
ltDict: begin
dst.Add(pfx+'<dict>');
for i:=0 to v.count-1 do begin
dst.Add(XMLPFX+'<key>'+XMLEncodeText(v.names[i])+'</key>');
dst.Add(XMLPFX+'<key>'+XMLEncodeText(UTF8Decode(v.names[i]))+'</key>');
WriteXMLValue(v.items[i], dst, pfx+XMLPFX);
end;
dst.Add(pfx+'</dict>');
@ -374,7 +373,7 @@ var
begin
Result:=nil;
if not Assigned(valnode) then Exit;
if not NodeNameToPListType(valnode.NodeName, tp) then Exit;
if not NodeNameToPListType( UTF8Encode(valnode.NodeName), tp) then Exit;
Result:=TPListValue.Create(tp);
case tp of
ltBoolean: Result.bool:=(valnode.NodeName='true'); // false is false

View File

@ -28,7 +28,7 @@ function UpdateProject(const ProjFileName: string; TemplateValues, ResFiles: TSt
procedure UpdateBldConfig(const proj: PBXProject; optName, optVal: string);
procedure UpdateMainFile(const proj: PBXProject; mainfile: string);
procedure UpdateCompileOpts(const proj: PBXProject; const options: string);
procedure UpdateCompileOpts(const proj: PBXProject; const aoptions: string);
const
XCodeProjectTemplateIconID : AnsiString ='0AE3FFA610F3C9AF00A9B007,';
@ -206,43 +206,19 @@ const
' rootObject = 0A52AE8310F0D05300478C4F /* Project object */;'#10+
'}'#10;
BuildScript =
'## start'#13
+'echo "compiling FPC project"'#13
+''#13
+'export RESULT_EXE=${BUILT_PRODUCTS_DIR}/${EXECUTABLE_PATH}'#13
+'export IOSHEADERS='#13
+'cd $FPC_MAIN_DIR'#13
+'#rm $RESULT_EXE'#13
+'export TargetCPU=${PLATFORM_PREFERRED_ARCH}'#13
+''#13
+'if [ "${PLATFORM_NAME}" == "iphonesimulator" ]; then'#13
+' export TargetOS="iphonesim"'#13
+'fi'#13
+'export Target=${TargetCPU}-${TargetOS}'#13
+''#13
+'pwd'#13
+'echo ${RESULT_EXE}'#13
+''#13
+'${FPC_DIR}fpc -T${TargetOS} -P${TargetCPU} -MDelphi -Scghi -O1 -l -dIPHONEALL \'#13
+' ${FPC_CUSTOM_OPTIONS} \'#13
//-Fu~/iOS_6_0 -Fu.
+'-Filib/${Target} -FUlib/${Target} \'#13
+'-XR${SDKROOT} -FD${PLATFORM_DEVELOPER_BIN_DIR} $FPC_MAIN_FILE \'#13
+' -o${RESULT_EXE}'#13
+'export RES=$?'#13
+''#13
+'if [ $RES != 0 ]; then'#13
+' exit $RES'#13
+'fi'#13
+''#13
+'echo ${RESULT_EXE}'#13
+''#13
+'exit $FPCRES'#13;
var
// global variable... a bad pattern must be replaced
DefaultBuildScript : string = '';
function ReadBuildScriptFile(const fn: string): string;
implementation
function EmptyBuildScript: string;
begin
Result:='';
end;
function GetValueName(const Source: String; idx: Integer): String;
var
i : integer;
@ -355,8 +331,9 @@ begin
Result:=StringReplace(Result, '$(TargetOS)', os, [rfReplaceAll, rfIgnoreCase]);
end;
procedure UpdateCompileOpts(const proj: PBXProject; const options: string);
procedure UpdateCompileOpts(const proj: PBXProject; const aoptions: string);
var
options : string;
opt : string;
i32opt : string;
i64opt : string;
@ -367,6 +344,7 @@ var
begin
//UpdateBldConfig(proj, 'FPC_CUSTOM_OPTIONS', options);
UpdateBldConfig(proj, 'FPC_CUSTOM_OPTIONS', '');
options:=aoptions+' '; // trailing space, always to consume the last options
i:=1;
j:=1;
l:=length(options);
@ -521,7 +499,7 @@ begin
if not Assigned(TargetFindRunScript(trg)) then begin
scr:=TargetAddRunScript(trg);
scr.shellScript:=BuildScript;
scr.shellScript:=DefaultBuildScript;
scr.showEnvVarsInLog:=true;
end;
@ -563,8 +541,9 @@ begin
prj.Free;
Exit;
end;
end else
end else begin
prj:=ProjectCreate3_2;
end;
try
PrepareTemplateFile(prj, TemplateValues, Resfiles);

View File

@ -185,7 +185,7 @@ end;
procedure DoReadXibDoc(ADoc: TXMLDocument; var Obj: TXibObject);
const
DataNode = 'data';
//DataNode = 'data';
XibObject = 'object';
var
node : TDOMNode;
@ -288,7 +288,7 @@ begin
n:=fXibNode.FirstChild;
while Assigned(n) do begin
if (n.NodeName='string') and (TDOMElement(n).AttribStrings['key']='') then
list.Add(n.TextContent);
list.Add(UTF8Encode(n.TextContent));
n:=n.NextSibling;
end;
end;
@ -319,13 +319,13 @@ var
n : TDOMNode;
begin
n:=FindProperty(PropName);
if Assigned(n) and (n.NodeName='string') then Result:=n.TextContent
if Assigned(n) and (n.NodeName='string') then Result:=UTF8Encode(n.TextContent)
else Result:='';
end;
function isKeyAttr(n: TDomNode; const KeyAttrVal: String): Boolean;
begin
Result:=Assigned(n) and (n is TDOMElement) and (TDOMElement(n).AttribStrings['key']=KeyAttrVal)
Result:=Assigned(n) and (n is TDOMElement) and (TDOMElement(n).AttribStrings['key']=UTF8Decode(KeyAttrVal))
end;
function TXibObject.FindProperty(const PropName:String):TDOMNode;
@ -344,7 +344,7 @@ begin
Result:='';
Exit;
end;
Result:=TDOMElement(fXibNode).AttribStrings['key'];
Result:=UTF8Encode(TDOMElement(fXibNode).AttribStrings['key']);
end;
function TXibObject.GetXibClass:String;
@ -353,7 +353,7 @@ begin
Result:='';
Exit;
end;
Result:=TDOMElement(fXibNode).AttribStrings['class'];
Result:=UTF8Encode(TDOMElement(fXibNode).AttribStrings['class']);
end;
procedure ListClassesDescr(const FileName: AnsiString; DstList : TList); overload;