MantisBT - CMake
View Issue Details
0012317CMakeCMakepublic2011-07-05 19:112016-06-10 14:31
Aaron Simmons 
Kitware Robot 
highminoralways
closedmoved 
UnixUbuntu11.04
CMake 2.8.4 
 
0012317: pkg_check_modules produces output incompatible with other cmake variables
Using pkg_check_modules outputs XXX_LDFLAGS as a list (semi-colon delimited) whereas CMAKE_EXE_LINKER_FLAGS requires a flat space-delimited string.

Run this code on Ubuntu 11.04:
   # setup glib2
   pkg_check_modules(GLIB2 REQUIRED glib-2.0)
   message("GLIB2_LDFLAGS= ${GLIB2_LDFLAGS}")
   add_definitions(${GLIB2_CFLAGS} ${GLIB2_CFLAGS_OTHER})
   set( CMAKE_EXE_LINKER_FLAGS ${GLIB2_LDFLAGS})
This will output:
   GLIB2_LDFLAGS= -L/usr/lib/i386-linux-gnu;-lglib-2.0
which when put into CMAKE_EXE_LINKER_FLAGS, will create invalid flags for gcc-- it will literally emit "-L/usr/lib/i386-linux-gnu;-lglib-2.0" to the command-line.


It's unclear how pkg_check_modules is intended to be used-- are we supposed to write custom code transform its output? Why?
No tags attached.
Issue History
2011-07-05 19:11Aaron SimmonsNew Issue
2011-07-06 12:04Alex NeundorfNote Added: 0027012
2012-08-11 11:38David ColeStatusnew => backlog
2012-08-11 11:38David ColeNote Added: 0030275
2015-09-11 18:06Dan KegelNote Added: 0039408
2015-09-11 18:07Dan KegelNote Edited: 0039408bug_revision_view_page.php?bugnote_id=39408#r1893
2016-06-10 14:28Kitware RobotNote Added: 0041857
2016-06-10 14:28Kitware RobotStatusbacklog => resolved
2016-06-10 14:28Kitware RobotResolutionopen => moved
2016-06-10 14:28Kitware RobotAssigned To => Kitware Robot
2016-06-10 14:31Kitware RobotStatusresolved => closed

Notes
(0027012)
Alex Neundorf   
2011-07-06 12:04   
That's a weakness of pkg-config, if you want to use it in cmake basically you have to deal with it.
What I usually recommend:
use the results of pkg-config as HINTS to find_path() and find_library(), so if pkg-config has found the package, the dirs it reported will be checked first by find_library() and find_path(). If pkg-config has not found the package, cmake may still find it.
This also makes sure that the cmake code will also work on systems without pkg-config or where it is not properly set up.
I.e. something like:

FIND_PACKAGE(PkgConfig)
PKG_CHECK_MODULES(PC_LIBXML libxml-2.0 QUIET)
SET(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER})

FIND_PATH(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h
   HINTS
   ${PC_LIBXML_INCLUDEDIR}
   ${PC_LIBXML_INCLUDE_DIRS}
   PATH_SUFFIXES libxml2
   )

FIND_LIBRARY(LIBXML2_LIBRARIES NAMES xml2 libxml2
   HINTS
   ${PC_LIBXML_LIBDIR}
   ${PC_LIBXML_LIBRARY_DIRS}
   )
(0030275)
David Cole   
2012-08-11 11:38   
Sending old, never assigned issues to the backlog.

(The age of the bug, plus the fact that it's never been assigned to anyone means that nobody is actively working on it...)

If an issue you care about is sent to the backlog when you feel it should have been addressed in a different manner, please bring it up on the CMake mailing list for discussion. Sign up for the mailing list here, if you're not already on it: http://www.cmake.org/mailman/listinfo/cmake [^]

It's easy to re-activate a bug here if you can find a CMake developer who has the bandwidth to take it on, and ferry a fix through to our 'next' branch for dashboard testing.
(0039408)
Dan Kegel   
2015-09-11 18:06   
(edited on: 2015-09-11 18:07)
You have to fix the list separator. It's rather painful. e.g.:
  pkg_check_modules(GSTREAMER gstreamer-1.0)
  # Ah, cmake, gotta love your list separator.
  STRING(REPLACE ";" " " GSTREAMER_CFLAGS_STRING "${GSTREAMER_CFLAGS}")
  STRING(REPLACE ";" " " GSTREAMER_LDFLAGS_STRING "${GSTREAMER_LDFLAGS}")
  pkg_check_modules(GSTREAMER_APP REQUIRED gstreamer-app-1.0)
  STRING(REPLACE ";" " " GSTREAMER_APP_CFLAGS_STRING "${GSTREAMER_APP_CFLAGS}")
  STRING(REPLACE ";" " " GSTREAMER_APP_LDFLAGS_STRING "${GSTREAMER_APP_LDFLAGS}")
...

That undoes some of the brain damage. Woe until you if a library has a space in a filename, though!

(0041857)
Kitware Robot   
2016-06-10 14:28   
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.