This paper considers solving optimal control of switched systems with polynomial data globally, where the number of switches and the switching signal are not preassigned. The problem is transformed into an embedded polynomial form in which a continuous variable controls the switching policy. Then, using occupation measures, the embedded optimal control problem is formulated as an infinite-dimensional linear programming (LP) over the space of measures. A polynomial sum-of-squares strengthening corresponding to conic dual of the measure LP problem provides an approximating optimal feedback control for both classical control and the switching signal. Furthermore, the optimal switching signal is calculated without mode projection. Finally, three simulation experiments are included to confirm the theoretical results in the paper.