-
-
Save fracek/3323924 to your computer and use it in GitHub Desktop.
| # 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}) |
| #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); | |
| } |
The code:
target_compile_definitions(hello PRIVATE ${GTKMM_CFLAGS_OTHER})
are breaking my compilation. Because it insert the flag -D-pthread, this generate the error:
error: macro names must be identifiers
Like I said earlier in this thread. Should use target_compile_options(hello PRIVATE ${GTKMM_CFLAGS_OTHER}) instead.
@raulpy271 I said this litterly above your comment https://gist.github.com/fracek/3323924?permalink_comment_id=4023933#gistcomment-4023933
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})
Again, as said earlier in this thread, please use:
instead (so with
target_prefix).So DO NOT USE the following anymore: