Catechism of the Catholic Church
1755 A morally good act requires the goodness of the object, of the end, and of the circumstances together. An evil end corrupts the action, even if the object is good in itself (such as praying and fasting "in order to be seen by men").
The object of the choice can by itself vitiate an act in its entirety. There are some concrete acts - such as fornication - that it is always wrong to choose, because choosing them entails a disorder of the will, that is, a moral evil.
1756 It is therefore an error to judge the morality of human acts by considering only the intention that inspires them or the circumstances (environment, social pressure, duress or emergency, etc.) which supply their context. There are acts which, in and of themselves, independently of circumstances and intentions, are always gravely illicit by reason of their object; such as blasphemy and perjury, murder and adultery. One may not do evil so that good may result from it.
IN BRIEF:
1757 The object, the intention, and the circumstances make up the three "sources" of the morality of human acts.
1758 The object chosen morally specifies the act of willing accordingly as reason recognizes and judges it good or evil.
1759 "An evil action cannot be justified by reference to a good intention" (cf. St. Thomas Aquinas, Dec. praec. 6). The end does not justify the means.
1760 A morally good act requires the goodness of its object, of its end, and of its circumstances together.
1761 There are concrete acts that it is always wrong to choose, because their choice entails a disorder of the will, i.e., a moral evil. One may not do evil so that good may result from it.
Notes:
English Translation of the Cathechism of the Catholic Church for the United States of America © 1997, United States Catholic Conference, Inc.