Fix compatibility with older versions of CMake.

Fixes #6240