Proper usage of HANDLE_COMPONENTS in custom FindXXX.cmake Module

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)