Evolution of the long water waves and small-amplitude surface waves with the weak nonlinearity, weak dispersion and weak perturbation in fluid mechanics in three spatial dimensions can be described by a generalized (3+1)-dimensional variable-coefficient Kadomtsev–Petviashvili equation, which is studied in this paper with symbolic computation. Via the truncated Painlevé expansion, an auto-Bäcklund transformation is derived, based on which, under certain variable-coefficient constraints, one-soliton, two-soliton, homoclinic breather-wave and rouge-wave solutions are respectively obtained via the Hirota method. Graphic analysis shows that the soliton propagates with the varying soliton direction. Change of the value of any one of g(t), m(t), n(t), h(t), q(t) and l(t) in the equation can cause the change of the soliton shape, while the soliton amplitude cannot be affected by that change, where g(t) represents the dispersion, m(t) and n(t) respectively stand for the disturbed wave velocities along the y and z directions, h(t), q(t) and l(t) are the perturbed effects, y and z are the scaled spatial coordinates, and t is the temporal coordinate. Soliton direction and type of the interaction between the two solitons can vary with the change of the value of g(t), while they cannot be affected by m(t), n(t), h(t), q(t) and l(t). Homoclinic breather wave and rouge wave are respectively displayed, where the rouge wave comes from the extreme behaviour of the homoclinic breather wave.