Skip to content

Commit 531a550

Browse files
committed
NEW: First commit with READMEs and basic Test App
0 parents  commit 531a550

File tree

5 files changed

+197
-0
lines changed

5 files changed

+197
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
**/build/macos

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# GTK+ v3 Examples (C++ Language)
2+
3+
This is a repository of C++ (C++11 and C++2a) examples of using GTK+ v3 to build Graphical User Interfaces for system applications using the `gtkmm` library for C++ bindings.
4+
5+
You can use `gtk`'s C bindings instead of `gtkmm`, but to write more modern code in C++ style we decided to use `gtkmm`.
6+
7+
For more testing purposes, we're also building with GCC 9 using the C++2a standard ("C++20") and testing out the latest language features with the GUI apps shown here.
8+
9+
Once you've followed the build-and-setup section, you should go to the [test_install](test_install/README.md) documentation and follow those instructions to verify that everything is setup correctly.
10+
11+
## Build and Setup
12+
13+
Follow the setup instructions for your system before trying to build, modify, or run any of the provided example subprojects in this repository.
14+
15+
### macOS Catalina (10.15.x)
16+
17+
Note that with macOS Catalina (10.15.x), Apple changed the default shell for the system and user accounts to be `zsh` instead of `bash`. You shouldn't need to change it to run anything here, but I built everything using `bash` instead of `zsh`, so for reference here's how I updated my config:
18+
19+
```zsh
20+
chsh -s /bin/bash;
21+
touch ~/.bash_profile;
22+
touch ~/.bashrc;
23+
echo "source ~/.bashrc" >> ~/.bash_profile;
24+
```
25+
26+
And then you can use either `~/.bashrc` or `~/.bash_profile` to put your shell preferences in. As configured, it's preferable to put everything in `~/.bashrc` since that'll be `source`-ed (read: "imported") by the `~/.bash_profile` file. I do this typically just to try and keep things more comparable to Linux systems that I use and work with, since they tend to only use a `~/.bashrc` config file and don't have the `~/.bash_profile` version. Most (if not all) of the configs are compatible between macOS and Linux, so putting everything into `~/.bashrc` this way can make the config more portable and reusable.
27+
28+
Again, the above is optional, but it's what I did, so there may be `bash`-specific commands referenced, and if you're using `zsh` you may get errors that I didn't. So please just be aware of that so that you don't get stuck or post a config-specific issue. If you'd like to request `zsh` support for this repo, please create an Enhancement issue on GitHub.
29+
30+
For the rest of the setup, the steps we'll follow are:
31+
32+
1. Install Homebrew, to make library installations consistent and (relatively) config-proof.
33+
1. Use Homebrew to install the GTK+ v3 library and its dependencies.
34+
1. Download and install a macOS compatible D Language Compiler.
35+
1. Download the `gtkd` source code.
36+
1. Build and install `gtkd`.
37+
38+
This process, all together, should take about 30-60 minutes with downloads and depending on your system specs.
39+
40+
1. [Homebrew](https://brew.sh/) install:
41+
```bash
42+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
43+
```
44+
1. C++ Compiler installation (we're using GCC 9.3.x from Homebrew):
45+
```bash
46+
bre install gcc;
47+
```
48+
1. Homebrew install GTK+ v3 to macOS system:
49+
```bash
50+
brew install gtk+3;
51+
brew install gtkmm3; # Optional, C++ bindings in-case you want to do C++ development.
52+
```
53+
1. Go to the [test_install README](test_install/README.md) and confirm that the application builds and runs.
54+
55+
## Examples
56+
57+
### test_install
58+
59+
Simple example to confirm that the installation of prerequisites was successful.
60+
61+
See the [test_install README](test_install/README.md) for more info.

test_install/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# test_install App
2+
3+
This is an example app to confirm that GTK+3 and gtkmm are installed, as well as a valid C++ compiler.
4+
5+
You should have been directed here as the first to run after cloning out this repository, to confirm that your system is ready for development with GTK+ v3.x.y (GTK+3).
6+
7+
## Prerequisites
8+
9+
- GTK+ v3 installed on system.
10+
- C++ Compiler (modern).
11+
- GNU Make v3.82 or higher.
12+
13+
## Tested System Setup
14+
15+
- macOS Catalina (10.15.4)
16+
- Homebrew: [https://brew.sh/](https://brew.sh/)
17+
- GTK+3 install: 3.24.18 (2020-04-14, macOS Homebrew)
18+
- GCC install: 9.3.0_1 (macOS Homebrew)
19+
- GNU Make (`gmake`) install: 4.3 (macOS Homebrew)
20+
21+
## Build
22+
23+
Currently this only supports macOS.
24+
25+
To build the application defined in the `src/` directory, use the following `bash` commands:
26+
27+
```bash
28+
cd <REPO_PATH>/build/macos/;
29+
make;
30+
```
31+
32+
The above should build an executable file named `test_install` that can be run (see below).
33+
34+
## Run
35+
36+
After following the build instructions:
37+
38+
```bash
39+
# ASSUMED: cd <REPO_PATH>/build/macos/;
40+
./test_install;
41+
```
42+
43+
That above command should pop-open a small Application Window with a few widgets in it.
44+
45+
If that succeeds, then your system is all set to run through the other examples.
46+
47+
If you get an error or some issue with any of the above commands, you'll need to re-review the prerequisites and confirm that your system is configured correctly.
48+
49+
## Executable Info
50+
51+
- Name: `test_install` (defined in `Makefile`)
52+
- Size: `20.15 kiB`

test_install/build/macos/Makefile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# GNU Make 4.3
2+
# macOS Build Script
3+
#
4+
# Tommy Vegetables (leafyrabbet)
5+
# leafyrabbet@gmail.com
6+
# Copyright (c) 2020, TenonGarden Productions
7+
8+
.RECIPEPREFIX = +
9+
10+
CC_STD = c++2a
11+
GCC := gcc-9 --std=$(CC_STD)
12+
FLAGS = -Wall -Wextra -Werror -pedantic -g
13+
14+
LIB_GTKMM = gtkmm-3.0
15+
LIB_GLIB = glib-2.0
16+
LIBS := `pkg-config $(LIB_GTKMM) $(LIB_GLIB) --cflags --libs` -lstdc++
17+
18+
BINTAG ?= # `date +D%Y.%m.%d_T%H.%M.%S_Z%z`
19+
EXE_NAME_BASE ?= test_install
20+
21+
SRC_DIR := ../../src
22+
23+
.DELETE_ON_ERROR:
24+
25+
.PHONY: all
26+
all:
27+
+ $(GCC) $(FLAGS) \
28+
-o $(EXE_NAME_BASE)$(BINTAG) \
29+
$(SRC_DIR)/main.cpp \
30+
$(LIBS)
31+
+ chmod +x $(EXE_NAME_BASE)$(BINTAG)
32+
33+
.PHONY: clean
34+
clean:
35+
+ rm ./$(EXE_NAME_BASE)

test_install/src/main.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @defgroup MAIN main
3+
*
4+
* @brief GTK+3 (gtkmm, C++ Bindings) example window launcher app.
5+
*
6+
* A minimal-ish proof-of-concept app that confirms that GTK+3 and gtkmm are
7+
* installed properly by launching a small window with an editable textbox
8+
* and 2 checkboxes below it.
9+
*
10+
* Implemented based-on the example shown here:
11+
* https://developer.gnome.org/gtkmm-tutorial/stable/sec-text-entry.html.en
12+
*
13+
* @author Tommy Vegetables <leafyrabbet@gmail.com>
14+
* @date 2020-05-16
15+
* @copyright 2020, TenonGarden Productions
16+
*/
17+
#include <gtkmm.h>
18+
19+
int main(int argc, char * argv[])
20+
{
21+
auto app = Gtk::Application::create(
22+
argc
23+
, argv
24+
, "leafyrabbet_app"
25+
);
26+
27+
Gtk::Window window;
28+
Gtk::Box box_layout(Gtk::ORIENTATION_VERTICAL);
29+
Gtk::Entry wdgt_textentry;
30+
Gtk::CheckButton wdgt_btn_success;
31+
Gtk::CheckButton wdgt_btn_fail;
32+
33+
window.set_default_size(420, 80);
34+
35+
wdgt_textentry.set_text("Success!");
36+
37+
box_layout.pack_start(wdgt_textentry);
38+
box_layout.pack_start(wdgt_btn_success);
39+
box_layout.pack_start(wdgt_btn_fail);
40+
41+
window.add(box_layout);
42+
43+
window.show_all_children();
44+
45+
auto ret_code = app->run(window);
46+
47+
return (ret_code);
48+
}

0 commit comments

Comments
 (0)