Both: The capability of the Saturn V set the maximum weight of the Apollo spacecraft, and the development of Apollo forced some changes to the Saturn.
Originally, the plan was to develop a large semi-modular family of rockets under the Saturn moniker, at one point ranging from the C-1 for LEO medium-lift (which evolved into the Saturn I) to the 4800-ton C-8 for lunar direct ascent. At the same time, the Apollo program was conceived as a general purpose LEO and lunar spacecraft, with the Apollo CSM being the final lunar-ascent-and-earth-return stage in a direct ascent mission mode.
When Kennedy set the end-of-decade goal for lunar landing in his May 1961 address to Congress, waiting for the massive C-8 became unacceptable, so the choice of mission mode came down to the Earth orbit rendezvous (EOR), with two C-4 launches to either assemble or fuel the complete lunar spacecraft, or lunar orbit rendezvous (LOR), using a single C-4 launch with a small lunar lander. In the end, LOR was selected as the fastest and cheapest plan. The C-4 design used 4 F-1 engines on the first stage, 4 J-2 on the second stage, and the single J-2, S-IVB as the third stage.
Before LOR was chosen, the Apollo CSM design had already stabilized to some extent, which is why the engine on the service module is so large: it was intended for lift-off from the moon.
By the end of 1961, it appeared the C-4 would not be big enough for the single-launch LOR mission, so the C-5 was developed. This configuration originally had only 4 engines on the first stage, but NASA's Director of Launch Vehicles, Milton Rosen, pushed for the fifth engine. According to Stages To Saturn:
Adding the extra power plant really did not call for extensive design changes; this was Rosen's most convincing argument. Marshall [Space Flight Center] engineers had drawn up the first stage to mount the original four engines at the ends of two heavy crossbeams at the base of the rocket. The innate conservatism of the von Braun design team was fortunate here, because the crossbeams were much heavier than required. Their inherent strength meant no real problems in mounting the fifth powerplant at the junction of the crossbeams, and the Saturn thus gained the added thrust to handle the increasingly heavy payloads of the later Apollo missions. "Conservative design," Rosen declared, "saved Apollo."
At second glance, MSFC people themselves found no good reason not to add the extra engine, especially with the payload creeping upward all the time. "I had an awfully uneasy feeling, you know," von Braun remembered; "every time we talked to the Houston people, the damn LEM had gotten heavier again."
NASA announced plans to build the C-5 at the beginning of 1962, and by early 1963 it was confirmed as the launcher choice for Apollo and renamed Saturn V.
Late in the project, Grumman had real trouble with weight overruns on the lunar module. With the somewhat over-built CSM, the total weight of the spacecraft ran up against the payload limits of the Saturn V, and multiple "campaigns" of weight-stripping engineering effort had to be made to reach the final landing weight goals. As late as Apollo 10, the LM was still a couple hundred pounds overweight, in fact.
So early on, the spacecraft drove the launcher payload capability, forcing the 5th engine to be added, and late in the program, the launcher payload limits drove the spacecraft design.