Let's work out some of the math here; the details of your build and your DM are going to influence how these numbers work out. Some assumptions I am making based on what you have stated.
Assumptions
- You said DM is letting you use flanking rules so I am assuming you are getting advantage on each attack so I am going to state that you are getting advantage on your rolls 75% of the time due to other skills and tactics you could be doing.
- I am assuming that your attack stat at this point is a 20 in any of the builds. I am ignoring barbarians right now who can get more then a 20 in a stat also I am ignoring belts or other items that can raise your stat above a 20.
- Finally we are going to ignore the Sun Blade because getting a hold of a specific magic item should not be a requirement for a build.
- This also assumes that your DM lets you roll your X number of attacks and decide to apply the sneak attack to the critical attack. The once per term requirement is very vague on this and should be clarified.
The Math
My first thought is that the thief build is going to be really top heavy; you are trying to get as many dice rolls as possible because you want that natural 20 critical to double the number of dice you are rolling for damage. I did a little look at monsters vs stats and I am trying to figure out a good threshold for when a die roll will hit and I feel like 13 on the die should hit based on average AC of monsters at that level. So 13 for die roll, 2 for weapon bonus, 6 for proficiency and 5 for stat. Now one could argue these numbers one way or another but I am going to be using them as the base because I need something to compare apples to apples.
So 13 + 2 + 6 + 5 = 26 for target AC to hit or 35% chance to hit and a 5% chance to crit. I used http://andrewgelman.com/2014/07/12/dnd-5e-advantage-disadvantage-probability/ as a reference for determining advantage so that translates to a 63.9% chance to hit and a 9.8% to critical. That makes it so 54.1% of the time you are going to do normal damage and 9.8% time you are going to do double damage. I basically am saying 2/3 of the time you are going to hit with your attack, really anything that gives you 2 attacks is going to let you get a sneak attack in during that round so long as you are within 5 feet of your target. This is also a pretty high number, some could argue that 10 or above would be a more realistic number then you are talking almost an 80% chance to hit with advantage.
Since you decided to dip into fighter instead of go 20 rogue you don't get Stroke of Luck but that would only be a factor depending on how much resting vs combat you would do. To ease math on calculating average damage I am assuming your weapon damage for rogue is a D6. If you are getting a D8 or better this just slightly makes your numbers better it just helps me to do my math faster.
Critical Hit - 18d6 + 2d6 + 5 + 2 = 77 Avg
Normal Hit - 9d6 + 1d6 + 5 + 2 = 42 Avg
GWF Critical Hit - 18d6 + 2d6 + 5 + 2 = 85 Avg
GWF Normal Hit - 9d6 + 1d6 + 5 + 2 = 46 Avg
The math was kind of surprising because of the limited reroll only on 1 or 2 and you could get a 1 after you rerolled a 2 but on average on 10d6 rolling a 1 or 2 and getting 4 extra damage on average.
Polearm Master
After looking at the polearm master the numbers are basically the same for attack and damage except that you get another attack that you will get your critical damage against. Even though the base dice is a d4 that extra attack is what gets you the key advantage — do you want that extra damage from the reroll or the chance to attack again and be able to sneak attack? Frankly I'd rather take the 63.9% to do my sneak attack dice again then the extra 4 damage on average.
Crossbow Expert
This basically follows the same rules as Polearm master: the feat is letting you get an extra attack with the a crossbow and I still think it is better then Polearm master because being able to attack at range is crucial; however, that depends on your flavor and what you like to do. However where this starts to break down is flanking and how your GM rules on flanking with a crossbow. If your GM rules you can't with a range weapon then you are stuck with polearm.
Bottom Line
Bottom line your GM house rule about flanking is getting you the most bang for your buck here because you want to maximize that rule. The winner between all 3 is really hard to decide, and also depends on how your GM house rules critical hits and determining which one was a sneak attack. If you get to pick the extra attack is going to be always worth it. If you can't pick which attack to apply sneak attack damage to then they are really almost a wash because your extra critical chance vs the on average higher damage from your rolling is going to end up being almost a wash in the long term at high level.
Prioritize number of attacks and Feat combinations
Ok, a quick addendum before we go any further. There is no such thing as one perfect build for every situation. The environment you'll be fighting in, the type and number of opponents, and even the nature of the story you're engaged in can all change which characters are "best" suited. For example, a character who hits once but hits extremely hard (like a rogue) may have higher DPR (damage per round) than another, but against a horde of weak enemies (e.g. Goblins) they may find themselves less useful than their DPR would suggest they would be, since a large amount of their damage each round is wasted hurting an already dead enemy.
All that being said, I've done a bit of research and found that at this particular level, there is a build that will work very well in a lot of scenarios, and meets the criteria you've set (survivability and DPR without any other players' help) in a measurable way. So enough hedging: let's look at the details.
The Build
Stout Halfling (counterintuitive, but hear me out), Eldritch Knight Fighter 13, Rogue (or Wizard) 2
Str: 8
Dex: 20
Con: 16
Int: 14
Wis: 12
Cha: 8
AC: 18, 20 with Haste, up to 25 with cover
Feats: Sharpshooter, Crossbow Expert
Favored weapon: Hand crossbow
Favored Spells (in order of importance): Haste, Mage Armor, Shield, Find Familiar (or another 1st level Wizard spell), 7 more evocation or abjuration wizard spells of your choice (you'll rarely be casting them).
Rationale
In descending order of importance, the three factors you need for maximum ranged weapon damage dealing are:
- Multiple attacks
- Accuracy & Damage Bonus (about equal: both come from Dex)
- Base Damage (weapon's dice)
Multiple attacks are almost always the most important feature. A typical enemy in DnD will have an AC which can be hit on a natural 8 or better. So usually, an increase an increase in accuracy (say, the 2 point increase from the fighter's "archery" style) will grant you about a 16.666% overall boost in expected damage (hitting on 14/20 attacks rather than 12/20), while a boost in number of attacks will grant you at least a 20% boost in damage (going from 5 attacks to 6, which usually can only happen at 20th level anyway). Although enemies with particularly high AC may alter this math, on average multiple attacks will be of more benefit. That being said, we're going to get both as high as possible.
With all that in mind, you're going to want the following build:
- 13 levels in Eldritch Knight: 11 for 3 standard attacks. At level 13, trade in the spell you gained at 8th level for "Haste", and get another single weapon attack (4 per round total so far).
- At level 4, take crossbow expert feat. Now, according to sage advice (http://dnd.wizards.com/articles/features/sageadvice_feats), you will be able to use your bonus action for another hand crossbow attack. Although the hand crossbow has the lowest damage dice of the martial ranged weapons, this feat makes it the most damaging in most circumstances. (5 attacks per round by level 15).
- At level 6, take sharpshooter. Now, you can shoot your hand crossbow just as well up to 120 feet (and since most combat in a dungeon crawl happens within 100 feet, you're golden). Also, as long as your target's AC is less than 22, you always want to take the -5 to roll for +10 to damage (the average damage per round will be higher).
Your remaining two attribute increases should got to getting a 20 dexterity. So far we're up to: 5 attacks per round, expending nothing other than a 3rd level spell slot (2 per day available) and ammunition. Each attack does 1d6+15 damage, or 18.5 average damage per successful attack. That's (averaging out the rolls) a whopping 92.5 damage per round, without even using action surge! Even more amazingly, you could still be dealing an average 37 damage on a turn in which you are DODGING (haste action + bonus action attacks)!
Even without haste, we still could be doing an average of 74 damage per round (assuming all attacks hit) with the hand crossbow, expending no resources other than bolts.
For the final two levels, there are a couple of options; but probably the best one is to take two levels of Rogue. You'll get an extra 1d6 per round from sneak attack, and cunning action (which, although it would lose one weapon attack, would allow you to disengage, dash, or hide as a bonus action: it'll give you considerable versatility on the battle field, and allow you to easily keep your distance). Also, you could get expertise in stealth and acrobatics, which will be a huge boon if you're hoping to scout or hide in combat, or avoid being grappled. Our damage total (without action surge) is now up to 96 damage per round. If you wanted to Haste more often rather than do a bit more damage (and losing some battlefield mobility), you could take 2 levels in Wizard instead, allowing you 3 castings of haste automatically, and an Arcane Tradition (War Magic could fit nicely here, or Bladesinger if your DM allows it for a non-elven character. Warning: a DM may consider an attack with a hand crossbow to be using "two hands to attack with a weapon", which ends the bladesong. Check with them before choosing a subclass).
The Halfling's bonus to dexterity is essential, but you could get this from other races. A real benefit is the +1 bonus to constitution. It may not look like much, but this build is very much about maintaining the Haste, and has no attribute boosts to spare. If you take this build, DC 10 concentration saves (which is what most attacks will incur if they hit you; only attacks dealing 22 or more damage will up this difficulty) will only fail on a natural 1: and because of Halfling's "Lucky" trait, this means the standard concentration save will only fail 1 in 400 times. Also, the Halfling ability to move through the space of medium hostile creatures makes this build insanely mobile. If you went with 2 levels of Rogue, even if your character was completely surrounded by (medium sized) guards, you could Disengage (cunning action), Dash 45 feet (Haste dash action, speed doubled, five feet of difficult terrain for moving through an enemy's space), make three attacks (action), then move up to 50 feet more, all without incurring any opportunity attacks.
For your non-abjuration/evocation first level spell gained at level 3, I'd suggest Find Familiar (an Owl using the Help action in combat can be very useful). You should pick up Mage Armor right away at level 3. With mage armor and Haste activated, you'll have an AC of 20 (13+5 from dex+2 from Haste), before you even take cover (which you should be doing as much as possible as a ranged character). This will make your standard AC between 22 and 25. If you pick up Shield at level 5, you can even bring this up to 30 for a round, in REACTION to being hit (which could cancel the hit in question) at the expense of a first level spell slot.
There are other options that make for powerful ranged damage dealers at this level (Level 10 bard with swift quiver and heavy crossbows will fire 4 times per round, and ranger5/rogue* beats out fighter at most levels). But this build has a slight (or major) numerical advantage over all of them I've been able to calculate at precisely level 15. One last consideration: if you went Fighter 14, Rogue 1, you'd get the same max damage, lose the cunning action, and get access to one 3rd, 2nd, or 1st level Wizard spell of your choice. Mirror image alone might be worth this: but it all depends on how much flexibility you want on your turn. Personally, I'd go Rogue 2 (cunning action is fun and useful).
Best Answer
So, I couldn't sleep and decided to work on that. Here's the best I got until the moment - using only PHB.
I have done the math for 3 builds so far, all using Variant Human and fighting style Archery when multiclassed:
Sneak Attack procs are assumed every round, as there are melee allies. I'm the first to say I was not very creative with the use of subclasses or magic items. As noted by András in the comments, Sneak Attack only procs once per turn, so the second Hand Crossbow attack does not deal the extra 2d6 damage, putting both builds roughly 2.5 average points below the Sharpshooter.
Assuming you you can hide to get unseen every turn
If Hide = Unseen = Attack with advantage is a thing (this depends on your stealth checks, but with expertise they should be very likely to work), the highest damaging build becomes Rogue 2/Fighter 1, Sharpshooter, Heavy Crossbow +1.
For the Rogue 3, Crossbow Expert build, assuming we can attack with the same hand crossbow twice, we have nine possible situations. Each one has a \$P_i\$ associated with it and an average damage \$ d_i \$. The average total damage is given by \$ \sum_{i=1}^{9} P_i \cdot d_i \$. Let \$ P = \{ 0.55, 0.5, 0.45 \} \$ be the probability of hitting an individual hit and \$ P_c = 0.05\$ the probability of landing a critical hit.
The result of the summation, if I did everything right, gives us an average damage of \$ \{16.92, 15.79, 14.62 \} \$.
Similarly, for Rogue 2/Fighter 1, removing the 1d6 from Sneak Attack, we get \$\mathbf{d} = \{12, 12, 19, 19, 24, 27.5, 31, 20.5\} \$, but increasing the Probabilities to \$ \{ 0.65, 0.6, 0.55\}\$, we get an average damage of \$ \{ 15.66, 14.70, 13.73 \} \$.