The failure would happen when the main project was configured with a compiler which is not the system default. The new configuration was not forwarded to "ctest --build-and-test". This fixes it.