Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a verbose output for CMake?

Tags:

cmake

I would like to investigate why I have this error:

$ cmake ..
-- The C compiler identification is unknown
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /cygdrive/c/Users/Ycr/Home/bin/arm-none-eabi-gcc
-- Check for working C compiler: /cygdrive/c/Users/Ycr/Home/bin/arm-none-eabi-gcc -- broken
CMake Error at /usr/share/cmake-3.6.2/Modules/CMakeTestCCompiler.cmake:61 (message):
  The C compiler "/cygdrive/c/Users/Ycr/Home/bin/arm-none-eabi-gcc" is not
  able to compile a simple test program.

Unfortunately after the error:

  • I have no idea of what CMake did. I don't have a verbose log of the command it executed.
  • The CMakeFiles/cmTC_e4aa4.dir was cleaned after the error, so I have no possibility to explore the issue myself.

How should I investigate such an error?

I tried to use the --debug-trycompile option. This time CMake creates a CMakeTmp folder which makes perfectly without errors. However, I still have this CMakeFiles/cmTC_e4aa4.dir that generates errors and even with the option CMake unlinks the folder.

like image 207
nowox Avatar asked Oct 17 '22 07:10

nowox


1 Answers

Getting a Verbose Log

The try_compile() calls that CMake does in the beginning to test the compiler, gives a detailed error output on the console and writes it to

[your binary output directory]/CMakeFiles/CMakeError.log

I've checked the source code again and there is no CMake option that would give more a more detailed output for CMake's internal try_compile() calls.

You could just force the output to standard output by adding some variable_watch() calls to your main CMakeLists.txt before your project() call like:

variable_watch(__CMAKE_C_COMPILER_OUTPUT)
variable_watch(__CMAKE_CXX_COMPILER_OUTPUT)

Keeping the Temporary Files

To keep the temporary file of try_compile, add --debug-trycompile to the cmake command line.

But be aware that the multiple compiler tests at the beginning overwrite the artifacts of previous ones:

It may however change the results of the try-compiles as old junk from a previous try-compile may cause a different test to either pass or fail incorrectly. This option is best used for one try-compile at a time, and only when debugging.

References

  • How to keep generated temporary files?
  • CMake error at CMakeLists.txt:30 (project): No CMAKE_C_COMPILER could be found
like image 58
Florian Avatar answered Oct 21 '22 07:10

Florian