[CMake] [ANN] New PkgConfig module

Brad King brad.king at kitware.com
Wed Nov 1 08:50:43 EST 2006


Maik Beckmann wrote:
> Hello 
> 
> I would like to discuss three points
> 
> 1. naming conventions
> 2. what if pkg-config sends an error
> 3. protect already defined variables

Another approach to this problem is to setup the pkgconfig macros so
they can be used by Find*.cmake modules.  When a user wants to find
package Foo it should not matter how it is found.  The user should be
able to write

FIND_PACKAGE(FOO)

and get FOO_FOUND, FOO_INCLUDE_DIRS, etc. without knowing that it was
found via pkgconfig.  I'm not asking you to rewrite all our find modules
with your macros, but just to think about how the macros might be used
in the modules in the future.

> ------------------------------------
> 
> 1. naming conventions:
> 
> The interface will get a prefix like
>         pkg_check_modules(LIBNAME ...)
> 
> I would prefer to stick close to the command names, so
> 
> since INCLUDE_DIRECTORIES -> LIBNAME_INCLUDE_DIRECTORIES
> since LINK_DIRECTORIES -> LIBNAME_LINK_DIRECTORIES
> since LINK_LIBRARIES / TARGET_LINK_LIBRARIES -> LIBNAME_LINK_LIBRARIES
> since ADD_DEFINITIONS -> LIBNAME_DEFINITIONS
> 
> rather than 
> LIBNAME_INCLUDE_DIRS and
> LIBNAME_LINK_LIBS ...

The conventions used by other Find* modules are documented in the source
tree under CMake/Modules/readme.txt.

> ----------------------------------
> 2. what if the lib isn't found
> 
> This regards the pkg_check_modules interface. If the lib(s)
> wasn't/weren't found or version(s) to low the developer should be able
> to react.
> 
> IMHO there are two possible solution
> 
> first:
> pkg_config(MYPREFIX found "lib1 >= ??? lib2 >= ??? ...")
> if(NOT found)
> 	# FATAL_ERROR of looking for alternatives ...
> endif(NOT found)
> 
> second:
> pkg_config(MYPREFIX "lib1 >= ??? lib2 >= ??? ...")
> if(NOT MYPREFIX_FOUND)
> 	# FATAL_ERROR of looking for alternatives ...
> endif(NOT MYPREFIX_FOUND)
> 
> What do you're like more?

MYPREFIX_FOUND would be consistent with all the other Find* modules.

> ----------------------------------
> 3. protect already defined variables
> How can we ensure that variables of the module-user won't be overwritten
> 
> Just a random example...
> 
> set(varname ...)
> pkg_module_macro(...)
> #...
> # using varname
> 
> If inside the macro a
>     SET(varname ...)
> happens, the module user will be in trouble.
> 
> Is it possible to set variables being private?
> If not, we can use a prefix like
>     PKGCONFIG_PRIVATE_*
> for all internal variables. For more complex tasks this may be a little
> to verbose. So I played around doing something like this:
> 
> MACRO(...)   
>  SET(PKGCONFIG_PRIVATE_list_of_used_vars 
>             version_number_1_digits  
>             version_number_2_digits
>             version_number_1_digits_count
>             version_number_2_digits_count
>             to
>             digit_is
>             digit_min
>             digits_count_min )  

This is not necessary.  Just using the private prefix is good enough.
If PKGCONFIG_PRIVATE is too verbose just use "_" as a prefix.  This
convention has been followed by some other macro authors.

-Brad


More information about the CMake mailing list