Cam mechanisms are used as the control system in several industrial fields such as filling and canning, textiles, automotive. This paper introduces the development of a software for designing planar cam mechanism adapting the dynamic and kinematic requirements. The designed cam profile is then changed into numerical data used to generate the machine codes served for CNC-based fabrication. Traditional cam design is very complicated and has accumulated errors. The envelope theory and inverse method are utilized to perform constraint in pressure angle and motion. The smallest cam radius is then determined in a non-linear optimization adapting the constraints. The paper also presents the design of a CNC machine for cam profile fabrication. The design includes the control system and the circuit board. The CNC control program is built to receive numerical data from cam design section, to simulate the cam profile fabrication and then to fabricate. The optimal design and fabrication are applied to the cam mechanisms with knife-edge/roller reciprocating/oscilating followers. The verification shows that the designed and fabricated cam adapts the requirement of accuracy.