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_*_COMPILERbeing used?
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.
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?
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.