Comment 1 for bug 1523508

Revision history for this message
In , Marco Trevisan (TreviƱo) (3v1n0) wrote :

I'm Marco, from the Ubuntu desktop team; and we're facing an issue with
recent pkg-config when using it in cmake.

As per commit 50c2867f4a6981e085c721d936c96f174f11f415 in pkg-config,
variables are unquoted.

This is fine for most of scenarios, but when there are variables such as

 CPPflags=-I${includedir} -I${includedir}/xorg -I${sourcedir} \
 -DDUMMY_CONF_PATH=\"${datarootdir}/xorg/gtest/dummy.conf\" \
 -DLOGFILE_DIR=\"/tmp\"

Then when using the new pkg-config "pkg-config --variable=CPPflags"
returns something like:

 -I/usr/include -I/usr/include/xorg -I/usr/src/xorg-gtest \
 -DDUMMY_CONF_PATH="/usr/share/xorg/gtest/dummy.conf" \
 -DLOGFILE_DIR="/tmp"

Which is wrong since the quotes aren't escaped.

Changing the variable so that it uses something like
  -DLOGFILE_DIR=\\\"/tmp\\\"

Makes it return the proper thing, but not in a subshell, but it doesn't
seem the case.

In fact pkg-config seems to return the proper thing when called in a
subshell, but not when used directly.

I.e.:

$ pkg-config --variable=CPPflags xorg-gtest
+ pkg-config --variable=CPPflags xorg-gtest
-I/usr/include -I/usr/include/xorg -I/usr/src/xorg-gtest
-DDUMMY_CONF_PATH="/usr/share/xorg/gtest/dummy.conf" -DLOGFILE_DIR="/tmp"

$ gcc-5 $(pkg-config --variable=CPPflags xorg-gtest) foo.c
++ pkg-config --variable=CPPflags xorg-gtest
+ gcc-5 -I/usr/include -I/usr/include/xorg -I/usr/src/xorg-gtest
'-DDUMMY_CONF_PATH="/usr/share/xorg/gtest/dummy.conf"'
'-DLOGFILE_DIR="/tmp"' foo.c

As you can see when called in a subshell, the variables are properly
single-quoted, making the thing work. But when calling this directly
there are no single quotes.

So I'm wondering what's the best way to fix this case.