In this paper, we investigate transmit beampattern optimization techniques for a multiple-input multiple-output radar in the presence of a legitimate communications receiver and an eavesdropping target. The primary objectives of the radar are to satisfy a certain target-detection criterion and to simultaneously communicate safely with a legitimate receiver by maximizing the secrecy rate against the eavesdropping target. Therefore, we consider three optimization problems, namely target return signal-to-interference-plus-noise ratio maximization, secrecy rate maximization, and transmit power minimization. However, these problems are nonconvex due to the nonconcavity of the secrecy rate function, which appears in all three optimizations either as the objective function or as a constraint. To solve this issue, we use Taylor series approximation of the nonconvex elements through an iterative algorithm, which recasts the problem as a convex problem. Two transmit covariance matrices are designed to detect the target and convey the information safely to the communication receiver. Simulation results are presented to validate the efficiency of the aforementioned optimizations.