3

This information is available elsewhere but not consolidated to this particular use-case, hence I felt the need for a stackoverflow self-answer that I (and others) can refer to. Feel free to add your own answers if there is anything I have missed.

project some_project is
   for Source_Dirs use ("src");
   for Object_Dir use "obj";
   for Main use ("main.adb");

   package Compiler is
      for Default_Switches ("ada") use ("-O1", "-gnatwae");
   end Compiler;
end some_project;

I want to have this generate ../some_program_name.exe. How do I specify the name of the executable this gpr project will generate? Can it be in a directory above?

TamaMcGlinn
  • 2,840
  • 23
  • 34

1 Answers1

7

Add this to your gpr file:

for Exec_Dir use "..";
package Builder is
   for Executable ("main.adb") use "some_program_name";
end Builder;

Note that the .exe suffix is added automatically if you are on windows.

In the same Builder package, only the extension can also be changed

for Executable_Suffix use ".elf";

The information was scattered across Adacore's docs for the GNAT Project Manager.

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
TamaMcGlinn
  • 2,840
  • 23
  • 34
  • 1
    Also, if you change this in GNAT Studio you also need to click the Refresh button in the Project tab, otherwise it will build the executable with the new name but then run the old main.exe – carbin Nov 14 '21 at 13:22
  • 1
    what's annoying is that `"main.adb"` can't be put in a variable to be used in the `for main use` and in the `for executable use`. GPR parsing tools only accept literals so you have to copy/paste – Jean-François Fabre Sep 05 '22 at 09:08