1

This may be related to my previous question.

I copied the code from the "Simple Example" here.

I copied the cmake instructions from here.

The error I am getting is:

-- Checking for module 'gtkmm-3.0'
--   No package 'gtkmm-3.0' found
CMake Warning (dev) in CMakeLists.txt:
  No cmake_minimum_required command is present.  A line of code such as

    cmake_minimum_required(VERSION 3.10)

  should be added at the top of the file.  The version specified may be lower
  if you wish to support older CMake versions for this project.  For more
  information run "cmake --help-policy CMP0000".
This warning is for project developers.  Use -Wno-dev to suppress it.

-- Configuring done
-- Generating done
-- Build files have been written to: /path-to-files/

This is my CMakeLists.txt

project(SimpleExample)

find_package(PkgConfig REQUIRED)

set(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/pkgconfig;/usr/share/pkgconfig")

pkg_check_modules(GTKMM gtkmm-3.0)

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

add_executable(SimpleExample SimpleExample.cpp)

target_link_libraries(SimpleExample ${GTKMM_LIBRARIES})

There's a really dumb line in here set(CMAKE_PREFIX_PATH "/usr/lib/x86_64-linux-gnu/pkgconfig;/usr/share/pkgconfig") which I'm fairly sure isn't supposed to be there, however in my previous question I was struggeling to figure out why pkg-config wasn't finding the correct locations for the gtkmm-3.0.pc file.

So I did a search to try and figure out how to set the paths for pkg-config manually in a CMake file. That is what I came up with. However it does not work.

FreelanceConsultant
  • 13,167
  • 27
  • 115
  • 225
  • Why do not follow the warning message, and add a line like `cmake_minimum_required(VERSION 3.0)` at the top of your `CMakeLists.txt`? This warning message is longer than other parts of the build log together... – Tsyvarev Feb 05 '18 at 14:56
  • @Tsyvarev Becuase it's not relevant to the question? However I have added it, regardless. – FreelanceConsultant Feb 05 '18 at 15:19

1 Answers1

1

CMake variable CMAKE_PREFIX_PATH and environment variable PKG_CONFIG_PATH denote different paths:

  • CMAKE_PREFIX_PATH points to the installation prefix(es) of the one or more programs.

  • PKG_CONFIG_PATH points to location(s) of .pc files.

When CMake wants to call pkg-config via pkg_check_modules command, it translates content of CMAKE_PREFIX_PATH variable into PKG_CONFIG_PATH by appending sufficies to every path in CMAKE_PREFIX_PATH variable (see branch if(NOT "${_extra_paths}" STREQUAL "") in FindPkgConfig.cmake):

  • lib/pkgconfig
  • share/pkgconfig
  • lib32/pkgconfig or lib32/pkgconfig for some distros
  • some other system-specific sufficies

As you can see, you may obtain /usr/share/pkgconfig in PKG_CONFIG_PATH by using /usr in CMAKE_PREFIX_PATH.

But obtaining /usr/lib/x86_64-linux-gnu/pkgconfig in PKG_CONFIG_PATH is very questionable.

In any case, parameters described the host system itself are normally passed via environment or cmake arguments, not by the project's CMakeLists.txt. In given case command line

export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig:/usr/share/pkgconfig"

is much more simpler (and reliable) than setting CMAKE_PREFIX_PATH CMake variable.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153