LazBuild: Allow --opt option to be specified multiple times to add compiler options

This commit is contained in:
n7800 2024-09-28 01:50:30 +05:00 committed by Juha
parent fc90be95ce
commit eba189ea8c
2 changed files with 34 additions and 6 deletions

View File

@ -172,9 +172,9 @@ resourcestring
'info file after build. If not specified, build number will be incremented '+
'if configured.';
lisExtraOpts = 'Pass additional options to the compiler. If compilation '+
'options are also specified in --build-ide, then the options from --opt '+
'will be added after them.';
lisExtraOpts = 'Pass additional options to the compiler, can be specified '+
'multiple times. If compilation options are also specified in --build-ide, '+
'then the options from --opt will be added after them.';
lisGetExpandText = 'Print the result of substituting macros in the text. '+
'The absence of macros in the text means the name of the macro. '+
'By default, active build mode is used.';

View File

@ -119,6 +119,7 @@ type
protected
function GetParams(Index: Integer): String; override;
function GetParamCount: Integer; override;
function HasCustomCompilerOpts(out aValue: string): boolean;
// Builds project or package, depending on extension.
// Packages can also be specified by package name if they are known to the IDE.
@ -401,6 +402,33 @@ begin
Result := ToolParamCount;
end;
function TLazBuildApplication.HasCustomCompilerOpts(out aValue: string): boolean;
var
p: string; // current parameter
v: string; // value of current parameter
i: Integer;
begin
aValue := '';
for i := 1 to GetParamCount do
begin
p := GetParams(i);
if LazStartsText('--opt=', p) then
begin
// get value
v := copy(p, length('--opt=') + 1, length(p));
// remove quotes
if length(v) >= 2 then
if ((v[1] = '"' ) and (v[length(v)] = '"' )) or
((v[1] = '''') and (v[length(v)] = ''''))
then
v := copy(v, 2, length(v) - 2);
// append
aValue := MergeCustomOptions(aValue, v);
end;
end;
result := aValue <> '';
end;
function TLazBuildApplication.BuildFile(Filename: string): boolean;
var
OriginalFilename: string;
@ -499,7 +527,7 @@ begin
APackage.CompilerOptions.TargetCPU:=CPUOverride;
if SubtargetOverride then
APackage.CompilerOptions.Subtarget:=SubtargetOverrideValue;
if HasLongOptIgnoreCase('opt', S) then
if HasCustomCompilerOpts(S) then
with APackage.CompilerOptions do
CustomOptions := MergeCustomOptions(CustomOptions, S);
@ -613,7 +641,7 @@ begin
if BuildIDEOptions <> '' then
CurProf.ExtraOptions := MergeCustomOptions(CurProf.ExtraOptions, BuildIDEOptions);
// add parameters from the --opt option after --build-ide, as higher priority
if HasLongOptIgnoreCase('opt', s) then
if HasCustomCompilerOpts(s) then
CurProf.ExtraOptions := MergeCustomOptions(CurProf.ExtraOptions, s);
if BuildAll then
@ -811,7 +839,7 @@ var
MatrixOption.MacroName:='LCLWidgetType';
MatrixOption.Value:=WidgetSetOverride;
end;
if HasLongOptIgnoreCase('opt', S) then
if HasCustomCompilerOpts(S) then
with Project1.CompilerOptions do
CustomOptions := MergeCustomOptions(CustomOptions, S);