-
-
Save 1ay1/29fcef85a68a47f6a87e2408f20a347e to your computer and use it in GitHub Desktop.
CMake and GTK+ 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set the name and the supported language of the project | |
PROJECT(hello-world C) | |
# Set the minimum version of cmake required to build this project | |
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) | |
# Use the package PkgConfig to detect GTK+ headers/library files | |
FIND_PACKAGE(PkgConfig REQUIRED) | |
PKG_CHECK_MODULES(GTK3 REQUIRED gtk+-3.0) | |
# Setup CMake to use GTK+, tell the compiler where to look for headers | |
# and to the linker where to look for libraries | |
INCLUDE_DIRECTORIES(${GTK3_INCLUDE_DIRS}) | |
LINK_DIRECTORIES(${GTK3_LIBRARY_DIRS}) | |
# Add other flags to the compiler | |
ADD_DEFINITIONS(${GTK3_CFLAGS_OTHER}) | |
# Add an executable compiled from hello.c | |
ADD_EXECUTABLE(hello main.c) | |
# Link the target to the GTK+ libraries | |
TARGET_LINK_LIBRARIES(hello ${GTK3_LIBRARIES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <gtk/gtk.h> | |
static void | |
activate(GtkApplication *app, | |
gpointer user_data) { | |
GtkWidget *window; | |
window = gtk_application_window_new(app); | |
gtk_window_set_title(GTK_WINDOW(window), "Hello GNOME"); | |
gtk_widget_show_all(window); | |
} | |
int | |
main(int argc, char **argv) { | |
GtkApplication *app; | |
int status; | |
app = gtk_application_new("org.gtk.example", | |
G_APPLICATION_FLAGS_NONE); | |
g_signal_connect(app, "activate", | |
G_CALLBACK(activate), NULL); | |
status = g_application_run(G_APPLICATION(app), argc, argv); | |
g_object_unref(app); | |
return (status); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment