-2

I've been happily programming in C++ and compiling with g++ for quite a while. Not long ago, I'd decided to get an IDE, and I came accross juCi++.

This IDE is absolutely brilliant, but it uses CMake (or Meson) to build projects. This wasn't a problem, until I had to include a library (GTK+ 3.0 if you're wondering) using pkg-config. This could be done quite easily when compiling with g++, but, as I am completely new to CMake, I have no idea how to do it in the new IDE.

Can somebody please explain?

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
x64L
  • 1
  • 1
  • 3

1 Answers1

3

If your IDE handles CMake and Meson, it should be able to detect your project files. I'd say go for Meson, it's the future, and CMake syntax has a few quirks that Meson doesn't.

Meson:

Meson documentation

He's a basic meson.build that expects to find your application code in main.c and produces a binary named gtk3-test.

project('gtk3-test', 'c')

cc = meson.get_compiler('c')
deps = dependency ('gtk+-3.0')
sources = ['main.c']

executable('gtk3-test', sources, dependencies: deps)

CMake

CMake documentation

For CMake, just give a look at my answer to How do I link gtk library more easily with cmake in windows? (which also works under Linux). It was for GTK+2, but adapting it to GTK+3 is easy, so here's the CMakeLists.txt to use:

project (gtk3-test)
cmake_minimum_required (VERSION 2.4)

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

include_directories (${GTK3_INCLUDE_DIRS})
link_directories (${GTK3_LIBRARY_DIRS})
add_executable (gtk3-test main.c)
add_definitions (${GTK3_CFLAGS_OTHER})
target_link_libraries (gtk3-test ${GTK3_LIBRARIES})
Community
  • 1
  • 1
liberforce
  • 11,189
  • 37
  • 48
  • Thank you very much for the detailed explanation! – x64L Mar 11 '17 at 14:08
  • Looks like I'm using CMake the old way here, here's a link more neutral about modern CMake: https://www.reddit.com/r/linux/comments/6tsqcb/gtk_drops_autotools_in_favor_of_meson/dloiu1h/ – liberforce Oct 03 '17 at 16:05