diff --git a/.gitattributes b/.gitattributes index 683dc456ed..21d3adffb5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -4995,6 +4995,8 @@ ide/frames/compiler_codegen_options.lfm svneol=native#text/plain ide/frames/compiler_codegen_options.pas svneol=native#text/pascal ide/frames/compiler_compilation_options.lfm svneol=native#text/plain ide/frames/compiler_compilation_options.pas svneol=native#text/pascal +ide/frames/compiler_config_target.lfm svneol=native#text/plain +ide/frames/compiler_config_target.pas svneol=native#text/pascal ide/frames/compiler_linking_options.lfm svneol=native#text/plain ide/frames/compiler_linking_options.pas svneol=native#text/pascal ide/frames/compiler_messages_options.lfm svneol=native#text/plain diff --git a/ide/frames/compiler_config_target.lfm b/ide/frames/compiler_config_target.lfm new file mode 100644 index 0000000000..59e1864877 --- /dev/null +++ b/ide/frames/compiler_config_target.lfm @@ -0,0 +1,185 @@ +object CompilerConfigTargetFrame: TCompilerConfigTargetFrame + Left = 0 + Height = 446 + Top = 0 + Width = 594 + ClientHeight = 446 + ClientWidth = 594 + TabOrder = 0 + DesignLeft = 457 + DesignTop = 542 + object grpConfigFile: TGroupBox + Left = 0 + Height = 110 + Top = 0 + Width = 594 + Align = alTop + AutoSize = True + Caption = 'grpConfigFile' + ClientHeight = 91 + ClientWidth = 590 + TabOrder = 0 + object chkConfigFile: TCheckBox + Left = 6 + Height = 21 + Top = 6 + Width = 578 + Align = alTop + BorderSpacing.Around = 6 + Caption = 'chkConfigFile' + TabOrder = 0 + end + object chkCustomConfigFile: TCheckBox + Left = 6 + Height = 21 + Top = 33 + Width = 578 + Align = alTop + BorderSpacing.Around = 6 + Caption = 'chkCustomConfigFile' + OnClick = chkCustomConfigFileClick + TabOrder = 1 + end + object edtConfigPath: TEdit + Left = 6 + Height = 25 + Top = 60 + Width = 578 + Align = alTop + BorderSpacing.Around = 6 + TabOrder = 2 + Text = 'edtConfigPath' + end + end + object grpTargetPlatform: TGroupBox + AnchorSideBottom.Side = asrBottom + Left = 0 + Height = 118 + Top = 121 + Width = 594 + Align = alTop + AutoSize = True + BorderSpacing.Top = 11 + Caption = 'grpTargetPlatform' + ClientHeight = 99 + ClientWidth = 590 + TabOrder = 1 + object lblTargetOS: TLabel + AnchorSideLeft.Control = grpTargetPlatform + AnchorSideTop.Control = TargetOSComboBox + AnchorSideTop.Side = asrCenter + Left = 6 + Height = 15 + Top = 11 + Width = 70 + BorderSpacing.Around = 6 + Caption = 'lblTargetOS' + ParentColor = False + end + object lblTargetCPU: TLabel + AnchorSideLeft.Control = grpTargetPlatform + AnchorSideTop.Control = TargetCPUComboBox + AnchorSideTop.Side = asrCenter + Left = 6 + Height = 15 + Top = 42 + Width = 78 + BorderSpacing.Around = 6 + Caption = 'lblTargetCPU' + ParentColor = False + end + object lblTargetProcessorProc: TLabel + AnchorSideLeft.Control = grpTargetPlatform + AnchorSideTop.Control = TargetProcessorProcComboBox + AnchorSideTop.Side = asrCenter + Left = 6 + Height = 15 + Top = 73 + Width = 144 + BorderSpacing.Around = 6 + Caption = 'lblTargetProcessorProc' + ParentColor = False + end + object TargetOSComboBox: TComboBox + AnchorSideLeft.Control = lblTargetOS + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = grpTargetPlatform + AnchorSideRight.Control = grpTargetPlatform + AnchorSideRight.Side = asrBottom + Left = 88 + Height = 25 + Top = 6 + Width = 496 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 6 + BorderSpacing.Around = 6 + ItemHeight = 0 + Style = csDropDownList + TabOrder = 0 + end + object TargetCPUComboBox: TComboBox + AnchorSideLeft.Control = lblTargetCPU + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = TargetOSComboBox + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = grpTargetPlatform + AnchorSideRight.Side = asrBottom + Left = 96 + Height = 25 + Top = 37 + Width = 488 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 6 + BorderSpacing.Around = 6 + ItemHeight = 0 + Style = csDropDownList + TabOrder = 1 + end + object TargetProcessorProcComboBox: TComboBox + AnchorSideLeft.Control = lblTargetProcessorProc + AnchorSideLeft.Side = asrBottom + AnchorSideTop.Control = TargetCPUComboBox + AnchorSideTop.Side = asrBottom + AnchorSideRight.Control = grpTargetPlatform + AnchorSideRight.Side = asrBottom + Left = 162 + Height = 25 + Top = 68 + Width = 422 + Anchors = [akTop, akLeft, akRight] + BorderSpacing.Left = 6 + BorderSpacing.Around = 6 + ItemHeight = 0 + Style = csDropDownList + TabOrder = 2 + end + end + object grpSyntaxMode: TGroupBox + Left = 0 + Height = 56 + Top = 250 + Width = 594 + Align = alTop + Anchors = [akTop] + AutoSize = True + BorderSpacing.Top = 11 + Caption = 'grpSyntaxMode' + ClientHeight = 37 + ClientWidth = 590 + TabOrder = 2 + object cmbSyntaxMode: TComboBox + AnchorSideRight.Control = grpSyntaxMode + AnchorSideRight.Side = asrBottom + Left = 6 + Height = 25 + Top = 6 + Width = 578 + Align = alLeft + Anchors = [akTop, akLeft, akRight, akBottom] + BorderSpacing.Around = 6 + ItemHeight = 0 + Style = csDropDownList + TabOrder = 0 + end + end +end diff --git a/ide/frames/compiler_config_target.pas b/ide/frames/compiler_config_target.pas new file mode 100644 index 0000000000..6f9089c9a6 --- /dev/null +++ b/ide/frames/compiler_config_target.pas @@ -0,0 +1,408 @@ +{*************************************************************************** + * * + * This source is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This code is distributed in the hope that it will be useful, but * + * WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * General Public License for more details. * + * * + * A copy of the GNU General Public License is available on the World * + * Wide Web at . You can also * + * obtain it by writing to the Free Software Foundation, * + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * * + *************************************************************************** + + Abstract: + Frame to edit custom options and conditionals of compiler options + (project+packages). +} +unit compiler_config_target; + +{$mode objfpc}{$H+} + +{$DEFINE VerboseCOCondSynCompletion} + +interface + +uses + Classes, SysUtils, math, AVL_Tree, LazLogger, FileUtil, + Forms, Controls, Graphics, Dialogs, StdCtrls, LCLProc, ComCtrls, LCLType, + ExtCtrls, + CodeToolsCfgScript, KeywordFuncLists, + SynEdit, SynEditKeyCmds, SynCompletion, + IDEOptionsIntf, CompOptsIntf, + IDEDialogs, IDECommands, Project, CompilerOptions, LazarusIDEStrConsts, + SourceSynEditor, EditorOptions, PackageDefs, LinkScanner; + +type + + { TCompilerConfigTargetFrame } + + TCompilerConfigTargetFrame = class(TAbstractIDEOptionsEditor) + chkConfigFile: TCheckBox; + chkCustomConfigFile: TCheckBox; + cmbSyntaxMode: TComboBox; + edtConfigPath: TEdit; + grpConfigFile: TGroupBox; + grpSyntaxMode: TGroupBox; + grpTargetPlatform: TGroupBox; + lblTargetCPU: TLabel; + lblTargetOS: TLabel; + lblTargetProcessorProc: TLabel; + TargetCPUComboBox: TComboBox; + TargetOSComboBox: TComboBox; + TargetProcessorProcComboBox: TComboBox; + procedure chkCustomConfigFileClick(Sender: TObject); + private + FCompOptions: TBaseCompilerOptions; + FIsPackage: boolean; + public + constructor Create(TheOwner: TComponent); override; + destructor Destroy; override; + function Check: Boolean; override; + function GetTitle: string; override; + procedure Setup(ADialog: TAbstractOptionsEditorDialog); override; + procedure ReadSettings(AOptions: TAbstractIDEOptions); override; + procedure WriteSettings(AOptions: TAbstractIDEOptions); override; + class function SupportedOptionsClass: TAbstractIDEOptionsClass; override; + property IsPackage: boolean read FIsPackage; + property CompOptions: TBaseCompilerOptions read FCompOptions; + end; + +implementation + +{$R *.lfm} + +function CaptionToOS(const OS: string): string; +begin + Result:=LowerCase(OS); +end; + +function CaptionToCPU(const CPU: string): string; +begin + Result:=LowerCase(CPU); +end; + +function ProcessorToCaption(const Processor: string): string; +begin + if SysUtils.CompareText(Processor, '80386') = 0 then + Result := '386/486 (-Op80386)' + else if SysUtils.CompareText(Processor, 'pentium') = 0 then + Result := 'Pentium/Pentium MMX (-OpPENTIUM)' + else if SysUtils.CompareText(Processor, 'pentium2') = 0 then + Result := 'Pentium Pro/Pentium II/C6x86/K6 (-OpPENTIUM2)' + else if SysUtils.CompareText(Processor, 'pentium3') = 0 then + Result := 'Pentium III (-OpPENTIUM3)' + else if SysUtils.CompareText(Processor, 'pentium4') = 0 then + Result := 'Pentium IV (-OpPENTIUM4)' + else if SysUtils.CompareText(Processor, 'pentiumm') = 0 then + Result := 'Pentium M (-OpPENTIUMM)' + else + Result := '(' + lisDefault + ')'; +end; + +function CaptionToProcessor(const Caption: string): string; +begin + if System.Pos('-Op80386', Caption) > 0 then + Result := '80386' + else if System.Pos('-OpPENTIUMM', Caption) > 0 then + Result := 'pentiumm' + else if System.Pos('-OpPENTIUM4', Caption) > 0 then + Result := 'pentium4' + else if System.Pos('-OpPENTIUM3', Caption) > 0 then + Result := 'pentium3' + else if System.Pos('-OpPENTIUM2', Caption) > 0 then + Result := 'pentium2' + else if System.Pos('-OpPENTIUM', Caption) > 0 then + Result := 'pentium' + else + Result := ''; +end; + +function SyntaxModeToCaption(const Mode: string): string; +begin + if SysUtils.CompareText(Mode, 'ObjFPC') = 0 then + Result := lisObjectPascalDefault + ' (-Mobjfpc)' + else if SysUtils.CompareText(Mode, 'Delphi') = 0 then + Result := lisDelphi + ' (-Mdelphi)' + else if SysUtils.CompareText(Mode, 'tp') = 0 then + Result := lisTurboPascal + ' (-Mtp)' + else if SysUtils.CompareText(Mode, 'fpc') = 0 then + Result := lisFreePascal + ' (-Mfpc)' + else if SysUtils.CompareText(Mode, 'macpas') = 0 then + Result := lisMacPascal + ' (-Mmacpas)' + else + Result := ''; +end; + +function CaptionToSyntaxMode(const Caption: string): string; +begin + if System.Pos('-Mdelphi', Caption) > 0 then + Result := 'Delphi' + else if System.Pos('-Mtp', Caption) > 0 then + Result := 'tp' + else if System.Pos('-Mmacpas', Caption) > 0 then + Result := 'macpas' + else if System.Pos('-Mfpc', Caption) > 0 then + Result := 'fpc' + else + Result := 'ObjFPC'; +end; + + +{ TCompilerConfigTargetFrame } + +procedure TCompilerConfigTargetFrame.chkCustomConfigFileClick(Sender: TObject); +begin + edtConfigPath.Enabled := chkCustomConfigFile.Checked; +end; + +constructor TCompilerConfigTargetFrame.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); +end; + +destructor TCompilerConfigTargetFrame.Destroy; +begin + inherited Destroy; +end; + +function TCompilerConfigTargetFrame.Check: Boolean; +var + NewDontUseConfigFile: Boolean; + NewCustomConfigFile: Boolean; + NewConfigFilePath: String; + AdditionalConfig: String; +begin + //debugln(['TCompilerConfigTargetFrame.ReadSettings ',dbgs(Pointer(FCompOptions)),' ',FCompOptions=Project1.CompilerOptions]); + + NewDontUseConfigFile := not chkConfigFile.Checked; + NewCustomConfigFile := chkCustomConfigFile.Checked; + NewConfigFilePath := edtConfigPath.Text; + + if ((NewDontUseConfigFile <> CompOptions.DontUseConfigFile) or + (NewCustomConfigFile <> CompOptions.CustomConfigFile) or + (NewConfigFilePath <> CompOptions.ConfigFilePath)) and (not NewDontUseConfigFile) and + NewCustomConfigFile then + begin + // config file options changed + // and both additional and standard config files are used + AdditionalConfig := ExtractFilename(edtConfigPath.Text); + if (CompareFileNames(AdditionalConfig, 'fpc.cfg') = 0) or + (CompareFileNames(AdditionalConfig, 'ppc386.cfg') = 0) then + begin + if IDEMessageDialog(lisCOAmbiguousAdditionalCompilerConfigFile, + Format(lisCOClickOKIfAreSureToDoThat, + [BreakString(lisCOWarningTheAdditionalCompilerConfigFileHasTheSameNa, + 60, 0), LineEnding+LineEnding]), mtWarning, [mbOK, mbCancel]) <> mrOk then + begin + Result := False; + exit; + end; + end; + end; + + Result := True; +end; + +function TCompilerConfigTargetFrame.GetTitle: string; +begin + Result := dlgConfigAndTarget; +end; + +procedure TCompilerConfigTargetFrame.Setup(ADialog: TAbstractOptionsEditorDialog); +var + m: TCompilerMode; + s: string; +begin + // Config + grpConfigFile.Caption := dlgConfigFiles; + chkConfigFile.Caption := dlgUseFpcCfg + ' (If not checked: -n)'; + chkCustomConfigFile.Caption := dlgUseCustomConfig + ' (@)'; + edtConfigPath.Text := ''; + // Target + grpTargetPlatform.Caption := dlgTargetPlatform; + lblTargetOS.Caption := dlgTargetOS + ' (-T)'; + + with TargetOSComboBox do + begin + with Items do + begin + Add('(' + lisDefault + ')'); + Add('Darwin'); + Add('FreeBSD'); + Add('Linux'); + Add('NetBSD'); + Add('OpenBSD'); + Add('Solaris'); + Add('Win32'); + Add('Win64'); + Add('WinCE'); + Add('aix'); + Add('amiga'); + Add('android'); + Add('atari'); + Add('beos'); + Add('embedded'); + Add('emx'); + Add('gba'); + Add('go32v2'); + Add('haiku'); + Add('iphonesim'); + Add('java'); + Add('macos'); + Add('morphos'); + Add('nds'); + Add('netware'); + Add('netwlibc'); + Add('os2'); + Add('palmos'); + Add('qnx'); + Add('symbian'); + Add('watcom'); + Add('wdosx'); + end; + ItemIndex := 0; + end; + + lblTargetCPU.Caption := dlgTargetCPUFamily + ' (-P)'; + + with TargetCPUComboBox do + begin + with Items do + begin + Add('(' + lisDefault + ')'); + Add('arm'); + Add('i386'); + Add('m68k'); + Add('powerpc'); + Add('sparc'); + Add('x86_64'); + Add('mipsel'); + Add('mips'); + Add('jvm'); + end; + ItemIndex := 0; + end; + + lblTargetProcessorProc.Caption := dlgTargetProc; + + with TargetProcessorProcComboBox do + begin + with Items do + begin + Clear; + Add(ProcessorToCaption('')); + Add(ProcessorToCaption('80386')); + Add(ProcessorToCaption('Pentium')); + Add(ProcessorToCaption('Pentium2')); + Add(ProcessorToCaption('Pentium3')); + Add(ProcessorToCaption('Pentium4')); + Add(ProcessorToCaption('PentiumM')); + end; + ItemIndex := 0; + end; + + grpSyntaxMode.Caption := lisSyntaxMode + ' (-M, {$MODE})'; + cmbSyntaxMode.Items.BeginUpdate; + cmbSyntaxMode.Items.Clear; + for m := Low(TCompilerMode) to High(TCompilerMode) do + begin + s := SyntaxModeToCaption(CompilerModeNames[m]); + if s <> '' then + cmbSyntaxMode.Items.Add(s); + end; + cmbSyntaxMode.Items.EndUpdate; +end; + +procedure TCompilerConfigTargetFrame.ReadSettings(AOptions: TAbstractIDEOptions); +var + i: Integer; +begin + FCompOptions:=AOptions as TBaseCompilerOptions; + FIsPackage:=CompOptions is TPkgCompilerOptions; + //debugln(['TCompilerConfigTargetFrame.ReadSettings ',dbgs(Pointer(FCompOptions)),' ',FCompOptions=Project1.CompilerOptions]); + + with CompOptions do + begin + chkConfigFile.Checked := not DontUseConfigFile; + chkCustomConfigFile.Checked := CustomConfigFile; + edtConfigPath.Enabled := chkCustomConfigFile.Checked; + edtConfigPath.Text := ConfigFilePath; + + if fIsPackage then begin + grpTargetPlatform.Visible:=false; + TargetOSComboBox.ItemIndex := 0; + TargetOSComboBox.Text := 'default'; + TargetCPUComboBox.ItemIndex := 0; + TargetCPUComboBox.Text := 'default'; + TargetProcessorProcComboBox.Text := 'default'; + end else begin + grpTargetPlatform.Visible:=true; + i := TargetOSComboBox.Items.IndexOf(TargetOS); + if i < 0 then + i := 0; // 0 is default + TargetOSComboBox.ItemIndex := i; + TargetOSComboBox.Text := TargetOS; + i := TargetCPUComboBox.Items.IndexOf(TargetCPU); + if i < 0 then + i := 0; // 0 is default + TargetCPUComboBox.ItemIndex := i; + TargetCPUComboBox.Text := TargetCPU; + TargetProcessorProcComboBox.Text := ProcessorToCaption(TargetProcessor); + + cmbSyntaxMode.Text := SyntaxModeToCaption(SyntaxMode); + end; + end; +end; + +procedure TCompilerConfigTargetFrame.WriteSettings(AOptions: TAbstractIDEOptions); +var + CurOptions: TBaseCompilerOptions; + NewTargetOS: string; + NewTargetCPU: string; +begin + //debugln(['TCompilerConfigTargetFrame.WriteSettings ',DbgSName(AOptions)]); + CurOptions:=AOptions as TBaseCompilerOptions; + with CurOptions do + begin + DontUseConfigFile := not chkConfigFile.Checked; + CustomConfigFile := chkCustomConfigFile.Checked; + ConfigFilePath := edtConfigPath.Text; + + if not fIsPackage then + begin + NewTargetOS := TargetOSComboBox.Text; + if TargetOSComboBox.Items.IndexOf(NewTargetOS) <= 0 then + NewTargetOS := ''; + TargetOS := CaptionToOS(NewTargetOS); + + NewTargetCPU := TargetCPUComboBox.Text; + if TargetCPUComboBox.Items.IndexOf(NewTargetCPU) <= 0 then + NewTargetCPU := ''; + TargetCPU := CaptionToCPU(NewTargetCPU); + TargetProcessor := CaptionToProcessor(TargetProcessorProcComboBox.Text); + + SyntaxMode := CaptionToSyntaxMode(cmbSyntaxMode.Text); + end; + end; +end; + +class function TCompilerConfigTargetFrame.SupportedOptionsClass: TAbstractIDEOptionsClass; +begin + Result := TBaseCompilerOptions; +end; + +initialization + RegisterIDEOptionsEditor(GroupCompiler, TCompilerConfigTargetFrame, + CompilerOptionsConfigTarget); + RegisterIDEOptionsEditor(GroupPkgCompiler, TCompilerConfigTargetFrame, + CompilerOptionsConfigTarget); + +end. +