Running “cairos” from testgtk via Alire
Minimal Setup: Run testgtk “Gtk demo” – “Cairo” with Alire
Date: June 28 2025
Confirmed versions:
Ubuntu: 24.04.2 LTS, Gnat: 14.2.1, Gtkada:25.0.1
PC: OMEN 17-ck2095cl, i9-13900HX, RTX-4080
Setup Build Space “cairos” for “testcairo_drawing” / ”create_cairo”
testgtk sample project name: create_about
New directory name: about
~$ mkdir ada/s_testgtk
~$ cd ada/s_testgtk~/ada/s_testgtk$ alr init cairos –bin
Alire needs some user information to initialize the crate author and maintainer,
for eventual submission to the Alire community index. This information will be
interactively requested now.
You can edit this information at any time with ‘alr config’
Enter a short description of the crate: (default: ”)
> Press Enter
Using default: ”
Please enter your email address: (default: ‘example@example.com’)
> Press Enter
Using default: ‘example@example.com’
Select a software license for the crate?
- MIT OR Apache-2.0 WITH LLVM-exception
- MIT
- Apache-2.0 WITH LLVM-exception
- Apache-2.0
- BSD-3-Clause
- LGPL-3.0-or-later
- GPL-3.0-or-later WITH GCC-exception-3.1
- GPL-3.0-or-later
- Other…
Alire needs some user information to initialize the crate author and maintainer,
for eventual submission to the Alire community index. This information will be
interactively requested now.
You can edit this information at any time with ‘alr config’
Enter a short description of the crate: (default: ”)
> Press Enter
Using default: ”
Please enter your email address: (default: ‘example@example.com’)
> Press Enter
Using default: ‘example@example.com‘
Select a software license for the crate?
1. MIT OR Apache-2.0 WITH LLVM-exception
2. MIT
3. Apache-2.0 WITH LLVM-exception
4. Apache-2.0
5. BSD-3-Clause
6. LGPL-3.0-or-later
7. GPL-3.0-or-later WITH GCC-exception-3.1
8. GPL-3.0-or-later
9. Other…
Enter your choice index (#1 is default):
> Press Enter
Enter a comma (‘,’) separated list of tags to help people find your crate: (default: ”)
> Press Enter
Using default: ”
Enter an optional Website URL for the crate: (default: ”)
> Press Enter
Using default: ”
✓ cairos initialized successfully.
Setup gtkada Environment
~/ada/s_testgtk$ cd cairos
/ada/s_testgtk/about$ alr with gtkada
◴ Updating index... remote: Enumerating objects: 126, done.
remote: Counting objects: 100% (99/99), done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 126 (delta 57), reused 77 (delta 48), pack-reused 27 (from 1)
Receiving objects: 100% (126/126), 47.03 KiB | 3.62 MiB/s, done.
Resolving deltas: 100% (61/61), completed with 17 local objects.
From https://github.com/alire-project/alire-index
4f64614..f814b95 stable-1.3.0 -> origin/stable-1.3.0
01882d3..c8f57b5 stable-1.4.0 -> origin/stable-1.4.0
Updating 4f64614..f814b95
Fast-forward
index/pr/press_utils/press_utils-1.0.0.toml | 15 +++++++++++++++
.../sparkfun_qwiic_motor_driver-0.1.0.toml | 19 +++++++++++++++++++
2 files changed, 34 insertions(+)
create mode 100644 index/pr/press_utils/press_utils-1.0.0.toml
create mode 100644 index/sp/sparkfun_qwiic_motor_driver/sparkfun_qwiic_motor_driver-0.1.0.toml
◵ Solving dependencies: 0/0/0/6 (complete/partial/dupes/states)... Looking for e. ◵ Solving dependencies: 0/0/0/6 (complete/partial/dupes/states)... Looking for e. ◵ Solving dependencies: 0/0/0/6 (complete/partial/dupes/states)... Looking for e. ◵ Solving dependencies: 0/0/0/6 (complete/partial/dupes/states)... Looking for e. ◵ Solving dependencies: 0/0/0/6 (complete/partial/dupes/states)... Looking for e. ◵ Solving dependencies: 0/0/0/6 (complete/partial/dupes/states)... Looking for e. Requested changes:
✓ gtkada ^25.0.1 (add)
Changes to dependency solution:
+ gtkada 25.0.1 (new)
+📦 libgtk3 3.24.41 (new,indirect,system package)
+📦 make 4.3.0 (new,indirect,system package)
+📦 pkg_config 1.8.1 (new,indirect,system package)
Do you want to proceed?
[Y] Yes [N] No (default is Yes) <strong>Yes</strong>
~~/ada/s_testgtk/cairos$ alr build
ⓘ Building cairos=0.1.0-dev/cairos.gpr...
Setup
[mkdir] object directory for project Cairos
[mkdir] exec directory for project Cairos
Compile
[Ada] cairos.adb
Bind
[gprbind] cairos.bexch
[Ada] cairos.ali
Link
[link] cairos.adb
✓ Build finished successfully in 0.61 seconds.
Setup Source Files
~/ada/s_testgtk/cairo$ ls -al
total 44
drwxrwxr-x 8 mm mm 4096 Jun 21 09:29 .
drwxrwxr-x 5 mm mm 4096 Jun 21 09:27 ..
drwxrwxr-x 3 mm mm 4096 Jun 21 09:29 alire
-rw-rw-r– 1 mm mm 288 Jun 21 09:28 alire.toml
drwxrwxr-x 2 mm mm 4096 Jun 21 09:29 bin
-rw-rw-r– 1 mm mm 564 Jun 21 09:27 cairos.gpr
drwxrwxr-x 2 mm mm 4096 Jun 21 09:27 config
-rw-rw-r– 1 mm mm 29 Jun 21 09:27 .gitignore
drwxrwxr-x 3 mm mm 4096 Jun 21 09:29 obj
drwxrwxr-x 3 mm mm 4096 Jun 21 09:27 share
drwxrwxr-x 2 mm mm 4096 Jun 21 09:27 src
Copy 2 files from the testgtk directory into src directory.
https://github.com/AdaCore/gtkada/tree/master/testgtk
testcairo_drawing.ads, testcairo_drawing.adb
These files are not usedcreate_cairo.ads, creat_cairo.adb
~/ada/s_testgtk/cairo$ cd src
~/ada/s_testgtk/cairo/src$ ls -al
total 48
drwxrwxr-x 2 mm mm 4096 Jun 21 09:33 .
drwxrwxr-x 8 mm mm 4096 Jun 21 09:29 ..
-rw-rw-r– 1 mm mm 47 Jun 21 09:27 cairos.adb
-rw-rw-r– 1 mm mm 22166 May 10 14:44 testcairo_drawing.adb
-rw-rw-r– 1 mm mm 2388 May 10 14:44 testcairo_drawing.ads
Edit Source Files
cairos.adb is auto-created file
~/ada/s_testgtk/cairos/src$ cat cairos.adb
~/ada/s_testgtk/cairos/src$ cat cairos.adb
procedure Cairos is
begin
null;
end Cairos;
Edit main program
Create 3 files and paste next codes into them:
cairos.adb (main program)
with Glib; use Glib;
with Gtk.Main; -- use Gtk.Main;
with Gtk.Window; use Gtk.Window;
with Gtk.Box; use Gtk.Box;
with Gtk.Button; use Gtk.Button;
with Gtk.Label; use Gtk.Label;
with Gtk.Separator; use Gtk.Separator;
with Gtk.Enums; use Gtk.Enums;
with Sub_Cairos; use Sub_Cairos;
with Gtk.Widget; use Gtk.Widget;
with Gdk.Event; -- use Gdk.Event;
procedure Cairos is
Window : Gtk_Window;
Main_Box : Gtk_Vbox;
Title : Gtk_Label;
Separator : Gtk_Hseparator;
Button : Gtk_Button;
function Delete_Event_Cb
(Self : access Gtk_Widget_Record'Class;
Event : Gdk.Event.Gdk_Event)
return Boolean;
---------------------
-- Delete_Event_Cb --
---------------------
function Delete_Event_Cb
(Self : access Gtk_Widget_Record'Class;
Event : Gdk.Event.Gdk_Event)
return Boolean
is
pragma Unreferenced (Self, Event);
begin
-- Close all child windows before closing main loop
Window.Destroy;
Gtk.Main.Main_Quit;
return True;
end Delete_Event_Cb;
begin
-- Initialize GTK
Gtk.Main.Init;
-- Create main window
Gtk_New (Window);
Window.Set_Title ("Cairo Graphics Library Demos");
Window.Set_Default_Size (400, 600);
Window.Set_Position (Win_Pos_Center);
-- Stop the Gtk process when closing the window
Window.On_Delete_Event (Delete_Event_Cb'Unrestricted_Access);
-- Window.On_Delete_Event (Sub_Cairos.On_Delete_Event_Handler'Access);
-- Window.On_Delete_Event (Gtk.Main.Delete_Event_Cb'Access);
-- Create main vertical box
Gtk_New_Vbox (Main_Box, Homogeneous => False, Spacing => 5);
Main_Box.Set_Border_Width (10);
Window.Add (Main_Box);
-- Add title label
Gtk_New (Title, "Cairo Graphics Library Demos");
Title.Set_Markup ("<big><b>Cairo Graphics Library Demos</b></big>");
Title.Set_Justify (Justify_Center);
Main_Box.Pack_Start (Title, Expand => False, Fill => False, Padding => 5);
-- Add separator
Gtk_New_Hseparator (Separator);
Main_Box.Pack_Start (Separator, Expand => False, Fill => False,
Padding => 5);
-- Add demo buttons in order
Gtk_New (Button, "1. Simple rectangles");
Button.On_Clicked (On_Rectangles_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
Gtk_New (Button, "2. Transparency");
Button.On_Clicked (On_Transparency_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
Gtk_New (Button, "3. Compositing operators");
Button.On_Clicked (On_Operators_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
Gtk_New (Button, "4. Translating, rotation and scaling");
Button.On_Clicked (On_Matrix_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
Gtk_New (Button, "5. Direct transformations");
Button.On_Clicked (On_Transformations_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
Gtk_New (Button, "6. Paths");
Button.On_Clicked (On_Paths_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
Gtk_New (Button, "7. Patterns");
Button.On_Clicked (On_Patterns_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
Gtk_New (Button, "8. The TOY_TEXT API");
Button.On_Clicked (On_Toy_Text_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
Gtk_New (Button, "9. Rendering text with pango");
Button.On_Clicked (On_Pango_Text_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
Gtk_New (Button, "10. Painting and clipping");
Button.On_Clicked (On_Clip_And_Paint_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
Gtk_New (Button, "11. Using surfaces and saving to PNG");
Button.On_Clicked (On_Surface_And_Png_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
Gtk_New (Button, "12. Image as background");
Button.On_Clicked (On_Image_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
-- Add separator
Gtk_New_Hseparator (Separator);
Main_Box.Pack_Start (Separator, Expand => False, Fill => False,
Padding => 10);
-- Add quit button
Gtk_New (Button, "Quit");
Button.On_Clicked (On_Quit_Clicked'Access, Button);
Main_Box.Pack_Start (Button, Expand => False, Fill => False);
-- Show all widgets and start main loop
Window.Show_All;
Gtk.Main.Main;
end Cairos;
sub_cairos.ads
with Glib.Object; use Glib.Object;
package Sub_Cairos is
procedure On_Rectangles_Clicked
(Object : access GObject_Record'Class);
-- Show simple rectangles demo
procedure On_Transparency_Clicked
(Object : access GObject_Record'Class);
-- Show transparency demo
procedure On_Operators_Clicked
(Object : access GObject_Record'Class);
-- Show compositing operators demo
procedure On_Matrix_Clicked
(Object : access GObject_Record'Class);
-- Show translating, rotation and scaling demo
procedure On_Transformations_Clicked
(Object : access GObject_Record'Class);
-- Show direct transformations demo
procedure On_Paths_Clicked
(Object : access GObject_Record'Class);
-- Show paths demo
procedure On_Patterns_Clicked
(Object : access GObject_Record'Class);
-- Show patterns demo
procedure On_Toy_Text_Clicked
(Object : access GObject_Record'Class);
-- Show the TOY_TEXT API demo
procedure On_Pango_Text_Clicked
(Object : access GObject_Record'Class);
-- Show rendering text with pango demo
procedure On_Clip_And_Paint_Clicked
(Object : access GObject_Record'Class);
-- Show painting and clipping demo
procedure On_Surface_And_Png_Clicked
(Object : access GObject_Record'Class);
-- Show using surfaces and saving to PNG demo
procedure On_Image_Clicked
(Object : access GObject_Record'Class);
-- Show image as background demo
procedure On_Quit_Clicked
(Object : access GObject_Record'Class);
-- Quit the application
--
end Sub_Cairos;
sub_cairos.adb
with Gtk.Main; -- use Gtk.Main;
with Gtk.Window; use Gtk.Window;
with Gtk.Frame; use Gtk.Frame;
with Gtk.Enums; use Gtk.Enums;
with Testcairo_Drawing; use Testcairo_Drawing;
package body Sub_Cairos is
procedure Show_Demo (Test : Test_Type) is
Window : Gtk_Window;
Frame : Gtk_Frame;
begin
Gtk_New (Window);
Window.Set_Title ("Cairo Demo - " & Test'Img);
Window.Set_Default_Size (600, 400);
-- ****** Window.On_Delete_Event (Gtk.Main.Delete_Event_Cb'Access);
Gtk_New (Frame);
Window.Add (Frame);
Run_Test (Frame, Test);
Window.Show_All;
end Show_Demo;
procedure On_Rectangles_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Rectangles);
end On_Rectangles_Clicked;
procedure On_Transparency_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Transparency);
end On_Transparency_Clicked;
procedure On_Operators_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Operators);
end On_Operators_Clicked;
procedure On_Matrix_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Matrix);
end On_Matrix_Clicked;
procedure On_Transformations_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Transformations);
end On_Transformations_Clicked;
procedure On_Paths_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Paths);
end On_Paths_Clicked;
procedure On_Patterns_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Patterns);
end On_Patterns_Clicked;
procedure On_Toy_Text_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Toy_Text);
end On_Toy_Text_Clicked;
procedure On_Pango_Text_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Pango_Text);
end On_Pango_Text_Clicked;
procedure On_Clip_And_Paint_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Clip_And_Paint);
end On_Clip_And_Paint_Clicked;
procedure On_Surface_And_Png_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Surface_And_Png);
end On_Surface_And_Png_Clicked;
procedure On_Image_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Show_Demo (Image);
end On_Image_Clicked;
procedure On_Quit_Clicked
(Object : access GObject_Record'Class)
is
pragma Unreferenced (Object);
begin
Gtk.Main.Main_Quit;
end On_Quit_Clicked;
end Sub_Cairos;
Startup GnatStudio with Alire
~/ada/s_testgtk/cairos$ alr edit
File cairos.gpr opens as above screen automatically.
File cairos.gpr before modification:
with "config/cairos_config.gpr";
project Cairos is
for Source_Dirs use ("src/", "config/");
for Object_Dir use "obj/" & Cairos_Config.Build_Profile;
for Create_Missing_Dirs use "True";
for Exec_Dir use "bin";
for Main use ("cairos.adb");
package Compiler is
for Default_Switches ("Ada") use Cairos_Config.Ada_Compiler_Switches;
end Compiler;
package Binder is
for Switches ("Ada") use ("-Es"); -- Symbolic traceback
end Binder;
package Install is
for Artifacts (".") use ("share");
end Install;
end Cairos;
Modify cairos.gpr
Add the following line at the next of “for Main use (“cairos.adb”);
for Source_Files use
(“cairos.adb”, “cairos_config.ads”,
“sub_cairos.adb”, “sub_cairos.ads”, “testcairo_drawing.adb”, “testcairo_drawing.ads”);
File cairo.gpr after the modification
with "config/cairos_config.gpr";
project Cairos is
for Source_Dirs use ("src", "config");
for Object_Dir use "obj/" & Cairos_Config.Build_Profile;
for Create_Missing_Dirs use "True";
for Exec_Dir use "bin";
for Main use ("cairos.adb");
package Compiler is
for Default_Switches ("ada") use Cairos_Config.Ada_Compiler_Switches;
end Compiler;
package Binder is
for Switches ("Ada") use ("-Es"); -- Symbolic traceback
end Binder;
package Install is
for Artifacts (".") use ("share");
end Install;
for Source_Files use
("cairos.adb", "cairos_config.ads",
"sub_cairos.adb", "sub_cairos.ads", "testcairo_drawing.adb", "testcairo_drawing.ads");
package Pretty_Printer is
for Default_Switches ("ada") use ("-M99", "-cl3");
end Pretty_Printer;
end Cairos;
Build
Build message
gprbuild -d -P/home/mm/ada/s_testgtk/cairos/cairos.gpr -XLIBRARY_TYPE=static -XBUILD=Production -XGTK_PREFIX=/home/mm/.local/share/alire/builds/gtkada_25.0.1_d3787772/05561da954afaee17128f59bba699db2f2e4a4215317b2b818a8016192c82334/ -XOBJCFLAGS= -XLDFLAGS= -XCPPFLAGS= -XCFLAGS= -XADAFLAGS=
Compile
[Ada] cairos.adb
[Ada] sub_cairos.adb
Bind
[gprbind] cairos.bexch
[Ada] cairos.ali
Link
[link] cairos.adb
[2025-06-25 14:56:35] process terminated successfully, elapsed time: 01.40s
Execution
Execution is available in both GnatStudio and Terminal mode.
~/ada/s_testgtk/cairos$ cd bin
~/ada/s_testgtk/cairo/bin$ ./cairos