This turned out to be my own fault, in the CMakeLists.txt when building subdirectories, it was accidentally repeatedly compounding the env var for include directories until it was a monsterous jumble (a semicolon-separated list of 18K members being copied around).
After it was fixed in lws, peak memory reduced to ~93MB from>2GiB or double that if the cwd was long. Since it was not “wrong”, just containing the same paths over and over it did not otherwise create any symptom except the memory usage and time eaten for nothing.