I am trying to get hold of loops in CMake and the following is a sample Prime no test code
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()
The above code with LESS_EQUAL
is not working for some reason. I think something really silly but tried to debug the code and I am still not getting it.
Ohh My bad,
https://cmake.org/cmake/help/latest/command/if.html
My Cmake version doesn't support the LESS_EQUAL yet so had to convert LESS_EQUAL
to i LESS cntr OR i EQUAL cntr