[CMake] PKGCONFIG backward compatibility on CVS trunk.

Alan W. Irwin irwin at beluga.phys.uvic.ca
Tue Dec 5 18:58:22 EST 2006


On 2006-12-05 23:51+0100 Michel Hermier wrote:

> Alan W. Irwin wrote:
>> On 2006-12-05 22:31+0100 Michel Hermier wrote:
>> 
>>>>> 
>>>> Do you have a case where something works in CMake-2.4.4, but does not 
>>>> work in CVS CMake that uses UsePkgConfig.cmake?
>>>> If so, we will fix it.  If this is new stuff, we can not change 
>>>> UsePkgConfig.cmake because it will break old code.   There should
>>>> be no change in this stuff from 2.4.4 and 2.4.5, so either should work 
>>>> the same.  The new module is currently only in CVS.
>>>> 
>>>> -Bill
>>>> 
>> 
>>> I checked the generation of the qca.pc file and it was not updated for 2 
>>> month so it was definitely working before the update.
>> 
>> Michel, could you clarify, please?  Are you comparing an old CVS version
>> with latest CVS or an _actual release_ (such as 2.4.5 which is available 
>> for
>> you to try) with latest CVS?
> I reverted the UsePkgConfig.cmake, so that the old macro is defined, and it 
> worked again, so the package that broke for me was really working with the 
> old macro.
> Here is attached the hack that works for me and is probably not valid since I 
> don't check for empty values but I'm not sure.

It appears the 2.4.5 version of UsePkgConfig.cmake is what you need. I
therefore believe the current approach in cvs (although it works
consistently for PLplot for 2.4.5 and cvs version) is attempting the
impossible; emulate the old behaviour by using the modern macros with
post-processing to attempt to make the result _exactly_ compatible.

Therefore, I suggest the following improved proposal to take care of these
compatibility issues exactly.

1) Copy the 2.4.5 UsePkgConfig.cmake which defines the PKGCONFIG macro to
CVS with the only change being to add a message that it is an obsolete
macro.  Then you _know_ that if the user uses UsePkgConfig.cmake they will
automatically be compatible with what was done before.

2) Get rid of the emulated definition of the PKGCONFIG macro that is
currently in FindPkgConfig.cmake.  In other words, FindPkgConfig.cmake is
completely reserved for the new pkg-config stuff and does not try to emulate
the old PKGCONFIG macro.

I attach a patch to current CVS that implements this proposal.  It works
for PLplot.

Michel, does this patch work for you?

Alan
__________________________
Alan W. Irwin

Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).

Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the Yorick front-end to PLplot (yplot.sf.net); the
Loads of Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________

Linux-powered Science
__________________________
-------------- next part --------------
diff -Naur --exclude='*~' Modules_old/FindPkgConfig.cmake Modules/FindPkgConfig.cmake
--- Modules_old/FindPkgConfig.cmake	2006-11-27 16:25:24.000000000 -0800
+++ Modules/FindPkgConfig.cmake	2006-12-05 15:38:09.000000000 -0800
@@ -355,31 +355,6 @@
   endif(NOT DEFINED __pkg_config_checked_${_prefix} OR __pkg_config_checked_${_prefix} LESS ${PKG_CONFIG_VERSION})  
 endmacro(pkg_search_module)
 
-### 
-macro(PKGCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
-  message(STATUS "WARNING: you are using the obsolete 'PKGCONFIG' macro")
-  _pkg_check_modules_internal(0 0 _PKGCONFIG_TMP "${_package}")
-  if (_PKGCONFIG_TMP_FOUND)
-    # To be compatible with obsolete module must return blank-delimited strings.
-    # Also, lead with a blank (for TRUE/FALSE compatibility, 2.4.4 appears to
-    # have returned a blank sometimes followed by nl for the situation
-    # where the pkg-config  module has been found [e.g., _PKGCONFIG_TMP_FOUND]
-    # but does not define the desired quantity.
-    string(REGEX REPLACE ";" " " ${_include_DIR} " ${_PKGCONFIG_TMP_INCLUDE_DIRS}")
-    string(REGEX REPLACE ";" " " ${_link_DIR}	 " ${_PKGCONFIG_TMP_LIBRARY_DIRS}")
-    string(REGEX REPLACE ";" " " ${_link_FLAGS}	 " ${_PKGCONFIG_TMP_LDFLAGS}")
-    string(REGEX REPLACE ";" " " ${_cflags}	 " ${_PKGCONFIG_TMP_CFLAGS}")
-    set(_return_VALUE 0)
-  else(_PKGCONFIG_TMP_FOUND)
-    set(${_include_DIR})
-    set(${_link_DIR})
-    set(${_link_FLAGS})
-    set(${_cflags})
-    set(_return_VALUE 1)
-  endif(_PKGCONFIG_TMP_FOUND)
-endmacro(PKGCONFIG)
-
-
 ### Local Variables:
 ### mode: cmake
 ### End:
diff -Naur --exclude='*~' Modules_old/UsePkgConfig.cmake Modules/UsePkgConfig.cmake
--- Modules_old/UsePkgConfig.cmake	2006-11-27 10:53:12.000000000 -0800
+++ Modules/UsePkgConfig.cmake	2006-12-05 15:42:36.000000000 -0800
@@ -1,6 +1,6 @@
 # - obsolete pkg-config module for CMake
 #
-# Includes FindPkgConfig.cmake which defines 
+# Defines the following macros:
 #
 # PKGCONFIG(package includedir libdir linkflags cflags)
 #
@@ -10,11 +10,38 @@
 # variable will be empty when the function returns, otherwise they will contain the respective information
 #
 
-INCLUDE(FindPkgConfig)
-# Retain backwards compatibility with old PKGCONFIG_EXECUTABLE name.
-IF(PKG_CONFIG_EXECUTABLE)
-  SET(PKGCONFIG_EXECUTABLE ${PKG_CONFIG_EXECUTABLE})
-ELSE(PKG_CONFIG_EXECUTABLE)
-  SET(PKGCONFIG_EXECUTABLE PKGCONFIG_EXECUTABLE-NOTFOUND)
-ENDIF(PKG_CONFIG_EXECUTABLE)
 
+
+FIND_PROGRAM(PKGCONFIG_EXECUTABLE NAMES pkg-config PATHS /usr/local/bin )
+
+MACRO(PKGCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
+  message(STATUS "WARNING: you are using the obsolete 'PKGCONFIG' macro")
+# reset the variables at the beginning
+  SET(${_include_DIR})
+  SET(${_link_DIR})
+  SET(${_link_FLAGS})
+  SET(${_cflags})
+
+  # if pkg-config has been found
+  IF(PKGCONFIG_EXECUTABLE)
+
+    EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
+
+    # and if the package of interest also exists for pkg-config, then get the information
+    IF(NOT _return_VALUE)
+
+      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=includedir OUTPUT_VARIABLE ${_include_DIR} )
+
+      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=libdir OUTPUT_VARIABLE ${_link_DIR} )
+
+      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --libs OUTPUT_VARIABLE ${_link_FLAGS} )
+
+      EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --cflags OUTPUT_VARIABLE ${_cflags} )
+
+    ENDIF(NOT _return_VALUE)
+
+  ENDIF(PKGCONFIG_EXECUTABLE)
+
+ENDMACRO(PKGCONFIG _include_DIR _link_DIR _link_FLAGS _cflags)
+
+MARK_AS_ADVANCED(PKGCONFIG_EXECUTABLE)


More information about the CMake mailing list