MantisBT - CMake
View Issue Details
0015810CMakeModulespublic2015-10-27 01:292016-03-07 09:12
bchretien 
Brad King 
normalminoralways
closedfixed 
CMake 3.3.2 
CMake 3.5CMake 3.5 
0015810: FindPkgConfig.cmake: error returned to the user may be wrong when checking for package existence
In some cases, CMake returns the following error:

-- Checking for module 'foo'
-- Package 'foo' not found

When the actual error returned by pkg-config is actually:

  Package 'bar', required by 'foo', not found

This seems related to https://cmake.org/Bug/view.php?id=14310, [^] however I did not have the exact same problem: CMake does stop with an error, just not the correct one.
I used the same example as in https://cmake.org/Bug/view.php?id=14310 [^]

CMakeLists.txt
==============

cmake_minimum_required(VERSION 2.8)
include(FindPkgConfig)
pkg_check_modules(FOO REQUIRED foo)

foo.pc
======

Name: foo
Description: foo
Version: 0

Requires: bar
Cflags: -I/usr/include/foo

Steps
=====

# store both files in a directory
$ PKG_CONFIG_PATH=. cmake .

Expected
========

Failure, explaining that 'foo' was found but `bar` was not.

Current
======

Failure, explaining that 'foo' was not found.
I made a patch that solves this issue. Now, the actual error is forwarded to the user, for instance:

-- Checking for module 'foo'
-- Package 'bar', required by 'foo', not found

For the standard case (i.e. the package was indeed not found), the CMake error was:

-- Checking for module 'foo'
-- Package 'foo' not found

But with this patch, it now prints:

-- Checking for module 'foo'
-- No package 'foo' found
No tags attached.
patch 0001-FindPkgConfig-return-the-actual-error-when-a-package.patch (2,271) 2015-10-27 01:29
https://public.kitware.com/Bug/file/5559/0001-FindPkgConfig-return-the-actual-error-when-a-package.patch
patch 0001-FindPkgConfig-return-the-actual-error-when-a-package2.patch (2,993) 2015-10-27 11:12
https://public.kitware.com/Bug/file/5560/0001-FindPkgConfig-return-the-actual-error-when-a-package2.patch
Issue History
2015-10-27 01:29bchretienNew Issue
2015-10-27 01:29bchretienFile Added: 0001-FindPkgConfig-return-the-actual-error-when-a-package.patch
2015-10-27 09:34Brad KingNote Added: 0039681
2015-10-27 09:49bchretienNote Added: 0039682
2015-10-27 11:12bchretienFile Added: 0001-FindPkgConfig-return-the-actual-error-when-a-package2.patch
2015-10-27 11:13bchretienNote Added: 0039683
2015-10-28 10:22Brad KingNote Added: 0039697
2015-10-28 10:22Brad KingAssigned To => Brad King
2015-10-28 10:22Brad KingStatusnew => resolved
2015-10-28 10:22Brad KingResolutionopen => fixed
2015-10-28 10:22Brad KingFixed in Version => CMake 3.5
2015-10-28 10:22Brad KingTarget Version => CMake 3.5
2015-10-28 10:50bchretienNote Added: 0039698
2016-03-07 09:12Robert MaynardNote Added: 0040630
2016-03-07 09:12Robert MaynardStatusresolved => closed

Notes
(0039681)
Brad King   
2015-10-27 09:34   
Thanks for working on this. Do the --print-errors --short-errors options exist on all (old) versions of pkg-config?

Also this change makes the RunCMake.FindPkgConfig test fail. Please revise accordingly.
(0039682)
bchretien   
2015-10-27 09:49   
According to the pkg-config changelog (http://cgit.freedesktop.org/pkg-config/tree/ChangeLog [^] at least the one until 2009), --print-errors was added in 2001, and --short-errors in 2005 (release 0.20).

I will update the patch with the fixed test.
(0039683)
bchretien   
2015-10-27 11:13   
AFAIK, I could not upload a patch with the same name or remove the previous one, so I uploaded 0001-FindPkgConfig-return-the-actual-error-when-a-package2.patch.
(0039697)
Brad King   
2015-10-28 10:22   
Thanks, applied:

 FindPkgConfig: return actual error when a package is not found
 https://cmake.org/gitweb?p=cmake.git;a=commitdiff;h=1bfb527f [^]
(0039698)
bchretien   
2015-10-28 10:50   
Perfect, thanks!
(0040630)
Robert Maynard   
2016-03-07 09:12   
Closing resolved issues that have not been updated in more than 4 months.