The build vs. buy decision is made thousands of times a year by technology leaders. Most get it wrong in predictable ways.
The Differentiation Test
Capabilities that are genuine sources of competitive differentiation are strong candidates for custom development. Your competitors can buy the same off-the-shelf solution you can. Custom software, done well, can create capabilities they can't easily replicate. Commodity functions are almost always better bought.
Total Cost of Ownership
The most common mistake in build vs. buy analysis is comparing the purchase price of a commercial product to the development cost of a custom alternative, while ignoring the ongoing costs of both. Neither is free after the initial investment.