IDE: Create extra buildmodes better.

git-svn-id: trunk@51162 -
This commit is contained in:
juha 2016-01-03 14:53:10 +00:00
parent dae6a4f4b0
commit 1c326b667f
2 changed files with 56 additions and 52 deletions

View File

@ -30,9 +30,11 @@ unit BuildModesManager;
interface
uses
Classes, SysUtils, Forms, Controls, Dialogs, StdCtrls, Grids, Menus, ComCtrls,
ButtonPanel, LCLProc, IDEOptionsIntf, IDEDialogs, TransferMacros, Project,
CompOptsIntf, CompilerOptions, Compiler_ModeMatrix, BuildModeDiffDlg, LazarusIDEStrConsts;
Classes, SysUtils,
Forms, Controls, Dialogs, StdCtrls, Grids, Menus, ComCtrls, ButtonPanel, LCLProc,
IDEOptionsIntf, IDEDialogs, CompOptsIntf,
TransferMacros, Project, CompilerOptions, Compiler_ModeMatrix, BuildModeDiffDlg,
EnvironmentOpts, LazarusIDEStrConsts;
type
@ -109,10 +111,6 @@ procedure UpdateBuildModeCombo(aCombo: TComboBox);
implementation
const
DebugModeName = 'Debug';
ReleaseModeName = 'Release';
{$R *.lfm}
function ShowBuildModesDlg(aShowSession: Boolean): TModalResult;
@ -233,32 +231,6 @@ end;
procedure TBuildModesForm.btnCreateDefaultModesClick(Sender: TObject);
var
CurMode: TProjectBuildMode;
procedure AssignAndSetBooleans(aMode: TProjectBuildMode; IsDebug: Boolean);
begin
if CurMode<>nil then
aMode.Assign(CurMode); // clone from currently selected mode
with aMode.CompilerOptions do
begin
// Smart linking
SmartLinkUnit:=not IsDebug;
LinkSmart:=not IsDebug;
// Checks
IOChecks:=IsDebug;
RangeChecks:=IsDebug;
OverflowChecks:=IsDebug;
StackChecks:=IsDebug;
IncludeAssertionCode:=IsDebug;
// Debug flags
GenerateDebugInfo:=IsDebug;
UseExternalDbgSyms:=IsDebug;
UseHeaptrc:=IsDebug;
TrashVariables:=IsDebug;
end;
end;
var
NewMode: TProjectBuildMode;
i: Integer;
begin
i:=BuildModesStringGrid.Row-1;
@ -266,20 +238,8 @@ begin
CurMode:=fBuildModes[i]
else
CurMode:=nil;
// Create Debug mode
NewMode:=fBuildModes.Add(DebugModeName);
AssignAndSetBooleans(NewMode, True);
NewMode.CompilerOptions.OptimizationLevel:=1; // Optimization
NewMode.CompilerOptions.DebugInfoType:=dsDwarf2Set; // Debug
fActiveBuildMode:=NewMode; // activate Debug mode
// Create Release mode
NewMode:=fBuildModes.Add(ReleaseModeName);
AssignAndSetBooleans(NewMode, False);
NewMode.CompilerOptions.OptimizationLevel:=3; // Optimization, slow, but safe, -O4 is dangerous
NewMode.CompilerOptions.DebugInfoType:=dsAuto; // Debug
// Create Debug and Release modes, activate Debug mode
fActiveBuildMode:=fBuildModes.CreateExtraModes(CurMode);
FillBuildModesGrid; // show
// select identifier
BuildModesStringGrid.Col:=fModeNameCol;
@ -540,9 +500,8 @@ begin
ToolButtonMoveDown.Hint:=Format(lisMoveOnePositionDown, [Identifier]);
ToolButtonDiff.Hint:=lisShowDifferencesBetweenModes;
NoteLabel.Caption:='';
// ToDo: Save in Environment options and use for new projects.
cbDebugReleaseProject.Caption:=lisCreateDebugAndReleaseModesNewProj;
cbDebugReleaseProject.Hint:='Under Construction ...'; // Remove this when implemented.
//cbDebugReleaseProject.Hint:='Under Construction ...'; // Remove this when implemented.
btnCreateDefaultModes.Caption:=lisCreateNowForThisProject;
btnCreateDefaultModes.Hint:=''; // ToDo: Figure out a good hint.
@ -614,7 +573,7 @@ end;
procedure TBuildModesForm.cbDebugReleaseProjectClick(Sender: TObject);
begin
(Sender as TCheckBox).Checked := False;
//(Sender as TCheckBox).Checked := False;
end;
procedure TBuildModesForm.BuildModesStringGridDrawCell(Sender: TObject;

View File

@ -103,6 +103,9 @@ type
const
AllUnitCompDependencyTypes = [low(TUnitCompDependencyType)..high(TUnitCompDependencyType)];
// Names for extra buildmodes which may be created automatically.
DebugModeName = 'Debug';
ReleaseModeName = 'Release';
type
@ -543,8 +546,7 @@ type
function CreateDiff(CompOpts: TBaseCompilerOptions;
Tool: TCompilerDiffTool = nil): boolean; override; // true if differ
procedure InvalidateOptions;
procedure SetAlternativeCompile(const Command: string; ScanFPCMsgs: boolean
); override;
procedure SetAlternativeCompile(const Command: string; ScanFPCMsgs: boolean); override;
public
property LazProject: TProject read FProject;
property BuildMode: TProjectBuildMode read FBuildMode;
@ -652,6 +654,7 @@ type
function IsSessionMode(const ModeIdentifier: string): boolean;
function IsSharedMode(const ModeIdentifier: string): boolean;
procedure RenameMatrixMode(const OldName, NewName: string);
function CreateExtraModes(aCurMode: TProjectBuildMode): TProjectBuildMode;
// load, save
procedure LoadProjOptsFromXMLConfig(XMLConfig: TXMLConfig; const Path: string);
procedure LoadSessionFromXMLConfig(XMLConfig: TXMLConfig; const Path: string;
@ -6946,6 +6949,48 @@ begin
SessionMatrixOptions.RenameMode(OldName,NewName);
end;
function TProjectBuildModes.CreateExtraModes(aCurMode: TProjectBuildMode): TProjectBuildMode;
// Create Debug and Release buildmodes. Return the created debug mode.
// Params: aCurMode - existing mode to copy settings from.
procedure AssignAndSetBooleans(aMode: TProjectBuildMode; IsDebug: Boolean);
begin
if Assigned(aCurMode) then
aMode.Assign(aCurMode); // clone from currently selected mode
with aMode.CompilerOptions do
begin
// Smart linking
SmartLinkUnit:=not IsDebug;
LinkSmart:=not IsDebug;
// Checks
IOChecks:=IsDebug;
RangeChecks:=IsDebug;
OverflowChecks:=IsDebug;
StackChecks:=IsDebug;
IncludeAssertionCode:=IsDebug;
// Debug flags
GenerateDebugInfo:=IsDebug;
UseExternalDbgSyms:=IsDebug;
UseHeaptrc:=IsDebug;
TrashVariables:=IsDebug;
end;
end;
var
RelMode: TProjectBuildMode;
begin
// Create Debug mode
Result:=Add(DebugModeName);
AssignAndSetBooleans(Result, True);
Result.CompilerOptions.OptimizationLevel:=1; // Optimization
Result.CompilerOptions.DebugInfoType:=dsDwarf2Set; // Debug
// Create Release mode
RelMode:=Add(ReleaseModeName);
AssignAndSetBooleans(RelMode, False);
RelMode.CompilerOptions.OptimizationLevel:=3; // Optimization, slow, but safe, -O4 is dangerous
RelMode.CompilerOptions.DebugInfoType:=dsAuto; // No Debug
end;
// Methods for LoadFromXMLConfig
procedure TProjectBuildModes.AddMatrixMacro(const MacroName, MacroValue, ModeIdentifier: string;