Marcel Loose wrote:
I have a problem with a self-written CMake macro, but I don't know
exactly what the problem is.

I have defined macro(SetIfElse var val def), which is supposed to assign
the contents of val to var, when val is defined; otherwise it should
assign the contents of def to var. This macro was inspired by the
macro(SET_IF_NOT_SET var val) from the CMake module CTest.cmake

When I feed the CMakeLists.txt file below to cmake, I would expect as
output: 'text=Hello World', but instead I get 'text=Sorry mate!'
Could you please explain what I'm doing wrong?

project(hallo)
cmake_minimum_required(VERSION 2.6)

# Set variable ${var} equal to ${val} if ${val} is defined; else to
${def}.
macro(SetIfElse var val def)
  if(DEFINED "${val}")
    set("${var}" "${val}")
  else(DEFINED "${val}")
    set("${var}" "${def}")
  endif(DEFINED "${val}")
endmacro(SetIfElse)

set(hello "Hello World")
set(mate  "Sorry mate!")

SetIfElse(text "${hello}" "${mate}")
message(STATUS "text=${text}")

Isn't this asking if the variable "Hello World" (which, btw, I believe is not a valid variable name due to the space, although cmake is a touch inconsistent in handling such) is defined?

I think what you want is:
SetIfElse(text hello "${mate}")

--
Matthew
Please do not quote my e-mail address unobfuscated in message bodies.
--
You are in a dark room. The only exit is a door to the east.
> OPEN DOOR
I don't know which door you mean.
> OPEN EAST DOOR
It's locked.

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to