Fix distribution plotter bug.

The bug was reported by Coverity. The iterator was dereferenced
while it reached the end of the container.
Add return of implicit gates.
CMake configuration for static builds.
More configuration for static builds.