Skip to content

Instantly share code, notes, and snippets.

@vrkansagara
Forked from fracek/CMakeLists.txt
Created January 7, 2021 03:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vrkansagara/777cca5f4b1f78632c7eb411ae986db8 to your computer and use it in GitHub Desktop.
Save vrkansagara/777cca5f4b1f78632c7eb411ae986db8 to your computer and use it in GitHub Desktop.
CMake and GTK+ 3
# 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})
#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