Search code examples
cmake

Compare a cmake list entry to an expected value


I want to compare the first element in a list and check it is equal to 1

Here is what I have tried

# Get python installation details
find_package(Python3 REQUIRED COMPONENTS Interpreter Development NumPy) 
# Create a list from the numpy version
string(REPLACE "." ";" VERSION_LIST ${Python3_NumPy_VERSION})
# Get the first element
list(GET VERSION_LIST 0 MAJOR)
# Create variable
set(MY_VARIABLE "1")
# now do comparison
if (Major STREQUAL MY_VARIABLE)
    Message("Numpy OK")
else()
    Message(FATAL_ERROR "Wrong version of numpy found, please install version 1.26 upwards")
endif()

But my comparison is always failing When output the Major variable is is 1 so I don't understand why it is failing


Solution

  • It was a misunderstanding of CMake variables I had used Major instead of MAJOR