U.S. aerospace giant Boeing (BA 0.39%) has been one of the best-performing large-cap stocks of the past year. In fact, the stock has nearly doubled since bottoming out last February. Over the last five years, Boeing stock has almost tripled.

By contrast, Embraer (ERJ 1.72%) -- which is a distant No. 3 in aircraft manufacturing -- has struggled mightily in recent years, largely due to weak demand for business jets. Embraer stock has fallen about 24% over the past five years.

BA Chart

Boeing Stock vs. Embraer Stock Performance, data by YCharts.

However, Boeing stock has flown so high that it no longer looks like a compelling buy. On the other hand, Embraer is primed to make a comeback within the next few years. As a result, Embraer stock now looks like a better investment opportunity.

Momentum is on Boeing's side -- but the valuation is getting stretched

A year or two ago, many investors were worried that an ongoing order slowdown would prevent Boeing from sustaining its production plans, particularly for widebody jets. Indeed, the company has had to reduce deliveries of its 777 widebody jet dramatically. Last year, it was building 8.3 per month. By the end of this year, 777 output will drop to 5 per month -- and the actual delivery rate will fall to just 3.5 per month in 2018.

Fortunately, order activity has improved during 2017 -- even for widebody jets. Additionally, Boeing recently started ramping up production of the profitable 737 family from 42 per month to 57 per month. Meanwhile, 787 Dreamliner production has finally turned profitable.

A rendering of the Boeing 737 MAX 8

Boeing is boosting production of the popular 737 family. Image source: Boeing.

As a result, Boeing's free cash flow rose from $6.9 billion in 2015 to $7.9 billion in 2016, and the company expects to generate free cash flow of about $8.45 billion this year. Based on its recent price, Boeing stock trades for about 15 times free cash flow.

That may not seem very expensive. However, aircraft manufacturing is a cyclical business, and it is probably closer to a peak than to a trough right now. Furthermore, Boeing may have to spend heavily between 2020 and 2030 to design all-new jets and bring them to market. This will put a damper on its free cash flow growth in the future.

Embraer's commercial airplane business has high potential

While Embraer has posted erratic financial results in recent years, its core commercial jet business is quite lucrative. Whereas Boeing has struggled to sustain a 10% operating margin in its commercial airplanes segment, Embraer's commercial aviation segment routinely earns 12%-13% margins.

Embraer has warned that commercial jet production and the segment's profit margin could dip next year as the company transitions to building the next-generation E2-series jets. This is a key reason the stock has been mired below the $20 level recently.

The rollout of the first Embraer E190-E2

Embraer's next-generation E190-E2 will enter service in early 2018. Image source: Embraer.

On the bright side, any dip in production and profit margins should be temporary. Embraer ended last quarter with 285 firm orders for E2-series jets, enough to support nearly three years of production. Some of those orders are likely to fall through, but Embraer has another 445 signed options, letters of intent, and purchase rights -- some of which will turn into firm orders in the coming years.

So far, the E2 jets have exceeded performance expectations in testing. That bodes well for future order activity. Embraer executives have said that they expect order volume to accelerate in the second half of 2017, as the 2018 entry-into-service date for the E190-E2 approaches. Of course, there is no guarantee that orders will materialize as expected, but the outlook is promising.

Embraer's other segments are getting back on track

Declining sales and weak margins in the executive jets and defense segments have also crimped Embraer's performance in recent years. In fact, both of those segments lost a good deal of money in the first quarter of 2017. However, Embraer's guidance indicates that performance in those business segments will be much better going forward.

Right now, the market is working through a glut of used business jets. When the supply-demand balance improves, sales and profitability in that segment could soar. In the meantime, Embraer is prioritizing margins over sales, which should lead to stronger profitability in the executive jets segment during the remainder of 2017.

As for the defense segment, sales and profits could rise dramatically in the next few years as Embraer ramps up output of its new KC-390 tanker/transport plane, which should be fully certified in 2018. Embraer hopes to eventually earn $1.5 billion annually from KC-390 export sales. By contrast, the entire defense segment generated less than $1 billion of revenue in 2016.

In spite of its massive long-term growth potential, Embraer stock trades for less than 11 times earnings. As the company gets profit growing again in the next couple of years, Embraer stock is likely to soar higher -- just as Boeing stock has skyrocketed in the past five years.