CMake and the IF-ELSE issue

Today I fought a little war with CMake. I wanted to check whether the version of a package is valid, using the VERSION_LESS comparison in the CMAKE IF-command.

if(Foo_FIND_VERSION_EXACT AND (NOT Foo_VERSION VERSION_EQUAL Foo_FIND_VERSION))
  message(FATAL_ERROR "Need exact version..")
else(Foo_VERSION VERSION_LESS Foo_FIND_VERSION)
  message(FATAL_ERROR "Need at least version..")
endif()

Note the problem? It took me half an hour and lots of cursing..

The above is accepted by CMake, but if fails with a FATAL_ERROR with message ‘Need at least version..’.

The issue? It should be ELSEIF and not ELSE.

if(Foo_FIND_VERSION_EXACT AND (NOT Foo_VERSION VERSION_EQUAL Foo_FIND_VERSION))
  message(FATAL_ERROR "Need exact version..")
elseif(Foo_VERSION VERSION_LESS Foo_FIND_VERSION)
  message(FATAL_ERROR "Need at least version..")
endif()

Loving CMake, but that was …