cmake: rework elf detection (#1058)

6 files changed