Will Smith will star in “I Am Legend,” the long-gestating Warner Bros. adaptation of the Richard Matheson novel to be directed by “Constantine” helmer Francis Lawrence.

Smith has a pay-or-play deal to make “Legend” his next project, after he completes “Tonight, He Comes” at Sony.

“Legend” came closest to getting made back in 1997 with Ridley Scott directing Arnold Schwarzenegger. Warners applied the brakes because the budget hovered around $108 million, a figure considered high at the time. The fact Schwarzenegger was coming off the disappointing “Batman & Robin” and “Jingle All the Way” didn’t help matters.

Michael Bay and Smith then aligned to have a go at the film in 2002, but the pairing didn’t advance.

WB regained momentum last fall, when it assigned Lawrence to direct and Akiva Goldsman to rewrite and produce. The “Da Vinci Code” scribe has a working relationship with Smith from his last sci-fi hit, “I, Robot,” and from “Tonight, He Comes,” which Goldsman is producing with Michael Mann, Smith and James Lassiter.

Goldsman rewrote an original script by Mark Protosevich. Goldsman will produce with Erwin Stoff, David Heyman and Neal Moritz. The latter two originally set the picture up when they were partners, which illustrates just how long Warners has been trying to make the film.

Set in post-apocalyptic New York, “Legend” is about the last healthy man following the release of a virus that decimates the population. To survive, he must battle mutants that wreak havoc during the night.

Smith has a pretty full plate, having recently signed onto the Fox pitch “Greenbacks” and with plans to topline Universal’s adaptation of “It Takes a Thief.” Also on his schedule is a starring role in Columbia’s “Time Share” opposite Nicolas Cage.

Smith’s “Legend” deal clears the way for WB to plot an early 2007 start date on the actioner, which will be shot in New York.

WB will secure a co-financier to share its budget; sources said Village Roadshow Pictures is likely to be that partner.

Matheson’s tale previously formed the basis for the Vincent Price starrer “The Last Man on Earth” and the Charlton Heston vehicle “The Omega Man.”