Hello,

Has anyone thought about the possibility of adding return values from CMake 
functions?  This would be a very useful language feature that the Trilinos 
CMake files would use everywhere.

Here is an example use case.  One problem with CMake is that it has very loose 
checking.  For example, if I write:

   IF (MYVARABLE)
     ...
   ENDIF()

Instead of what I meant:

   IF (MYVARIABLE)
     ...
   ENDIF()

then my CMakeLists.txt file will not work correctly.  What I have been doing is 
to instead write an ASSERT_DEFINED(...) macro and then use it as:

   ASSERT_DEFINED(MYVARIABLE)
   IF (MYVARIABLE)
     ...
   ENDIF()

Of course the problem with this is that I could misspell one of the uses as:

   ASSERT_DEFINED(MYVARIABLE)
   IF (MYVARABLE)
     ...
   ENDIF()

and I am back in the same situation.  The problem is that I am duplicating the 
variable name.  This is a fundamental software engineering issue that needs to 
be addressed in some way.

What I would like to be able to write is a function like:

  FUNCTION(ASSERTDEF VARNAME)
    IF(NOT DEFINED ${VARNAME})
      MESSAGE(SEND_ERROR "Error, the variable ${VARNAME} is not defined!")
    ENDIF()
    RETURN(${VARNAME})
  ENDFUNCTION()

You could then use this function like:

   IF (${ASSERTDEF(MYVARIABLE)$)
     ...
   ENDIF()

Then, if I misspelled the variable name as:

   IF (${ASSERTDEF(MYVARABLE)}$)
     ...
   ENDIF()

I would get an error message and processing would stop immediately.

Above, I assume that the syntax:

   ${SOMEFUNCTION(ARGS)}

Is needed to get CMake to expect a return value from the function and then 
return it, just like it would return a variables value.

How hard would it be to all return values from CMake functions in this way?

Thanks,

- Ross


_______________________________________________
CMake mailing list
CMake@cmake.org
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to