MantisBT - CMake
View Issue Details
0014310CMakeModulespublic2013-07-24 20:492016-06-10 14:31
Michał Sawicz 
Kitware Robot 
normalmajoralways
closedmoved 
LinuxUbuntu13.10
CMake 2.8.11.2 
 
0014310: pkg_check_modules(FOO REQUIRED foo) completes even if foo's pkgconfig dependencies failed
When a .pc file contains a "Required: bar", CMake should fail if the module was REQUIRED and bar wasn't found.

pkg-config exits with exit code 1, but CMake proceeds like nothing happened, FOO_FOUND is set to 1, while all the other FOO_* remain empty.

This obfuscates missing dependencies and lets the build process continue, failing then due to missing headers / libraries.
CMakeLists.txt
==============
cmake_minimum_required(VERSION 2.8)

include(FindPkgConfig)

pkg_check_modules(FOO REQUIRED foo)

message("${FOO_FOUND}")
message("${FOO_INCLUDE_DIRS}")


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

Current
=======
quiet failure
CMake Output
============

$ PKG_CONFIG_PATH=. cmake .
-- Found PkgConfig: /usr/bin/pkg-config (found version "0.26")
-- checking for module 'foo'
-- found foo, version 0
Package bar was not found in the pkg-config search path.
Perhaps you should add the directory containing `bar.pc'
to the PKG_CONFIG_PATH environment variable
# === repeated multiple times ===
1

-- Configuring done
-- Generating done
-- Build files have been written to: /tmp/tmp
No tags attached.
patch cmake-pkgconfig-required.patch (5,060) 2013-11-15 03:43
https://public.kitware.com/Bug/file/4950/cmake-pkgconfig-required.patch
Issue History
2013-07-24 20:49Michał SawiczNew Issue
2013-11-15 03:42Arnaud FontaineNote Added: 0034453
2013-11-15 03:43Arnaud FontaineFile Added: cmake-pkgconfig-required.patch
2014-02-03 21:33Arnaud FontaineNote Added: 0035032
2014-12-16 06:24sobczykNote Added: 0037466
2015-10-26 11:35Dan KegelNote Added: 0039679
2016-06-10 14:29Kitware RobotNote Added: 0042325
2016-06-10 14:29Kitware RobotStatusnew => resolved
2016-06-10 14:29Kitware RobotResolutionopen => moved
2016-06-10 14:29Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0034453)
Arnaud Fontaine   
2013-11-15 03:42   
I get the same issue when pkgconfig fails when being called from _pkgconfig_invoke_dyn (FindPkgConfig.cmake as of cmake 2.8.12) for cflags as the exit status is not checked at this stage but only before.

I have attached a patch which fixes this issue even though it may not be that clean as I don't know cmake so well.
(0035032)
Arnaud Fontaine   
2014-02-03 21:33   
Anyone has had time to review the patch? Thanks.
(0037466)
sobczyk   
2014-12-16 06:24   
Are there any plans to fix this?
(0039679)
Dan Kegel   
2015-10-26 11:35   
Still present as of 3.4-rc1.

I'm considering working around it by only passing one library at a time,
and checking FOO_LIBRARIES rather than FOO_FOUND. If FOO_LIBRARIES is empty,
we've hit this bug, and I'll terminate my CMakeLists.txt.
(0042325)
Kitware Robot   
2016-06-10 14:29   
Resolving issue as `moved`.

This issue tracker is no longer used. Further discussion of this issue may take place in the current CMake Issues page linked in the banner at the top of this page.