cmake: enable hardening compiler flags and fix the reported issues