Last active
June 22, 2024 21:33
-
-
Save fracek/3323924 to your computer and use it in GitHub Desktop.
CMake and GTK+ 3
This file contains hidden or 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
# Thanks to @danger89 and @Ilothar for updating the gist. | |
# Set the name and the supported language of the project | |
project(hello-world C CXX) | |
# Set the minimum version of cmake required to build this project | |
cmake_minimum_required(VERSION 3.10) | |
# Use the package PkgConfig to detect GTK+ headers/library files | |
find_package(PkgConfig REQUIRED) | |
pkg_check_modules(GTK REQUIRED gtkmm-3.0) | |
add_executable(hello main.cpp) | |
target_link_libraries(hello PRIVATE ${GTKMM_LIBRARIES}) | |
# Add other flags to the compiler | |
target_compile_definitions(hello PRIVATE ${GTKMM_CFLAGS_OTHER}) | |
# Setup CMake to use GTK+, tell the compiler where to look for headers | |
# and to the linker where to look for libraries | |
target_include_directories(hello PRIVATE ${GTKMM_INCLUDE_DIRS}) | |
target_link_directories(hello PRIVATE ${GTKMM_LIBRARY_DIRS}) |
This file contains hidden or 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); | |
} |
I'm having a problem with these three lines, it says called with incorrect number of arguments:
target_include_directories(${PROJECT_TARGET} PRIVATE ${GTK_INCLUDE_DIRS})
target_link_directories(${PROJECT_TARGET} PRIVATE ${GTK_LIBRARY_DIRS})
target_compile_options(${PROJECT_TARGET} ${GTK_CFLAGS_OTHER})
Did you set PROJECT_TARGET
variable as your target name for your project? I mean this variable should be set by you.
@fracek Please, fix your mistakes.
Can you change: pkg_check_modules(GTK REQUIRED gtkmm-3.0)
to: pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)
in your snippet. Line 10.
And change target_compile_definitions(hello PRIVATE ${GTKMM_CFLAGS_OTHER})
to target_compile_options(hello PRIVATE ${GTKMM_CFLAGS_OTHER})
. On line 18.
@revix-0 I think you should target_compile_options(${PROJECT_TARGET} ${GTK_CFLAGS_OTHER})
change to target_compile_options(${PROJECT_TARGET} PRIVATE ${GTK_CFLAGS_OTHER})
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@raulpy271 I said this litterly above your comment https://gist.github.com/fracek/3323924?permalink_comment_id=4023933#gistcomment-4023933