Misleading "See also CMakeError.log" messages
Given the following CMake script:
cmake_minimum_required(VERSION 3.15)
project(error)
message(SEND_ERROR "this was the error")
include(CheckIncludeFile)
check_include_file(unitstd.h HAVE_UNISTD_H)
foreach(i RANGE 1 20)
message(STATUS ${i})
endforeach()
The output on my Windows machine whilst configuring MSVC was:
$ cmake -GNinja -S . -B build
-- The C compiler identification is MSVC 19.28.29914.0
-- The CXX compiler identification is MSVC 19.28.29914.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/BuildTools/VC/Tools/MSVC/14.28.29910/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
CMake Error at CMakeLists.txt:5 (message):
this was the error
-- Looking for unitstd.h
-- Looking for unitstd.h - not found
-- 1
-- 2
-- 3
-- 4
-- 5
-- 6
-- 7
-- 8
-- 9
-- 10
-- 11
-- 12
-- 13
-- 14
-- 15
-- 16
-- 17
-- 18
-- 19
-- 20
-- Configuring incomplete, errors occurred!
See also "C:/Temp/test/build/CMakeFiles/CMakeOutput.log".
See also "C:/Temp/test/build/CMakeFiles/CMakeError.log".
I know that the real error is somewhere above, but users new to CMake go looking into "C:/Temp/test/build/CMakeFiles/CMakeError.log" and see things like:
Determining if the include file unitstd.h exists failed with the following output:
Change Dir: C:/Temp/test/build/CMakeFiles/CMakeTmp
Run Build Command(s):C:/ProgramData/chocolatey/bin/ninja.exe cmTC_e220d && [1/2] Building C object CMakeFiles\cmTC_e220d.dir\CheckIncludeFile.c.obj
FAILED: CMakeFiles/cmTC_e220d.dir/CheckIncludeFile.c.obj
C:\PROGRA~2\MICROS~2\2019\BUILDT~1\VC\Tools\MSVC\1428~1.299\bin\Hostx64\x64\cl.exe /nologo /DWIN32 /D_WINDOWS /Zi /Ob0 /Od /RTC1 -MDd /showIncludes /FoCMakeFiles\cmTC_e220d.dir\CheckIncludeFile.c.obj /FdCMakeFiles\cmTC_e220d.dir\ /FS -c CheckIncludeFile.c
CheckIncludeFile.c(1): fatal error C1083: Cannot open include file: 'unitstd.h': No such file or directory
ninja: build stopped: subcommand failed.
And panic about failing to have unitstd.h
or something similar.
Can we do something to help the users spot the error messages?
- Repeat the
SEND_ERROR
messages at the end of the CMake configuration? - Add the
SEND_ERROR
to theCMakeFiles/CMakeError.log
?
A similar thing happens on CI when CMake fails to configure, usually the CI scrips get the (compilation) error which is reported at the end and forward it into the email message.