One of the main targets of the forthcoming fifth-generation (5G) cellular network will be the support of the communications for billions of sensors and actuators, so as to finally realize the Internet of things (IoT) paradigm. This pervasive scenario unavoidably requires the design of cheap antenna systems with beamforming capabilities for compensating the strong attenuations that characterize the millimeter-wave (mmWave) channel. To address this issue, this paper proposes an iterative algorithm for sparse antenna arrays that enables to derive the number of elements, their amplitudes, phases, and positions in the presence of constraints on the far-field pattern. The algorithm, which relies on the compressive sensing approach, is formulated by transforming the original nonconvex optimization problem into a convex one. To prove the suitability of the conceived solution for 5G IoT mmWave applications, numerical examples and comparisons with other existing methods are provided, considering synthesis problems with different pattern and aperture specifications.