# use compilers set by CMAKE\_\*\_COMPILER in ctest

**URL:** https://discourse.cmake.org/t/use-compilers-set-by-cmake-compiler-in-ctest/15652
**Category:** Development
**Tags:** os:linux
**Created:** [May 13, 2026, 11:00am UTC](https://discourse.cmake.org/t/use-compilers-set-by-cmake-compiler-in-ctest/15652 "2026-05-13T11:00:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![kkwli](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kkwli/32/6130_2.png) [@kkwli](https://discourse.cmake.org/u/kkwli)
#### Post date: [May 13, 2026, 11:00am UTC](https://discourse.cmake.org/t/use-compilers-set-by-cmake-compiler-in-ctest/15652/1 "2026-05-13T11:00:33Z")

</div>

I set the `CMAKE_*_COMPILER` when building cmake from scratch. When I run `ctest`, it seems that it always uses the one on the system. If I set `CXX` in running `ctest`, it will pick up the one set by `CXX`. Is it the expected behavior? Why is not the one from `CMAKE_*_COMPILER`being used?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [May 13, 2026, 1:31pm UTC](https://discourse.cmake.org/t/use-compilers-set-by-cmake-compiler-in-ctest/15652/2 "2026-05-13T13:31:59Z")

</div>

Yes, this is expected. CMake test suite creates a new build tree from scratch for each test case, configured in the ambient environment. Typically we use `CC=` and `CXX=` in the environment where I create a given build tree for CMake itself and run the tests in the same environment.

---

<div class="post-metadata">

### Author: ![kkwli](https://discourse.cmake.org/user_avatar/discourse.cmake.org/kkwli/32/6130_2.png) [@kkwli](https://discourse.cmake.org/u/kkwli)
#### Post date: [May 13, 2026, 3:50pm UTC](https://discourse.cmake.org/t/use-compilers-set-by-cmake-compiler-in-ctest/15652/3 "2026-05-13T15:50:05Z")

</div>

Thanks for the quick reply. I notice, in `Tests/FortranC/Flags`, the compiler in `cc.sh` and `fc.sh` always points to the one set by `CMAKE_C_COMPILER` and `CMAKE_Fortran_COMPILER` respectively. Should this compiler also be the one in `CC` and `FC`?

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [May 13, 2026, 3:54pm UTC](https://discourse.cmake.org/t/use-compilers-set-by-cmake-compiler-in-ctest/15652/4 "2026-05-13T15:54:50Z")

</div>

Thanks for pointing that out. `Tests/FortranC/Flags.cmake.in` is configured into the test case at configure time, and so uses configure-time information. It predated the RunCMake infrastructure documented by `Tests/RunCMake/README.rst`. The test could probably be converted to the latter in order to have test-time compiler selection.

It hasn’t been a problem in our CI or nightly testing though because the test suite is configured in a consistent environment.
