CMake find_package built from source

336 Views Asked by At

I'm running a CMake script to build a tool on a SUSE machine where I dont have admin rights. All my libraries / packages are built from source or extracted from RPMs as prebuilt binaries.

In my CMake script, there is a line searching for a package like this

find_package(PkgConfig 0.27.1 REQUIRED)
find_package(GTK2 2.4 REQUIRED gtk gtkmm) 
pkg_check_modules(atkmm REQUIRED IMPORTED_TARGET atkmm-1.6>=2.24.2)

However I get one set of warnings and one error about not being able to find gtkmm (warning) or atkmm (error).

-- Some or all of the gtkmm libraries were not found. (missing: GTK2_GTKMM_LIBRARY GTK2_GTKMM_INCLUDE_DIR GTK2_GTKMMCONFIG_INCLUDE_DIR GTK2_GDKMM_INCLUDE_DIR GTK2_GDKMMCONFIG_INCLUDE_DIR GTK2_GDKMM_LIBRARY GTK2_GLIBMM_INCLUDE_DIR GTK2_GLIBMMCONFIG_INCLUDE_DIR GTK2_GLIBMM_LIBRARY)

-- Found PkgConfig: /usr/bin/pkg-config (found suitable version "0.29.2", minimum required is "0.27.1")
-- Checking for module 'atkmm-1.6>=2.24.2'
--   No package 'atkmm-1.6' found

Reading the somewhat dense documentation, I stumbled through and created cmake/Modules/Findatkmm.cmake with one line

set(ATKMM_LIBRARY ${HOME}/opt/atkmm/usr/lib64/libatkmm-1.6.so.1)

(Replaced actual home dir path with $HOME prefix for writing here). It still throws the same error when I try to run cmake

Clearly, I'm using this command wrong, and/or misunderstand what its supposed to be doing. Any guidance would be greatly appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

pkg_check_modules builds on top of pkgconfig and its .pc files to find dependencies. By default, pkgconfig only searches in /usr/lib/pkgconfig, but the environment variable PKG_CONFIG_PATH can be set to add additional search paths. Additionally, when your cmake_minimum_required version is 3.1 or later, CMake will by default also add all of the paths specified in CMAKE_PREFIX_PATH to that env variable.

So you have two options:

  • Setting PKG_CONFIG_PATH yourself before calling CMake
  • Setting CMAKE_PREFIX_PATH

In both cases you'll need to set the variable to the directory containing the atkmm.pc file, most likely ${HOME}/opt/atkmm/usr/lib64/pkgconfig in your case. If everything is configured correctly you will not need to set the ATKMM_LIBRARY variable directly.