mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-22 00:59:30 +02:00
IDE: add a GUI for compiler defines. Synchronized with Custom Options.
git-svn-id: trunk@42262 -
This commit is contained in:
parent
3882730b78
commit
e34bd5faf0
@ -187,11 +187,16 @@ type
|
||||
|
||||
TCompilerOptReader = class
|
||||
private
|
||||
// Defines (-d...) are separated from custom options and stored here.
|
||||
fDefines: TStringList;
|
||||
// All options except for defines.
|
||||
fOtherOptions: TStringList;
|
||||
// Lists of selections parsed from "fpc -i". Contains supported technologies.
|
||||
fSupportedCategories: TStringList;
|
||||
// Hierarchy of options parsed from "fpc -h".
|
||||
fRootOptGroup: TCompilerOptGroup;
|
||||
fCompilerExecutable: string;
|
||||
fCompilerVersion: string;
|
||||
fCompilerExecutable: string; // Copiler path must be set by caller.
|
||||
fCompilerVersion: string; // Parsed from "fpc -h".
|
||||
fErrorMsg: String;
|
||||
function ReadFpcWithParam(aParam: string; aLines: TStringList): TModalResult;
|
||||
procedure ReadVersion(s: string);
|
||||
@ -207,6 +212,8 @@ type
|
||||
function FromCustomOptions(aStrings: TStrings): TModalResult;
|
||||
function ToCustomOptions(aStrings: TStrings; aUseComments: Boolean): TModalResult;
|
||||
public
|
||||
property Defines: TStringList read fDefines;
|
||||
property OtherOptions: TStringList read fOtherOptions;
|
||||
property SupportedCategories: TStringList read fSupportedCategories;
|
||||
property RootOptGroup: TCompilerOptGroup read fRootOptGroup;
|
||||
property CompilerExecutable: string read fCompilerExecutable write fCompilerExecutable;
|
||||
@ -722,6 +729,8 @@ end;
|
||||
constructor TCompilerOptReader.Create;
|
||||
begin
|
||||
inherited Create;
|
||||
fDefines := TStringList.Create;
|
||||
fOtherOptions := TStringList.Create;
|
||||
fSupportedCategories := TStringList.Create;
|
||||
fRootOptGroup := TCompilerOptGroup.Create(Nil);
|
||||
end;
|
||||
@ -734,6 +743,8 @@ begin
|
||||
for i := 0 to fSupportedCategories.Count-1 do
|
||||
fSupportedCategories.Objects[i].Free;
|
||||
fSupportedCategories.Free;
|
||||
fOtherOptions.Free;
|
||||
fDefines.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@ -971,6 +982,7 @@ end;
|
||||
function TCompilerOptReader.FromCustomOptions(aStrings: TStrings): TModalResult;
|
||||
var
|
||||
i, j, CommentPos: Integer;
|
||||
HasDefine: Boolean;
|
||||
s: String;
|
||||
sl: TStringList;
|
||||
begin
|
||||
@ -984,11 +996,20 @@ begin
|
||||
CommentPos := Pos('//', s);
|
||||
if CommentPos > 0 then // Remove possible comment.
|
||||
s := TrimRight(Copy(s, 1, CommentPos));
|
||||
HasDefine := Pos('-d', s) > 0;
|
||||
if not HasDefine then
|
||||
fOtherOptions.Add(s); // Don't split the line for other options if no defines.
|
||||
sl.StrictDelimiter := True;
|
||||
sl.Delimiter := ' ';
|
||||
sl.DelimitedText := s; // Split the line with space as a separator.
|
||||
for j := 0 to sl.Count-1 do
|
||||
fRootOptGroup.SelectOption(sl[j]);
|
||||
if AnsiStartsStr('-d', sl[j]) then
|
||||
fDefines.Add(sl[j])
|
||||
else begin
|
||||
fRootOptGroup.SelectOption(sl[j]);
|
||||
if HasDefine then
|
||||
fOtherOptions.Add(sl[j]);
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
sl.Free;
|
||||
@ -1007,10 +1028,10 @@ function TCompilerOptReader.ToCustomOptions(aStrings: TStrings;
|
||||
Result := '';
|
||||
end;
|
||||
|
||||
function CopyOptions(aRoot: TCompilerOpt): integer;
|
||||
procedure CopyOptions(aRoot: TCompilerOpt);
|
||||
var
|
||||
Children: TCompilerOptList;
|
||||
i, Res: Integer;
|
||||
i: Integer;
|
||||
s: string;
|
||||
begin
|
||||
if aRoot is TCompilerOptGroup then
|
||||
@ -1024,7 +1045,7 @@ function TCompilerOptReader.ToCustomOptions(aStrings: TStrings;
|
||||
end
|
||||
else begin // TCompilerOptGroup
|
||||
for i := 0 to Children.Count-1 do // Recursive call for children.
|
||||
Res := CopyOptions(TCompilerOpt(Children[i]));
|
||||
CopyOptions(TCompilerOpt(Children[i]));
|
||||
end;
|
||||
end
|
||||
else begin // TCompilerOpt
|
||||
@ -1036,12 +1057,13 @@ function TCompilerOptReader.ToCustomOptions(aStrings: TStrings;
|
||||
aStrings.Add(aRoot.Option + aRoot.Value + PossibleComment(aRoot));
|
||||
end;
|
||||
end;
|
||||
Result := Res;
|
||||
end;
|
||||
|
||||
begin
|
||||
Result := mrOK;
|
||||
aStrings.Clear;
|
||||
Result := CopyOptions(fRootOptGroup);
|
||||
CopyOptions(fRootOptGroup);
|
||||
aStrings.AddStrings(fDefines);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
@ -702,7 +702,6 @@ object CompilerOtherOptionsFrame: TCompilerOtherOptionsFrame
|
||||
TabOrder = 2
|
||||
object memoCustomOptions: TMemo
|
||||
AnchorSideLeft.Control = grpCustomOptions
|
||||
AnchorSideRight.Control = btnAllOptions
|
||||
AnchorSideBottom.Control = grpCustomOptions
|
||||
AnchorSideBottom.Side = asrBottom
|
||||
Left = 0
|
||||
@ -713,11 +712,38 @@ object CompilerOtherOptionsFrame: TCompilerOtherOptionsFrame
|
||||
BorderSpacing.Right = 6
|
||||
TabOrder = 0
|
||||
end
|
||||
object btnAllOptions: TButton
|
||||
object Label1: TLabel
|
||||
AnchorSideRight.Control = grpCustomOptions
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 417
|
||||
Height = 15
|
||||
Top = 30
|
||||
Width = 38
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Right = 21
|
||||
Caption = 'Under'
|
||||
Font.Color = clMaroon
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
object Label2: TLabel
|
||||
AnchorSideRight.Control = grpCustomOptions
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 385
|
||||
Height = 15
|
||||
Top = 45
|
||||
Width = 91
|
||||
Anchors = [akTop, akRight]
|
||||
Caption = 'construction...'
|
||||
Font.Color = clMaroon
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
object btnAllOptions: TBitBtn
|
||||
AnchorSideRight.Control = grpCustomOptions
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 381
|
||||
Height = 25
|
||||
Height = 26
|
||||
Top = 4
|
||||
Width = 95
|
||||
Anchors = [akTop, akRight]
|
||||
@ -726,27 +752,21 @@ object CompilerOtherOptionsFrame: TCompilerOtherOptionsFrame
|
||||
OnClick = btnAllOptionsClick
|
||||
TabOrder = 1
|
||||
end
|
||||
object Label1: TLabel
|
||||
AnchorSideLeft.Control = btnAllOptions
|
||||
Left = 381
|
||||
Height = 15
|
||||
Top = 28
|
||||
Width = 38
|
||||
Caption = 'Under'
|
||||
Font.Color = clMaroon
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
end
|
||||
object Label2: TLabel
|
||||
AnchorSideLeft.Control = btnAllOptions
|
||||
Left = 381
|
||||
Height = 15
|
||||
Top = 44
|
||||
Width = 91
|
||||
Caption = 'construction...'
|
||||
Font.Color = clMaroon
|
||||
ParentColor = False
|
||||
ParentFont = False
|
||||
object btnDefines: TBitBtn
|
||||
AnchorSideTop.Control = btnAllOptions
|
||||
AnchorSideTop.Side = asrBottom
|
||||
AnchorSideRight.Control = btnAllOptions
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 399
|
||||
Height = 26
|
||||
Top = 70
|
||||
Width = 77
|
||||
Anchors = [akTop, akRight]
|
||||
AutoSize = True
|
||||
BorderSpacing.Top = 40
|
||||
Caption = 'Defines ...'
|
||||
OnClick = btnDefinesClick
|
||||
TabOrder = 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -33,14 +33,15 @@ uses
|
||||
CodeToolsCfgScript, KeywordFuncLists, LazarusIDEStrConsts,
|
||||
IDEOptionsIntf, CompOptsIntf, IDECommands, Project,
|
||||
CompilerOptions, AllCompilerOptions, EditorOptions, PackageDefs,
|
||||
SynEdit, SynEditKeyCmds, SynCompletion, SourceSynEditor;
|
||||
SynEdit, SynEditKeyCmds, SynCompletion, SourceSynEditor, CustomDefines;
|
||||
|
||||
type
|
||||
|
||||
{ TCompilerOtherOptionsFrame }
|
||||
|
||||
TCompilerOtherOptionsFrame = class(TAbstractIDEOptionsEditor)
|
||||
btnAllOptions: TButton;
|
||||
btnDefines: TBitBtn;
|
||||
btnAllOptions: TBitBtn;
|
||||
grpCustomOptions: TGroupBox;
|
||||
grpConditionals: TGroupBox;
|
||||
CondStatusbar: TStatusBar;
|
||||
@ -50,6 +51,7 @@ type
|
||||
Label2: TLabel;
|
||||
memoCustomOptions: TMemo;
|
||||
procedure btnAllOptionsClick(Sender: TObject);
|
||||
procedure btnDefinesClick(Sender: TObject);
|
||||
procedure CondSynEditChange(Sender: TObject);
|
||||
procedure CondSynEditKeyPress(Sender: TObject; var Key: char);
|
||||
procedure CondSynEditProcessUserCommand(Sender: TObject;
|
||||
@ -117,6 +119,7 @@ begin
|
||||
AllOpts.CustomOptions := memoCustomOptions.Lines;
|
||||
if AllOpts.ShowModal = mrOK then
|
||||
begin
|
||||
// Synchronize with custom options memo
|
||||
AllOpts.ToCustomOptions(memoCustomOptions.Lines);
|
||||
memoCustomOptions.Invalidate;
|
||||
end;
|
||||
@ -125,6 +128,25 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TCompilerOtherOptionsFrame.btnDefinesClick(Sender: TObject);
|
||||
var
|
||||
EditForm: TCustomDefinesForm;
|
||||
begin
|
||||
EditForm:=TCustomDefinesForm.Create(Nil);
|
||||
try
|
||||
EditForm.DefinesCheckList.Items.Assign(Project1.CustomDefines);
|
||||
EditForm.FromCustomOptions(memoCustomOptions.Lines);
|
||||
if EditForm.ShowModal=mrOK then
|
||||
begin
|
||||
Project1.CustomDefines.Assign(EditForm.DefinesCheckList.Items);
|
||||
// Synchronize with custom options memo
|
||||
EditForm.ToCustomOptions(memoCustomOptions.Lines);
|
||||
end;
|
||||
finally
|
||||
EditForm.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
// Events dealing with conditionals SynEdit :
|
||||
|
||||
procedure TCompilerOtherOptionsFrame.CondSynEditChange(Sender: TObject);
|
||||
@ -138,9 +160,8 @@ begin
|
||||
//debugln(['TCompilerOtherOptionsFrame.CondSynEditKeyPress ',ord(Key)]);
|
||||
end;
|
||||
|
||||
procedure TCompilerOtherOptionsFrame.CondSynEditProcessUserCommand(
|
||||
Sender: TObject; var Command: TSynEditorCommand; var AChar: TUTF8Char;
|
||||
Data: pointer);
|
||||
procedure TCompilerOtherOptionsFrame.CondSynEditProcessUserCommand(Sender: TObject;
|
||||
var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer);
|
||||
begin
|
||||
if (Command=ecWordCompletion) or (Command=ecIdentCompletion) then
|
||||
StartCompletion;
|
||||
@ -630,6 +651,8 @@ begin
|
||||
grpCustomOptions.Caption := lisCustomOptions2;
|
||||
memoCustomOptions.Hint := lisCustomOptHint;
|
||||
grpConditionals.Caption := lisConditionals;
|
||||
btnAllOptions.Caption := lisDlgAllOptions;
|
||||
btnDefines.Caption := lisDlgDefines;
|
||||
end;
|
||||
|
||||
procedure TCompilerOtherOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
|
||||
|
@ -6,13 +6,12 @@ object GenericListEditForm: TGenericListEditForm
|
||||
Caption = 'GenericListEditForm'
|
||||
ClientHeight = 301
|
||||
ClientWidth = 343
|
||||
OnCreate = FormCreate
|
||||
Position = poScreenCenter
|
||||
LCLVersion = '0.9.31'
|
||||
LCLVersion = '1.1'
|
||||
object ButtonPanel1: TButtonPanel
|
||||
Left = 6
|
||||
Height = 26
|
||||
Top = 269
|
||||
Height = 33
|
||||
Top = 262
|
||||
Width = 331
|
||||
OKButton.Name = 'OKButton'
|
||||
OKButton.DefaultCaption = True
|
||||
@ -30,7 +29,7 @@ object GenericListEditForm: TGenericListEditForm
|
||||
end
|
||||
object Memo1: TMemo
|
||||
Left = 0
|
||||
Height = 263
|
||||
Height = 256
|
||||
Top = 0
|
||||
Width = 343
|
||||
Align = alClient
|
||||
|
@ -15,7 +15,6 @@ type
|
||||
TGenericListEditForm = class(TForm)
|
||||
ButtonPanel1: TButtonPanel;
|
||||
Memo1: TMemo;
|
||||
procedure FormCreate(Sender:TObject);
|
||||
private
|
||||
|
||||
public
|
||||
@ -29,13 +28,5 @@ implementation
|
||||
|
||||
{$R *.lfm}
|
||||
|
||||
{ TGenericListEditForm }
|
||||
|
||||
procedure TGenericListEditForm.FormCreate(Sender:TObject);
|
||||
begin
|
||||
ButtonPanel1.OKButton.Caption:=lisMenuOk;
|
||||
ButtonPanel1.CancelButton.Caption:=lisCancel;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
@ -3144,7 +3144,6 @@ resourcestring
|
||||
lisLazBuildABOChooseOutputDir = 'Choose output directory of the IDE executable ';
|
||||
lisLazBuildDefines = 'Defines';
|
||||
lisLazBuildEditDefines = 'Edit Defines';
|
||||
lisLazBuildEditDefinesDialogCaption = 'Edit Defines';
|
||||
lisLazBuildNameOfTheActiveProfile = 'Name of the active profile';
|
||||
lisLazBuildManageProfiles2 = 'Manage profiles';
|
||||
lisLazBuildDefinesWithoutD = 'Defines without -d';
|
||||
@ -5371,6 +5370,8 @@ resourcestring
|
||||
lisHintADefaultValueCanBeDefinedInTheConditionals = 'Hint: A default value '
|
||||
+'can be defined in the conditionals.';
|
||||
lisConditionals = 'Conditionals';
|
||||
lisDlgAllOptions = 'All options ...';
|
||||
lisDlgDefines = 'Defines ...';
|
||||
lisWithIncludes = '%s, with includes %s';
|
||||
lisWithIncludes2 = ', with includes ';
|
||||
lisParsed = ', parsed ';
|
||||
|
@ -773,6 +773,7 @@ type
|
||||
FStateFlags: TLazProjectStateFlags;
|
||||
FStorePathDelim: TPathDelimSwitch;
|
||||
FUnitList: TFPList; // list of _all_ units (TUnitInfo)
|
||||
FCustomDefines: TStrings; // list of user selectable defines for custom options
|
||||
FUpdateLock: integer;
|
||||
FUseAsDefault: Boolean;
|
||||
procedure ClearBuildModes;
|
||||
@ -1078,6 +1079,7 @@ type
|
||||
property StorePathDelim: TPathDelimSwitch read FStorePathDelim write SetStorePathDelim;
|
||||
property TargetFilename: string read GetTargetFilename write SetTargetFilename;
|
||||
property Units[Index: integer]: TUnitInfo read GetUnits;
|
||||
property CustomDefines: TStrings read FCustomDefines;
|
||||
property UpdateLock: integer read FUpdateLock;
|
||||
property UseAsDefault: Boolean read FUseAsDefault write FUseAsDefault; // for dialog only (used to store options once)
|
||||
end;
|
||||
@ -2565,6 +2567,7 @@ begin
|
||||
FRunParameters:=TRunParamsOptions.Create;
|
||||
Title := '';
|
||||
FUnitList := TFPList.Create; // list of TUnitInfo
|
||||
FCustomDefines := TStringList.Create;
|
||||
|
||||
FResources := TProjectResources.Create(Self);
|
||||
ProjResources.OnModified := @EmbeddedObjectModified;
|
||||
@ -2586,6 +2589,7 @@ begin
|
||||
FreeAndNil(FAllEditorsInfoList);
|
||||
FreeThenNil(FResources);
|
||||
FreeThenNil(FBookmarks);
|
||||
FreeThenNil(FCustomDefines);
|
||||
FreeThenNil(FUnitList);
|
||||
FreeThenNil(FJumpHistory);
|
||||
FreeThenNil(FSourceDirectories);
|
||||
@ -2797,6 +2801,17 @@ function TProject.WriteProject(ProjectWriteFlags: TProjectWriteFlags;
|
||||
aConfig.SetDeleteValue(Path+'Units/Count',SaveUnitCount,0);
|
||||
end;
|
||||
|
||||
procedure SaveCustomDefines(aConfig: TXMLConfig; const Path: string);
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
for i:=0 to FCustomDefines.Count-1 do begin
|
||||
aConfig.SetDeleteValue(Path+'CustomDefines/Define'+IntToStr(i)+'/Value',
|
||||
FCustomDefines[i],'');
|
||||
end;
|
||||
aConfig.SetDeleteValue(Path+'CustomDefines/Count',FCustomDefines.Count,0);
|
||||
end;
|
||||
|
||||
procedure SaveSessionInfo(aConfig: TXMLConfig; const Path: string);
|
||||
begin
|
||||
aConfig.DeleteValue(Path+'General/ActiveEditorIndexAtStart/Value');
|
||||
@ -2966,8 +2981,11 @@ begin
|
||||
// save units
|
||||
SaveUnits(XMLConfig,Path,true,SaveSessionInfoInLPI);
|
||||
|
||||
// save session info
|
||||
if SaveSessionInfoInLPI then begin
|
||||
// save custom defines
|
||||
SaveCustomDefines(XMLConfig,Path);
|
||||
|
||||
// save session info
|
||||
SaveSessionInfo(XMLConfig,Path);
|
||||
end;
|
||||
|
||||
@ -3050,7 +3068,10 @@ begin
|
||||
// save all units
|
||||
SaveUnits(XMLConfig,Path,true,true);
|
||||
|
||||
// save session
|
||||
// save custom defines
|
||||
SaveCustomDefines(XMLConfig,Path);
|
||||
|
||||
// save session info
|
||||
SaveSessionInfo(XMLConfig,Path);
|
||||
|
||||
// notifiy hooks
|
||||
@ -3447,7 +3468,21 @@ var
|
||||
end;
|
||||
FFlags:=FFlags-[pfUseDefaultCompilerOptions];
|
||||
end;
|
||||
|
||||
|
||||
procedure LoadCustomDefines(XMLConfig: TXMLConfig; const Path: string; Merge: boolean);
|
||||
var
|
||||
Cnt, i: Integer;
|
||||
s: String;
|
||||
begin
|
||||
Cnt := XMLConfig.GetValue(Path+'CustomDefines/Count', 0);
|
||||
for i := 0 to Cnt-1 do
|
||||
begin
|
||||
s := XMLConfig.GetValue(Path+'CustomDefines/Define'+IntToStr(i)+'/Value', '');
|
||||
if s <> '' then
|
||||
FCustomDefines.Add(s);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure LoadSessionInfo(XMLConfig: TXMLConfig; const Path: string; Merge: boolean);
|
||||
var
|
||||
NewUnitInfo: TUnitInfo;
|
||||
@ -3705,6 +3740,10 @@ begin
|
||||
PublishOptions.LoadFromXMLConfig(xmlconfig,
|
||||
Path+'PublishOptions/',fPathDelimChanged);
|
||||
|
||||
// load session info
|
||||
if not LoadParts then
|
||||
LoadCustomDefines(XMLConfig,Path,false);
|
||||
|
||||
// load session info
|
||||
if not LoadParts then
|
||||
LoadSessionInfo(XMLConfig,Path,false);
|
||||
@ -3743,6 +3782,9 @@ begin
|
||||
// load MacroValues and compiler options
|
||||
LoadBuildModes(XMLConfig,Path,false);
|
||||
|
||||
// load custom defines
|
||||
LoadCustomDefines(XMLConfig,Path,true);
|
||||
|
||||
// load session info
|
||||
LoadSessionInfo(XMLConfig,Path,true);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user