I had the $XDG_DATA_DIRS variable set to a custom location - apparently, this is not needed for my setup and messed up kbuildsycoca. To fix this, I had to unset the variable and ran kbuildsycoca4 --noincremental.

Also, the cmake error I got is irrelevant - you should build the sources from a top directory (in this case, kdelibs).