cppcheck: fix --with-gui option not finding cfg

Closes #27756.
Closes #27852.