CMake - gflags support, bugfix, rebased onto BVLC/dev

Description in title and commit message.