1838 in the literal sense, from fruit + cake (n.). Slang meaning "lunatic person" is first attested 1952.
nutty as a fruitcake