[CMake] Weird STREQUAL behaviour
Marcel Loose
loose at astron.nl
Tue Mar 31 05:40:21 EDT 2009
Hi all,
Could anyone shed a light on the following. IMHO it's a bug.
I'm running cmake version 2.6-patch 2.
Here's my initial CMakeLists.txt file:
cmake_minimum_required(VERSION 2.6)
set(options fine good bad)
option(fine "Fine" OFF)
option(good "Good" OFF)
option(bad "Bad" OFF)
foreach(opt ${options})
message(STATUS "opt = ${opt}")
if(opt STREQUAL "fine")
message(STATUS "This is fine")
elseif(opt STREQUAL "good")
message(STATUS "This is good")
else(opt STREQUAL "fine")
message(FATAL_ERROR "This is bad!")
endif(opt STREQUAL "fine")
endforeach(opt ${options})
Running cmake produces the following output:
...
-- opt = fine
CMake Error at CMakeLists.txt:13 (message):
This is bad!
...
which is not what I expected.
Quoting the variable opt in CMakeLists.txt yields:
cmake_minimum_required(VERSION 2.6)
set(options fine good bad)
option(fine "Fine" OFF)
option(good "Good" OFF)
option(bad "Bad" OFF)
foreach(opt ${options})
message(STATUS "opt = ${opt}")
if("${opt}" STREQUAL "fine")
message(STATUS "This is fine")
elseif("${opt}" STREQUAL "good")
message(STATUS "This is good")
else("${opt}" STREQUAL "fine")
message(FATAL_ERROR "This is bad!")
endif("${opt}" STREQUAL "fine")
endforeach(opt ${options})
Running cmake produces the following output:
...
-- opt = fine
-- This is fine
-- opt = good
-- This is fine
-- opt = bad
-- This is fine
...
which, again, is not what I expected.
Replacing STREQUAL with MATCHES in the initial CMakeLists.txt file
yields:
cmake_minimum_required(VERSION 2.6)
set(options fine good bad)
option(fine "Fine" OFF)
option(good "Good" OFF)
option(bad "Bad" OFF)
foreach(opt ${options})
message(STATUS "opt = ${opt}")
if(opt MATCHES "^fine$")
message(STATUS "This is fine")
elseif(opt MATCHES "^good$")
message(STATUS "This is good")
else(opt MATCHES "^fine$")
message(FATAL_ERROR "This is bad!")
endif(opt MATCHES "^fine$")
endforeach(opt ${options})
Running cmake produces the following output:
...
-- opt = fine
-- This is fine
-- opt = good
-- This is good
-- opt = bad
CMake Error at CMakeLists.txt:13 (message):
This is bad!
...
which is, finally, what I expected!
Is there something wrong with STREQUAL or do I simply fail to understand
how STREQUAL is supposed to work?
Best regards,
Marcel Loose.
More information about the CMake
mailing list