[CMake] Component support in FindPackageHandleStandardArgs

Johannes Zarl Johannes.Zarl at jku.at
Mon Dec 13 07:17:33 EST 2010


Hello list,

During a recent discussion about find_package modules and components,
the question came up how to best use FindPackageHandleStandardArgs
(FPHSA) with components.

One solution that currently works is to call FPHSA several times with
the qualified component name as "package name":

# Handle "core" package:
FPHSA(XXX DEFAULT_MSG XXX_LIBRARY XXX_INCLUDE_DIR)

# Handle explicitly requested component YYY:
# Set up (or not) XXX_YYY_LIBRARY, XXX_YYY_INCLUDE_DIR
SET(XXX_YYY_FIND_REQUIRED ${XXX_FIND_REQUIRED})
SET(XXX_YYY_FIND_QUIETLY ${XXX_FIND_QUIETLY})
FPHSA(XXX_YYY DEFAULT_MSG XXX_YYY_LIBRARY XXX_YYY_INCLUDE_DIR )

# Handle non-requested component ZZZ:
# Set up (or not) XXX_ZZZ_LIBRARY, XXX_ZZZ_INCLUDE_DIR
SET(XXX_ZZZ_FIND_REQUIRED FALSE)
SET(XXX_ZZZ_FIND_QUIETLY TRUE)
FPHSA(XXX_ZZZ DEFAULT_MSG XXX_ZZZ_LIBRARY XXX_ZZZ_INCLUDE_DIR )

IMO, the "new" syntax of FPHSA could easily extended to handle components
as well:

FPHSA(NAME [REQUIRED_VARS <var1>...<varN>]
     [COMPONENTS 
        [COMPONENT <cname> <cvar1>..<cvarN> [COMPONENT <cname> <cvar1>..<cvarN>[..]]]
        [[NO_]CHECK_REQUESTED_COMPONENTS]
     ]
     [VERSION_VAR   <versionvar>
     [CONFIG_MODE]
     [FAIL_MESSAGE "Custom failure message"] )

The component description begins with the keyword COMPONENTS, and has an
entry for each component (which starts with COMPONENT, followed by the 
component name (without the package-name prefix), and then lists all variables
required by the component. Components are checked after REQUIRED_VARS, in order
of their occurrence.

If CHECK_REQUESTED_COMPONENTS is set (=default), FPHSA also checks if any
other components have been requested by the user in the find_package command.

The three FPHSA calls from above could be written using this syntax as:
FPHSA(XXX REQUIRED_VARS XXX_LIBRARY XXX_INCLUDE_DIR
  COMPONENTS
    COMPONENT YYY XXX_YYY_LIBRARY XXX_YYY_INCLUDE_DIR
    COMPONENT ZZZ XXX_ZZZ_LIBRARY XXX_ZZZ_INCLUDE_DIR )

The attached patch implements this syntax for FPHSA.

Is this a desirable extension to FPHSA?

Cheers,
  Johannes



-- 
Johannes Zarl
Virtual Reality Services

Johannes Kepler University
Informationsmanagement

Altenbergerstrasze 69
4040 Linz, Austria
Phone: +43 732 2468-8321
johannes.zarl at jku.at
http://vrc.zid.jku.at










-------------- next part --------------
A non-text attachment was scrubbed...
Name: FindPackageHandleStandardArgs.cmake.diff
Type: application/octet-stream
Size: 4383 bytes
Desc: not available
URL: <http://www.cmake.org/pipermail/cmake/attachments/20101213/4828c29a/attachment.obj>


More information about the CMake mailing list