# Correct setup for building a compiler then its stdlib

**URL:** https://discourse.cmake.org/t/correct-setup-for-building-a-compiler-then-its-stdlib/6363
**Category:** Code
**Created:** [August 27, 2022, 6:51pm UTC](https://discourse.cmake.org/t/correct-setup-for-building-a-compiler-then-its-stdlib/6363 "2022-08-27T18:51:55Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![asdf2](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/7ab992/32.png) [@asdf2](https://discourse.cmake.org/u/asdf2)
#### Post date: [August 27, 2022, 6:51pm UTC](https://discourse.cmake.org/t/correct-setup-for-building-a-compiler-then-its-stdlib/6363/1 "2022-08-27T18:51:55Z")

</div>

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:

```auto
  set(CMAKE_Fortran_COMPILER_WORKS TRUE)
  set(CMAKE_Fortran_COMPILER_ID_RUN TRUE)
  set(CMAKE_Fortran_COMPILER_FORCED TRUE)
  set(CMAKE_Fortran_COMPILER_WORKS TRUE)
  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?

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)
#### Post date: [August 27, 2022, 6:56pm UTC](https://discourse.cmake.org/t/correct-setup-for-building-a-compiler-then-its-stdlib/6363/2 "2022-08-27T18:56:13Z")

</div>

> [@asdf2](#):
>
> ```auto
> 
> ```
> 
> Is there anyway I can tell CMake to not test the compiler path and just trust me it’s there?

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.

> [@asdf2](#):
>
> 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?

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.

---

<div class="post-metadata">

### Author: ![asdf2](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/a/7ab992/32.png) [@asdf2](https://discourse.cmake.org/u/asdf2)
#### Post date: [August 27, 2022, 11:44pm UTC](https://discourse.cmake.org/t/correct-setup-for-building-a-compiler-then-its-stdlib/6363/4 "2022-08-27T23:44:48Z")

</div>

Thanks! I will try a two stages build.
