在 while 循环中使用 LESS_EQUAL 进行 CMake 比较不起作用

CMake comparision using LESS_EQUAL in while loop not working

我正在尝试在 CMake 中获取循环,以下是 Prime 示例无测试代码

set(i 2)
set(n 7)
MATH(EXPR cntr ${n}/2)

message(${i}, ${n}, ${cntr})

# When I use `LESS` instead of `LESS_EQUAL` the loop works fine
while(i LESS_EQUAL cntr)
        message("Checking ${i}")
        MATH(EXPR RESULT ${n}%${i})
        if(RESULT EQUAL 0)
                message("${n} is not Prime, as ${n}%${i} is 0")
                break()
        endif()
        MATH(EXPR i ${i}+1)
endwhile()

if(i EQUAL cntr)
        message("${n} is Prime")
endif()

上面带有 LESS_EQUAL 的代码由于某种原因无法正常工作。我认为有些事情真的很愚蠢,但尝试调试代码但我仍然​​没有得到它。

哦,我的错,

https://cmake.org/cmake/help/latest/command/if.html

我的 Cmake 版本不支持 LESS_EQUAL,因此必须将 LESS_EQUAL 转换为 i LESS cntr OR i EQUAL cntr