I have been searching for this for ages on my CM 11 android phone, running kitkat.
Well.. finally I found it. It's hidden in a totally unintuitive location:
- Go to settings
- Go to storage
- Open the menu and choose USB computer connection
Here you can choose between Media Device (MTP), Camera (PTP) and Mass storage (UMS). Turn them all off to get it to charge only.
Sadly, if the option is not there, it is not supported by the phone. This seems to be the case for my HTC One (M7).