Does GPRbuild
support a configuration option or any other way to apply special compiler switches only to special files?
That could be useful if -gnatyXYZ
switches for strict syntax checks are used for most files in a project but some external / not project specific Ada files are not compliant with the enforced syntax checks.
You can specify both default switches for all Ada files and specific switches for individual files:
package Compiler is
for Default_Switches ("Ada")
use ("-O2");
for Switches ("proc.adb")
use ("-O0");
end Compiler;
GNAT's documentation gives more info.
EDIT: To address user @Martin's comment to my answer, it does indeed work when you need multiple switches for Default_Switches
and only want to change one in Switches
. See:
package Compiler is
for Default_Switches ("Ada")
use ("-gnata", "-O2");
for Switches ("proc.adb")
use ("-gnata", "-O0");
end Compiler;
Here the only switch that changes is the optimization flag. For large lists of switches you can use a variable to hold the ones shared by all files and append the different ones differently for Default_Switches
and Switches
Shared_Switches := ("-gnata", "-fstack-check");
package Compiler is
for Default_Switches ("Ada")
use Shared_Switches & ("-O2");
for Switches ("proc.adb")
use Shared_Switches & ("-O0");
end Compiler;