implemented updating IDE fpc values on changing TargetCPU, cross building IDE now switches global settings, so changing project settings no longer required

git-svn-id: trunk@8330 -
This commit is contained in:
mattias 2005-12-16 16:09:31 +00:00
parent 12344a9282
commit b77cd7e3d2
7 changed files with 173 additions and 37 deletions

View File

@ -109,6 +109,7 @@ type
FExtraOptions: string;
FRestartAfterBuild: boolean;
FConfirmBuild: boolean;
FTargetCPU: string;
FTargetDirectory: string;
fTargetOS: string;
fLCLPlatform: TLCLPlatform;
@ -119,6 +120,7 @@ type
function GetItems(Index: integer): TBuildLazarusItem;
procedure SetRestartAfterBuild(const AValue: boolean);
procedure SetConfirmBuild(const AValue: boolean);
procedure SetTargetCPU(const AValue: string);
procedure SetTargetDirectory(const AValue: string);
procedure SetTargetOS(const AValue: string);
procedure SetWithStaticPackages(const AValue: boolean);
@ -149,6 +151,7 @@ type
property CleanAll: boolean read FCleanAll write FCleanAll;
property ExtraOptions: string read FExtraOptions write FExtraOptions;
property TargetOS: string read fTargetOS write SetTargetOS;
property TargetCPU: string read FTargetCPU write SetTargetCPU;
property LCLPlatform: TLCLPlatform read fLCLPlatform write fLCLPlatform;
property StaticAutoInstallPackages: TStringList
read fStaticAutoInstallPackages;
@ -325,6 +328,9 @@ begin
// append target OS
if Options.TargetOS<>'' then
Tool.CmdLineParams:=Tool.CmdLineParams+' OS_TARGET='+Options.TargetOS;
// append target CPU
if Options.TargetCPU<>'' then
Tool.CmdLineParams:=Tool.CmdLineParams+' CPU_TARGET='+Options.TargetCPU;
Result:=ExternalTools.Run(Tool,Macros);
if Result<>mrOk then exit;
end;
@ -359,6 +365,9 @@ begin
// append target OS
if Options.TargetOS<>'' then
Tool.CmdLineParams:=Tool.CmdLineParams+' OS_TARGET='+Options.TargetOS;
// append target CPU
if Options.TargetCPU<>'' then
Tool.CmdLineParams:=Tool.CmdLineParams+' CPU_TARGET='+Options.TargetCPU;
// don't run svn2revisioninc when building the IDE for the second time
if not (blfWithoutLinkingIDE in Flags) then
Tool.CmdLineParams:=Tool.CmdLineParams+' USESVN2REVISIONINC=0';
@ -416,6 +425,7 @@ var
NewTargetFilename: String;
NewTargetDirectory: String;
DefaultTargetOS: string;
DefaultTargetCPU: string;
begin
Result:=mrOk;
CurItem:=Options.Items[ItemIndex];
@ -477,14 +487,17 @@ begin
// => find it automatically
DefaultTargetOS:={$I %FPCTARGETOS%};
if (Options.TargetOS<>'')
and (CompareText(Options.TargetOS,DefaultTargetOS)<>0) then
DefaultTargetCPU:={$I %FPCTARGETCPU%};
if ((Options.TargetOS<>'')
and (CompareText(Options.TargetOS,DefaultTargetOS)<>0))
or ((Options.TargetCPU<>'')
and (CompareText(Options.TargetCPU,DefaultTargetCPU)<>0)) then
begin
// Case 2. crosscompiling the IDE
// create directory <primary config dir>/bin/<TargetOS>
// create directory <primary config dir>/bin/<TargetCPU>-<TargetOS>
NewTargetDirectory:=AppendPathDelim(GetPrimaryConfigPath)+'bin'
+PathDelim+Options.TargetOS;
debugln('CreateBuildLazarusOptions Options.TargetOS=',Options.TargetOS,' DefaultOS=',DefaultTargetOS);
+PathDelim+Options.TargetCPU+'-'+Options.TargetOS;
debugln('CreateBuildLazarusOptions Options.TargetOS=',Options.TargetOS,' Options.TargetCPU=',Options.TargetCPU,' DefaultOS=',DefaultTargetOS,' DefaultCPU=',DefaultTargetCPU);
Result:=ForceDirectoryInteractive(NewTargetDirectory,[]);
if Result<>mrOk then exit;
end else begin
@ -1147,6 +1160,7 @@ begin
XMLConfig.SetDeleteValue(Path+'CleanAll/Value',FCleanAll,true);
XMLConfig.SetDeleteValue(Path+'ExtraOptions/Value',FExtraOptions,'');
XMLConfig.SetDeleteValue(Path+'TargetOS/Value',TargetOS,'');
XMLConfig.SetDeleteValue(Path+'TargetCPU/Value',TargetCPU,'');
XMLConfig.SetDeleteValue(Path+'LCLPlatform/Value',
LCLPlatformNames[fLCLPlatform],
GetDefaultLCLWidgetType);
@ -1175,6 +1189,7 @@ begin
CleanAll:=Source.CleanAll;
ExtraOptions:=Source.ExtraOptions;
TargetOS:=Source.TargetOS;
TargetCPU:=Source.TargetCPU;
LCLPlatform:=Source.LCLPlatform;
TargetDirectory:=Source.TargetDirectory;
WithStaticPackages:=Source.WithStaticPackages;
@ -1242,6 +1257,7 @@ begin
FCleanAll:=XMLConfig.GetValue(Path+'CleanAll/Value',true);
FExtraOptions:=XMLConfig.GetValue(Path+'ExtraOptions/Value','');
TargetOS:=XMLConfig.GetValue(Path+'TargetOS/Value','');
TargetCPU:=XMLConfig.GetValue(Path+'TargetCPU/Value','');
fLCLPlatform:=StrToLCLPlatform(XMLConfig.GetValue(Path+'LCLPlatform/Value',
GetDefaultLCLWidgetType));
FTargetDirectory:=AppendPathDelim(SetDirSeparators(
@ -1291,6 +1307,13 @@ begin
FConfirmBuild:=AValue;
end;
procedure TBuildLazarusOptions.SetTargetCPU(const AValue: string);
begin
if FTargetCPU=AValue then exit;
FTargetCPU:=AValue;
FGlobals.TargetCPU:=TargetCPU;
end;
procedure TBuildLazarusOptions.SetWithStaticPackages(const AValue: boolean);
begin
if FWithStaticPackages=AValue then exit;
@ -1324,6 +1347,7 @@ begin
FExtraOptions:='';
FTargetDirectory:=DefaultTargetDirectory;
TargetOS:='';
TargetCPU:='';
fLCLPlatform:=StrToLCLPlatform(GetDefaultLCLWidgetType);
// auto install packages

View File

@ -2450,6 +2450,9 @@ var
begin
if ParsedStamp[Option]<>CompilerParseStamp then begin
s:=UnparsedValues[Option];
//if Option=pcosCustomOptions then begin
// DebugLn('TParsedCompilerOptions.GetParsedValue START ',dbgs(ParsedStamp[Option]),' ',dbgs(CompilerParseStamp),' unparsed="',s,'" old="',ParsedValues[Option],'"');
//end;
// parse locally
if Assigned(OnLocalSubstitute) then s:=OnLocalSubstitute(s);
// parse globally
@ -2486,6 +2489,9 @@ begin
end;
ParsedValues[Option]:=s;
ParsedStamp[Option]:=CompilerParseStamp;
//if Option=pcosCustomOptions then begin
// DebugLn('TParsedCompilerOptions.GetParsedValue PARSED ',dbgs(ParsedStamp[Option]),' ',dbgs(CompilerParseStamp),' new="',ParsedValues[Option],'"');
//end;
end;
Result:=ParsedValues[Option];
end;

View File

@ -1075,7 +1075,7 @@ begin
// check for change and save
if not OldCompOpts.IsEqual(Options) then begin
Options.Modified:=true;
IncreaseCompilerGraphStamp;
IncreaseCompilerParseStamp;
end;
OldCompOpts.Free;
end;
@ -1151,16 +1151,20 @@ begin
with AncestorOptions.ParsedOpts do begin
AddChildNode(lisunitPath,
CreateRelativeSearchPath(GetParsedValue(pcosUnitPath),
CompilerOpts.BaseDirectory),icoUnitPath);
CompilerOpts.BaseDirectory),
icoUnitPath);
AddChildNode(lisincludePath,
CreateRelativeSearchPath(GetParsedValue(pcosIncludePath),
CompilerOpts.BaseDirectory),icoIncludePath);
CompilerOpts.BaseDirectory),
icoIncludePath);
AddChildNode(lisobjectPath,
CreateRelativeSearchPath(GetParsedValue(pcosObjectPath),
CompilerOpts.BaseDirectory),icoObjectPath);
CompilerOpts.BaseDirectory),
icoObjectPath);
AddChildNode(lislibraryPath,
CreateRelativeSearchPath(GetParsedValue(pcosLibraryPath),
CompilerOpts.BaseDirectory),icoLibraryPath);
CompilerOpts.BaseDirectory),
icoLibraryPath);
AddChildNode(lislinkerOptions, GetParsedValue(pcosLinkerOptions),
icoLinkerOptions);
AddChildNode(liscustomOptions, GetParsedValue(pcosCustomOptions),

View File

@ -106,6 +106,7 @@ function FileIsTextCached(const AFilename: string): boolean;
procedure SplitCmdLine(const CmdLine: string;
var ProgramFilename, Params: string);
function PrepareCmdLineOption(const Option: string): string;
function AddCmdLineParameter(const CmdLine, AddParameter: string): string;
// find file
function FindFilesCaseInsensitive(const Directory,
@ -1714,6 +1715,14 @@ begin
end;
end;
function AddCmdLineParameter(const CmdLine, AddParameter: string): string;
begin
Result:=CmdLine;
if (Result<>'') and (Result[length(Result)]<>' ') then
Result:=Result+' ';
Result:=Result+AddParameter;
end;
{-------------------------------------------------------------------------------
function CommentLines(const s: string): string;

View File

@ -572,9 +572,15 @@ type
procedure OnCopyError(const ErrorData: TCopyErrorData;
var Handled: boolean; Data: TObject);
// methods fro building
procedure SetBuildTarget(const TargetOS, TargetCPU, LCLWidgetType: string);
public
CurDefinesCompilerFilename: String;
CurDefinesCompilerOptions: String;
OverrideTargetOS: string;
OverrideTargetCPU: string;
OverrideLCLWidgetType: string;
class procedure ParseCmdLineOptions;
constructor Create(TheOwner: TComponent); override;
@ -792,6 +798,9 @@ type
function IsTestUnitFilename(const AFilename: string): boolean; override;
function GetRunCommandLine: string; override;
function GetProjPublishDir: string;
function GetLCLWidgetType(UseCache: boolean): string;
function GetTargetCPU(UseCache: boolean): string;
function GetTargetOS(UseCache: boolean): string;
procedure OnMacroSubstitution(TheMacro: TTransferMacro; var s: string;
var Handled, Abort: boolean);
function OnSubstituteCompilerOption(Options: TParsedCompilerOptions;
@ -3010,6 +3019,7 @@ begin
if frmCompilerOptions.ShowModal=mrOk then begin
RescanCompilerDefines(true);
Project1.DefineTemplates.AllChanged;
IncreaseCompilerParseStamp;
end;
finally
frmCompilerOptions.Free;
@ -5071,6 +5081,46 @@ begin
end;
end;
procedure TMainIDE.SetBuildTarget(const TargetOS, TargetCPU,
LCLWidgetType: string);
var
OldTargetOS: String;
OldTargetCPU: String;
OldLCLWidgetType: String;
NewTargetOS: String;
NewTargetCPU: String;
NewLCLWidgetType: String;
FPCTargetChanged: Boolean;
LCLTargetChanged: Boolean;
begin
OldTargetOS:=GetTargetOS(true);
OldTargetCPU:=GetTargetCPU(true);
OldLCLWidgetType:=GetLCLWidgetType(true);
OverrideTargetOS:=TargetOS;
OverrideTargetCPU:=TargetCPU;
OverrideLCLWidgetType:=LCLWidgetType;
NewTargetOS:=GetTargetOS(false);
NewTargetCPU:=GetTargetCPU(false);
NewLCLWidgetType:=GetLCLWidgetType(false);
FPCTargetChanged:=(OldTargetOS<>NewTargetOS)
or (OldTargetCPU<>NewTargetCPU);
LCLTargetChanged:=(OldLCLWidgetType<>NewLCLWidgetType);
//DebugLn('TMainIDE.SetBuildTarget Old=',OldTargetCPU,'-',OldTargetOS,'-',OldLCLWidgetType,
// ' New=',NewTargetCPU,'-',NewTargetOS,'-',NewLCLWidgetType,' FPC=',dbgs(FPCTargetChanged),' LCL=',dbgs(LCLTargetChanged));
if LCLTargetChanged then
CodeToolBoss.GlobalValues.Variables[ExternalMacroStart+'LCLWidgetType']:=
NewLCLWidgetType;
if FPCTargetChanged then
RescanCompilerDefines(true);
if FPCTargetChanged or LCLTargetChanged then begin
IncreaseCompilerParseStamp;
end;
end;
function TMainIDE.DoOpenFileInSourceEditor(AnUnitInfo: TUnitInfo;
PageIndex: integer; Flags: TOpenFlags): TModalResult;
var NewSrcEdit: TSourceEditor;
@ -7470,8 +7520,11 @@ begin
end;
MessagesView.BeginBlock;
try
SetBuildTarget(MiscellaneousOptions.BuildLazOpts.TargetOS,
MiscellaneousOptions.BuildLazOpts.TargetCPU,
LCLPlatformNames[MiscellaneousOptions.BuildLazOpts.LCLPlatform]);
// first compile all lazarus components (LCL, SynEdit, CodeTools, ...)
SourceNotebook.ClearErrorLines;
Result:=BuildLazarus(MiscellaneousOptions.BuildLazOpts,
@ -7529,6 +7582,8 @@ begin
if Result<>mrOk then exit;
finally
SetBuildTarget('','','');
DoCheckFilesOnDisk;
MessagesView.EndBlock;
end;
@ -9004,23 +9059,11 @@ begin
end else if MacroName='lazarusdir' then begin
s:=EnvironmentOptions.LazarusDirectory;
end else if MacroName='lclwidgettype' then begin
if Project1<>nil then
s:=Project1.CompilerOptions.LCLWidgetType
else
s:='';
if (s='') or (s='default') then s:=GetDefaultLCLWidgetType;
s:=GetLCLWidgetType(true);
end else if MacroName='targetcpu' then begin
if Project1<>nil then
s:=lowercase(Project1.CompilerOptions.TargetCPU)
else
s:='';
if (s='') or (s='default') then s:=GetDefaultTargetCPU;
s:=GetTargetCPU(true);
end else if MacroName='targetos' then begin
if Project1<>nil then
s:=lowercase(Project1.CompilerOptions.TargetOS)
else
s:='';
if (s='') or (s='default') then s:=GetDefaultTargetOS;
s:=GetTargetOS(true);
end else if MacroName='fpcsrcdir' then begin
s:=EnvironmentOptions.FPCSourceDirectory;
end else if MacroName='comppath' then begin
@ -9549,6 +9592,45 @@ begin
end;
end;
function TMainIDE.GetLCLWidgetType(UseCache: boolean): string;
begin
if UseCache and (CodeToolBoss<>nil) then begin
Result:=CodeToolBoss.GlobalValues.Variables[ExternalMacroStart+'LCLWidgetType'];
end else begin
if OverrideLCLWidgetType<>'' then
Result:=OverrideLCLWidgetType
else if Project1<>nil then
Result:=lowercase(Project1.CompilerOptions.LCLWidgetType)
else
Result:='';
end;
if (Result='') or (Result='default') then Result:=GetDefaultLCLWidgetType;
end;
function TMainIDE.GetTargetCPU(UseCache: boolean): string;
begin
if UseCache then ;
if OverrideTargetCPU<>'' then
Result:=OverrideTargetCPU
else if Project1<>nil then
Result:=lowercase(Project1.CompilerOptions.TargetCPU)
else
Result:='';
if (Result='') or (Result='default') then Result:=GetDefaultTargetCPU;
end;
function TMainIDE.GetTargetOS(UseCache: boolean): string;
begin
if UseCache then ;
if OverrideTargetOS<>'' then
Result:=OverrideTargetOS
else if Project1<>nil then
Result:=lowercase(Project1.CompilerOptions.TargetOS)
else
Result:='';
if (Result='') or (Result='default') then Result:=GetDefaultTargetOS;
end;
function TMainIDE.FindUnitFile(const AFilename: string): string;
var
SearchPath, ProjectDir: string;
@ -10129,8 +10211,8 @@ begin
EnvironmentOptions.LazarusDirectory;
Variables[ExternalMacroStart+'FPCSrcDir']:=
EnvironmentOptions.FPCSourceDirectory;
Variables[ExternalMacroStart+'LCLWidgetType']:=GetDefaultLCLWidgetType;
Variables[ExternalMacroStart+'ProjPath']:=VirtualDirectory;
Variables[ExternalMacroStart+'LCLWidgetType']:=GetDefaultLCLWidgetType;
end;
// build DefinePool and Define Tree
@ -10219,11 +10301,16 @@ var
TargetOS, TargetProcessor: string;
UnitLinksValid: boolean;
i: Integer;
CurTargetOS: String;
CurTargetCPU: String;
begin
if Project1.CompilerOptions.TargetOS<>'' then
CurOptions:='-T'+Project1.CompilerOptions.TargetOS
else
CurOptions:='';
CurOptions:='';
CurTargetOS:=GetTargetOS(false);
if CurTargetOS<>'' then
CurOptions:=AddCmdLineParameter(CurOptions,'-T'+CurTargetOS);
CurTargetCPU:=GetTargetCPU(false);
if CurTargetCPU<>'' then
CurOptions:=AddCmdLineParameter(CurOptions,'-d'+CurTargetCPU);
{$IFDEF VerboseFPCSrcScan}
writeln('TMainIDE.RescanCompilerDefines A ',CurOptions,
' OnlyIfCompilerChanged=',OnlyIfCompilerChanged,

View File

@ -3776,15 +3776,20 @@ var
Changed: Boolean;
begin
Changed:=false;
Changed:=Changed or CodeToolBoss.SetGlobalValue(
ExternalMacroStart+'LCLWidgetType',
Owner.CompilerOptions.GetEffectiveLCLWidgetType);
if CodeToolBoss.SetGlobalValue(ExternalMacroStart+'LCLWidgetType',
Owner.CompilerOptions.GetEffectiveLCLWidgetType)
then begin
DebugLn('TProjectDefineTemplates.UpdateGlobalValues '
,' LCLWidgetType="',CodeToolBoss.GlobalValues.Variables[ExternalMacroStart+'LCLWidgetType'],'" Effective="',Owner.CompilerOptions.GetEffectiveLCLWidgetType,'" Options="',Owner.CompilerOptions.LCLWidgetType,'"');
Changed:=true;
end;
if Owner.IsVirtual then
NewProjectDir:=VirtualDirectory
else
NewProjectDir:=Owner.ProjectDirectory;
Changed:=Changed or CodeToolBoss.SetGlobalValue(
ExternalMacroStart+'ProjPath',NewProjectDir);
if CodeToolBoss.SetGlobalValue(ExternalMacroStart+'ProjPath',NewProjectDir)
then
Changed:=true;
if Changed then
IncreaseCompilerParseStamp;
end;

View File

@ -1137,6 +1137,8 @@ begin
end;
function GetUsageOptionsList(PackageList: TList): TList;
// returns a list of TPkgAdditionalCompilerOptions
// from the list of TLazPackage
var
Cnt: Integer;
i: Integer;
@ -2151,7 +2153,6 @@ begin
FDefineTemplates:=TLazPackageDefineTemplates.Create(Self);
fPublishOptions:=TPublishPackageOptions.Create(Self);
Clear;
FCompilerOptions.ParsedOpts.InvalidateGraphOnChange:=true;
FUsageOptions.ParsedOpts.InvalidateGraphOnChange:=true;
end;