I find this to be the easiest way to try out new GCC versions and I actually use it exclusively for building testing my GCC 9 projects. With just a small wrapper Dockerfile, you can easy accommodate CMake or any other build dependencies.
For example, I have one I use for building CMake projects[2] (see README of same project for example of how to use said docker image).
GCC 9 is great, by the way. One of the best improvements, IMO is that gcov can now print coverage reports to stdout in JSON format which means you can take advantage of parallel computing to generate coverage reports fast. The Dockerfile I linked to in [2] above is a part of a utility I made as a drop-in replacement for lcov and can generate lcov reports at times up to 100x faster thanks to GCC 9 improvements.
[1] https://github.com/zbeekman/nightly-gcc-trunk-docker-image
[2] https://github.com/RPGillespie6/fastcov/blob/master/Dockerfi...