Can't sign in to iCloud as already signed in
I'm struggling to sign in to iCloud in System Preferences on my Mac. Every time I try I get a message saying that my account is already signed in to iCloud and "To use this Apple ID as your primary iCloud account, delete it from Internet Accounts and sign in again."
But when I open Internet Accounts I find there are no accounts added. I don't have my iCloud account set up with Mail but my 4 other Gmail addresses are all set up there and syncing properly even though they don't appear in internet accounts or in Mail preferences under "accounts".
I've tried restarting and safe booting neither of which make any difference.
On iPhone or iPad everything ok
In iTunes on this mac everything ok with Apple Music account too
iMac 2012 with Mojave