[CMake] PKGCONFIG("dbus-1 >= 1.0.0" ...) should also possible

Claus Klein claus.klein at arcormail.de
Fri Jan 12 13:17:00 EST 2007


On Friday 12 January 2007 08:43, Alexander Neundorf wrote:
> 
> Von: Claus Klein <claus.klein at arcormail.de>
> 
> > Hi,
> > 
> > to be more flexible, here is a patch for UsePkgConfig.cmake
> > 
> > #   PKGCONFIG("dbus-1 >= 1.0.0" ...) is now also possible.
> > 
> > #   Optional, for stage building, the
> > #   PKGCONFIG_OPTIONS and PKG_CONFIG_PATH environment variable are used 
> ...
> 
> Thanks for the patch, but please have a look at the new FindPkgConfig.cmake module, 
> which is much more powerful than the "old" and now obsolete UsePkgConfig.cmake. 
> I think FindPkgConfig.cmake should already be able to do what you want.  
> 
> Bye
> Alex
> 
I have reviewed  the code of the new FindPkgConfig.cmake and I think, the version check part:
line209,242
---------------------------------------------------------
      # check whether version is given
      if (_pkg_check_modules_pkg MATCHES ".*(>=|=|<=).*")
        string(REGEX REPLACE "(.*[^><])(>=|=|<=)(.*)" "\\1" _pkg_check_modules_pkg_name "${_pkg_check_modules_pkg}")
        string(REGEX REPLACE "(.*[^><])(>=|=|<=)(.*)" "\\2" _pkg_check_modules_pkg_op   "${_pkg_check_modules_pkg}")
        string(REGEX REPLACE "(.*[^><])(>=|=|<=)(.*)" "\\3" _pkg_check_modules_pkg_ver  "${_pkg_check_modules_pkg}")
      else(_pkg_check_modules_pkg MATCHES ".*(>=|=|<=).*")
        set(_pkg_check_modules_pkg_name "${_pkg_check_modules_pkg}")
        set(_pkg_check_modules_pkg_op)
        set(_pkg_check_modules_pkg_ver)
      endif(_pkg_check_modules_pkg MATCHES ".*(>=|=|<=).*")

      # handle the operands
      if (_pkg_check_modules_pkg_op STREQUAL ">=")
        list(APPEND _pkg_check_modules_exist_query --atleast-version)
      endif(_pkg_check_modules_pkg_op STREQUAL ">=")

      if (_pkg_check_modules_pkg_op STREQUAL "=")
        list(APPEND _pkg_check_modules_exist_query --exact-version)
      endif(_pkg_check_modules_pkg_op STREQUAL "=")
      
      if (_pkg_check_modules_pkg_op STREQUAL "<=")
        list(APPEND _pkg_check_modules_exist_query --max-version)
      endif(_pkg_check_modules_pkg_op STREQUAL "<=")

      # create the final query which is of the format:
      # * --atleast-version <version> <pkg-name>
      # * --exact-version <version> <pkg-name>      
      # * --max-version <version> <pkg-name>
      # * --exists <pkg-name>
      if (_pkg_check_modules_pkg_op)
        list(APPEND _pkg_check_modules_exist_query "${_pkg_check_modules_pkg_ver}")
      else(_pkg_check_modules_pkg_op)
        list(APPEND _pkg_check_modules_exist_query --exists)
      endif(_pkg_check_modules_pkg_op)
---------------------------------------------------------
could be simpler and perhaps faster if the pkg-config features would be used:

from man:pkg-config(1):
---------------------------------------------------------
       --atleast-version=VERSION
       --exact-version=VERSION
       --max-version=VERSION

             Rather than using the version-test options, you can simply give a version constraint after each package
              name, for example:
                $ pkg-config --exists 'glib-2.0 >= 1.3.4 libxml = 1.8.3'
              Remember to use --print-errors if you want error messages.
---------------------------------------------------------

You only have to quote the args to pkg-config as in the example.

Just to keep it simple :-)

Bye
Claus


More information about the CMake mailing list