5

I have copied a sample project from GTK

#include <gtkmm.h>

int main(int argc, char *argv[])
{
    auto app = Gtk::Application::create(argc, argv, "org.gtkmm.examples.base");

    Gtk::Window window;
    window.set_default_size(200, 200);

    return app->run(window);
}

And when compiling directly from terminal it works just fine:

g++ main.cpp -o simple `pkg-config gtkmm-3.0 --cflags --libs`

But when I try compilation using Clion it says

fatal error: gtkmm.h: No such file or directory
 #include <gtkmm.h>

My CMakeLists.txt looks like this:

cmake_minimum_required(VERSION 3.8)
project(songbook)

set(CMAKE_CXX_STANDARD 17)

find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK3 REQUIRED gtk+-3.0)

include_directories(${GTK3_INCLUDE_DIRS})
link_directories(${GTK3_LIBRARY_DIRS})

add_definitions(${GTK3_CFLAGS_OTHER})

set(SOURCE_FILES main.cpp)
add_executable(songbook ${SOURCE_FILES})

target_link_libraries(songbook ${GTK3_LIBRARIES})

What am I doing wrong?

sukovanej
  • 658
  • 2
  • 8
  • 18

1 Answers1

9

Solved thanks to https://github.com/DreaminginCodeZH/gtkmmproject! Final CMakeLists.txt:

cmake_minimum_required(VERSION 3.8)
project(songbook)

set(CMAKE_CXX_STANDARD 17)
find_package(PkgConfig)
pkg_check_modules(GTKMM gtkmm-3.0)

include_directories(${GTKMM_INCLUDE_DIRS})
link_directories(${GTKMM_LIBRARY_DIRS})

set(SOURCE_FILES main.cpp MainWindow.cpp MainWindow.h)
add_executable(songbook ${SOURCE_FILES})
target_link_libraries(${CMAKE_PROJECT_NAME} ${GTKMM_LIBRARIES})
sukovanej
  • 658
  • 2
  • 8
  • 18
  • 3
    CMake 3.6 and later supports `IMPORTED_TARGET` flag for `pkg_check_modules` command. With that flag using results of that command is very simple: `target_link_libraries(${CMAKE_PROJECT_NAME} PkgConfig::GTKMM)` (instead of using GTKMM-prefixed variables). See also [that question](https://stackoverflow.com/q/29191855/3440745) about general usage of `pkg-config` in CMake. – Tsyvarev Apr 08 '20 at 11:05