I did not get the downloaded 4.8.0 opencv to work, but I did not try very hard.
Forgot to mention that this was not gcc version 13 but a much earlier version so cmake was not the problem.
if it failed for openexr stuff during standalone build may be add -DWITH_OPENEXR=OFF ? and/or apply said limiting list of modules too as cmake argument.
Do not forgot to remove CmakeCache file in your build directory, too.
I was going with 'minimal mod of that work' instead of full upgrade partially because even normal build was not working for me on specific Slackware snapshot ... but may be I just lacked patience to try all possible stuff.