[1.6.x] Fixed #21558 -- Support building CHM files.

Thanks Michał Pasternak.

Backport of cd9e85ec from master.