CMake: warn on missing declarations
mark all local functions as static
CMake: warn on missing variable declarations
mark all local variables as static
avoid the extern keyword in .cpp files
remove unused globals

Also change globals into statics which are only used in one file
Merge pull request #579 from degasus/statics

Mark unexported global variables and functions as statics.