Manufacturing of workpieces with CNC machines requires computing machine tool trajectories that fast and accurately track the desired workpiece contour. This paper presents a novel B-spline trajectory generation method for machine tools. The method solves an optimal control problem to minimize the motion time of the tool, while taking into account the velocity, acceleration and jerk limits of the tool axes. Furthermore, it directly includes the allowed workpiece tolerance, by constraining the trajectory to lie inside a tube around the nominal geometry contour. This allows exploring the trade-off between accuracy and productivity, while computing near-optimal trajectories. The presented method creates fluent connections between segments that build up the contour by simultaneously optimizing trajectories for multiple segments. On the other hand, limiting the amount of simultaneously optimized segments and using an efficient problem formulation keeps the computation time acceptable. The trajectory generation method is validated in simulation by comparison with industrial benchmarks, showing a reduction in machining time of more than 10%. The comparison to a state-of-the-art corner smoothing approach shows that the presented method obtains similar or slightly faster trajectories, at a computation time that is up to 45 times lower. In addition, the method is validated experimentally on a 3-axis micro-milling machine. To easily generate trajectories for different workpieces and machines, the method is included in a user-friendly open-source software toolbox.