The modern and portable way is
file(REAL_PATH "~" HOME EXPAND_TILDE)
This would set the CMake variable HOME to the value of the HOME environment variable.
HOME
On Windows, the USERPROFILEenvironment variable might be used instead.
USERPROFILE