While the story is not a direct adaptation, the movie borrows concepts from a comic by Frank Miller titled The Dark Knight Returns
Here is an article that explores the two works of art (the comic was published first. 10 Times Batman V Superman Directly Used Frank Miller's The Dark Knight Returns
Batman’s Tactics Against Superman
We’ve got to hand it to Zack Snyder. Although the fight between The Dark Knight and the Man of Steel isn’t very lengthy in Batman V Superman: Dawn of Justice, he managed to make it about as badass as it could possibly be. Part of the reason we love this fight so much is the way in which Snyder directly used tactics used by Batman in the original fight, and adapted them for the silver screen. From the power armor, to the use of sonic guns, booby traps, and even a cloud of kryptonite gas, Snyder did his homework on how Miller’s Batman took down the last son of Krypton.
Sadly, Zach Snyder will no longer work on the DC Movie Universe but it sounds like he planned to do something similar to what Injustice: Gods Among Us comic (and video game) planned according tho this article
Regarding the Knightmare scene, Snyder reportedly planned to make that an actual flash-forward that would be seen in Justice League—which actually makes more sense than it being a dream—with Superman having been turned evil by Darkseid.
The other big reveal from Snyder’s talk is that Darkseid would’ve killed Lois Lane, somehow setting off the chain of events that destroyed the world, leading Batman and Cyborg to send the Flash back in time to try and save her (explaining that now-unresolved tease where Flash shows up in BvS with an ominous warning for Batman).
Unlike the comic where it is the Joker that makes Superman turn to tyranny, it was Darkseid but regardless, it was not to be.