Including glib.h in the CMake project

Trying to compile a library in Ubuntu using CMake, and one of the files is glib.h. The package is installed and glib.h is located in /usr/include/glib-2.0/glib.h .

I added the following, but the compiler still cannot find glib.h.

 FIND_PACKAGE(glib-2.0) IF (glib-2.0_FOUND) INCLUDE_DIRECTORIES(${glib-2.0_INCLUDE_DIR}) ENDIF() 

Does anyone know which package I should look for?

The actual code I used is

 find_package(PkgConfig REQUIRED) pkg_check_modules(GLIB_PKG glib-2.0) if (GLIB_PKG_FOUND) message(Found glib-2.0) include_directories(${GLIB_PKG_INCLUDE_DIRS}) 
+6
source share
1 answer

I suggest you follow the link: How does package search work .

As a reference, you can look at this CMake Module for glib2 search.

Your line of interest is here:

 find_path(GLIB_INCLUDE_DIR NAMES glib.h PATH_SUFFIXES glib-2.0) 

I suggest you copy this module to the <project root>/cmake/ directory. And then use find_package in the root CMakeLists.txt file.

+3
source

Source: https://habr.com/ru/post/914528/


All Articles