How to use pkg-config in CMake (juCi++)

北城余情 提交于 2019-12-14 04:12:32

问题


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?


回答1:


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})


来源:https://stackoverflow.com/questions/42634710/how-to-use-pkg-config-in-cmake-juci

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!