Correct setup for building a compiler then its stdlib

I need to build a Fortran compiler written in C++ then its libraries written in Fortran. I would like said libraries to be compiled with my just built compiler. The problem is that the compiler binary doesn’t exist while CMake is configuring the project and thus I get an error. I’ve tried:

  set(CMAKE_Fortran_COMPILER "path/to/non/exiting/compiler")

Is there anyway I can tell CMake to not test the compiler path and just trust me it’s there? Is the correct way to make a two stages build?

I tried to look at the clang code and they seem to do a two stages build where CMake invokes itself again to build the libraries (runtimes in clang speak). If this is the “correct” way, is there documentation on it?

You could try a toolchain file, but CMake isn’t really set up to support this. Too much wants to be able to inspect the compiler in general.

It’s probably the most reliable. Seeing as there is one compiler that self-hosts with CMake, there’s not much prior art here in the first place.

Thanks! I will try a two stages build.