Cannot compile CMake from source: Fortran compiler not found

Hello, I’m trying to compile CMake from source but I’m running into issues.
The first command I run is:

./bootstrap CC=cc CXX=c++ --generator="Unix Makefiles" --no-debugger CFLAGS="-fno-sanitize=undefined -fno-sanitize-trap=undefined" CXXFLAGS="-fno-sanitize=undefined -fno-sanitize-trap=undefined" LDFLAGS="-s"

This successfully builds the “initial CMake” which is then automatically run. Somewhere along the build I get this error about missing OpenSSL:

-- Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR (missing: OPENSSL_CRYPTO_LIBRARY OPENSSL_INCLUDE_DIR) 
CMake Error at Utilities/cmcurl/CMakeLists.txt:587 (message):
  Could not find OpenSSL.  Install an OpenSSL development package or
  configure CMake with -DCMAKE_USE_OPENSSL=OFF to build without OpenSSL.

There’s no way to pass -DCMAKE_USE_OPENSSL=OFF to the bootstrap script, so I manually invoke the “initial CMake” with the aforementioned flag:

./Bootstrap.cmk/cmake -DCMAKE_USE_OPENSSL=OFF .

The build continues then I get another error:

-- Looking for a Fortran compiler - NOTFOUND

That’s strange. I review the readme but there’s no mention of a Fortran compiler, only a C++ one… Is that an error in the documentation or did I do something wrong?

The check for a Fortran compiler is only for the test suite. Not finding it is not an error.

$ ./bootstrap ... -- -DCMAKE_USE_OPENSSL=OFF
1 Like

$ ./bootstrap ... -- -DCMAKE_USE_OPENSSL=OFF

Many thanks!

It completely stops the build process though:

-- Looking for a Fortran compiler - NOTFOUND
-- Configuring incomplete, errors occurred!
---------------------------------------------
Error when bootstrapping CMake:
Problem while running initial CMake
---------------------------------------------

Any way to bypass this?

The error could have been before that last line. Can you please provide the full log?

Sure thing.

The actual errors seem to be try_compile related:

-- Check size of sa_family_t
CMake Error at Modules/CheckTypeSize.cmake:146 (try_compile):
  Cannot copy output executable
 
    ''
 
  to destination specified by COPY_FILE:
 
    '/tmp/cmake-3.27.7/CMakeFiles/CheckTypeSize/SIZEOF_SA_FAMILY_T.bin'
 
  because:
 
    No such file or directory (input)
 
  Recorded try_compile output location doesn't exist:
 
    /tmp/cmake-3.27.7/CMakeFiles/CMakeScratch/TryCompile-BmCOMg/cmTC_b7220
 
Call Stack (most recent call first):
  Modules/CheckTypeSize.cmake:271 (__check_type_size_impl)
  Utilities/cmcurl/CMakeLists.txt:1289 (check_type_size)

I see some sanitizer flags in the bootstrap output; does it work if you don’t use a sanitizer?

Do you mean -fno-sanitize=undefined -fno-sanitize-trap=undefined ? These flags do turn off UBsan, which is on by default and prevents even the initial CMake from being built… I only added them to the bootstrap command though, maybe they’re not getting passed to the initial CMake?

Is it possible to see the full compiler error message that occurs during try_compile?

CMakeFiles/*.yaml has info (I can’t remember the name…CMakeConfigure.yaml?), but --debug-trycompile passed to the configure will leave the try_compile trees around for investigation.

1 Like

I couldn’t find any .yaml files in the source tree at all, but I did find 3 log files containing errors…

(I can only post 2 links per comment)

./bootstrap … -- --debug-trycompile may have more information stick around.

./bootstrap … -- --debug-trycompile

That’s what I did… I tried again now, same thing, no yaml files.

Hrm. Well, the paths in the error messages should be around at least. Can you go in those, try and build them and see what might be wrong there?

It turned out to be a linker issue; cc was symlinked to ld so it wasn’t working properly. Once that was fixed CMake built without issues (at least I hope so!)

Thank you so much Ben and Brad for the help :smile: