[CMake] Re: [ANN] New PkgConfig module

Enrico Scholz enrico.scholz at informatik.tu-chemnitz.de
Wed Nov 1 08:43:26 EST 2006


Maik Beckmann <maikbeckmann at gmx.de> writes:

> 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 ...

afais, the latter naming convention is required by 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.

My module:

* sets <PREFIX>_FOUND iff pkgconfig succeeded
* bails out with a (more or less ugly[1]) error message when the REQUIRED
  keyword was used


> first:
> pkg_config(MYPREFIX found "lib1 >= ??? lib2 >= ??? ...")
> if(NOT found)
> 	# FATAL_ERROR of looking for alternatives ...
> ...
> if(NOT MYPREFIX_FOUND)
> 	# FATAL_ERROR of looking for alternatives ...

I think, both are possible at the same time. But by implementing the
first variant you will run into the used-variables problem ('found'
might be used by the local CMakeLists.txt already).



> 3. protect already defined variables
> How can we ensure that variables of the module-user won't be overwritten

This is probably a common cmake problem. I could not find a clear
description how variables are scoped in cmake.

As a general rule, I use:

* macro arguments and FOREACH(...) iterators can be short names because
  they are substituted as-is.
* variables which are modified by SET(...) in a module and will not be
  exported must have a long and ugly name, composed e.g. by an underscore
  and the module/function name.


> MACRO(...)   
>  SET(PKGCONFIG_PRIVATE_list_of_used_vars 

good idea; but how do you protect the global
'PKGCONFIG_PRIVATE_list_of_used_vars' variable?



Enrico

Footnotes: 
[1]  probably a cmake 2.4.3 bug because valgrind complains heavily. Did
     not tested with 2.4.4 yet




More information about the CMake mailing list