Skip to content

cmake llvm detection doesn't report errors properly #14136

@michaelforney

Description

@michaelforney

Zig Version

0.11.0-dev.1014+c679fdee7

Steps to Reproduce and Observed Behavior

My LLVM install didn't have all the architectures that zig required, but it seems that there are some bugs in Findllvm.cmake that prevent the error from getting reported properly.

$ cmake ..
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /bin/cc - 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: /bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring zig version 0.11.0-dev.1014+c679fdee7
CMake Error at cmake/Findllvm.cmake:90 (continue):
  A CONTINUE command was found outside of a proper FOREACH or WHILE loop
  scope.
Call Stack (most recent call first):
  cmake/Findllvm.cmake:93 (NEED_TARGET)
  CMakeLists.txt:136 (find_package)


-- Configuring incomplete, errors occurred!
See also "/tmp/zig/build/CMakeFiles/CMakeOutput.log".

Expected Behavior

Findllvm.cmake should report the error rather than give a cmake syntax error.

The cmake documentation for macros (https://cmake.org/cmake/help/latest/command/macro.html#macro-vs-function) says

Another difference between macros and functions is the control flow. A function is executed by transferring control from the calling statement to the function body. A macro is executed as if the macro body were pasted in place of the calling statement.

So I don't think the continue() in the function body makes any sense. I tried switching NEED_TARGET to a macro instead, but this doesn't seem to work either. With some added debug messages, it seems that the continue() on line 90 is being reached, and the line after it is not being reached, so it does seem like continue is jumping control flow somewhere else. However the line at the beginning of the while(1) loop is only reached once. The line immediately before the endmacro(NEED_TARGET) is reached every time, even when it tries to continue in the outer loop. This causes the detection to incorrectly succeed.

Perhaps someone more familiar with the cmake language knows what's going on and how to fix it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions