# Proper usage of HANDLE\_COMPONENTS in custom FindXXX.cmake Module

**URL:** https://discourse.cmake.org/t/proper-usage-of-handle-components-in-custom-findxxx-cmake-module/1063
**Category:** Code
**Created:** [April 20, 2020, 2:32pm UTC](https://discourse.cmake.org/t/proper-usage-of-handle-components-in-custom-findxxx-cmake-module/1063 "2020-04-20T14:32:10Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![KBentley57](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kbentley57/32/474_2.png) [@KBentley57](https://discourse.cmake.org/u/KBentley57)
#### Post date: [April 20, 2020, 2:32pm UTC](https://discourse.cmake.org/t/proper-usage-of-handle-components-in-custom-findxxx-cmake-module/1063/1 "2020-04-20T14:32:10Z")

</div>

I am modernizing a bit of old CMake, and in the process, am re-writing a few module files. I’m following along the documentation in the cmake-developer man page, and generally have most things sorted. What I can’t seem to get is the proper handling of components.

I call find\_libary, find\_executable, and find\_path, as in the documentation, and I can get those paths reliably. I am thinking I’m supposed to pass those into find\_package\_handle\_standard\_args, under the REQUIRED\_VARS section, and the HANDLE\_COMPONENTS boolean is supposed to sort the details out.

Ex: Suppose I’m looking for a package that consists of a single header file, header.h, main executable, main, and two libraries, libA.so and libB.so. I’ve tried using the relevant section below, and while I can find all four parts, I can’t use it in the expected component signature way that I’m use to using myself; find\_package(PACKAGE 1.2 REQUIRED COMPONENTS A), to only find libA.so, and so on…

Do I have to sort it out myself, by using the components in the PACKAGE\_FIND\_COMPONENTS variable? I had the thought of looping over the components in that list, creating a separate list from those variables that match, and sending them into the REQUIRED\_VARS section, but that would seem redundant, or against the nature of the HANDLE\_COMPONENTS functionality.

Any advice? Using fairly recent versions, anywhere from 3.6 upwards.

Thanks.

```
find_program(PACKAGE_main_EXECUTABLE
    NAME main
    PATHS ${PACKAGE_BINARY_DIR})

find_library(PACKAGE_A_LIBRARY
    NAMES A
    PATHS ${PACKAGE_LIBRARY_DIR})

find_library(PACKAGE_B_LIBRARY
    NAMES B
    PATHS ${PACKAGE_LIBRARY_DIR})
    
find_path(PACKAGE_header_INCLUDE_DIR
    NAMES header.h
    PATHS ${PACKAGE_INCLUDE_DIR})

find_package_handle_standard_args(PACKAGE
REQUIRED_VARS
    PACKAGE_main_EXECUTABLE
    PACKAGE_header_INCLUDE_DIR
    PACKAGE_A_LIBRARY   
    PACKAGE_B_LIBRARY       
HANDLE_COMPONENTS
VERSION_VAR PACKAGE_VERSION)

mark_as_advanced(PACKAGE_main_EXECUTABLE
    PACKAGE_header_INCLUDE_DIR
    PACKAGE_A_LIBRARY   
    PACKAGE_B_LIBRARY)
```
