[Cmake-commits] [cmake-commits] king committed CMakeLists.txt 1.7 1.8 context.cmake NONE 1.1

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Mar 25 10:37:07 EDT 2009


Update of /cvsroot/CMake/CMake/Tests/MacroTest
In directory public:/mounts/ram/cvs-serv16835/Tests/MacroTest

Modified Files:
	CMakeLists.txt 
Added Files:
	context.cmake 
Log Message:
BUG: Fix CMAKE_CURRENT_LIST_FILE in macros

The value of CMAKE_CURRENT_LIST_FILE is supposed to be the list file
currently being executed.  Before macros were introduced this was always
the context of the argument referencing the variable.

Our original implementation of macros replaced the context of command
arguments inside the macro with that of the arguments of the calling
context.  This worked recursively, but only worked when macros had at
least one argument.  Furthermore, it caused parsing errors of the
arguments to report the wrong location (calling context instead of line
with error).

The commit "Improve context for errors in macros" fixed the latter bug
by keeping the lexical context of command arguments in macros.  It broke
evaluation of CMAKE_CURRENT_LIST_FILE because the calling context was no
longer preserved in the argument referencing the variable.  However,
since our list file processing now maintains the proper value of
CMAKE_CURRENT_LIST_FILE with dynamic scope we no longer need the context
of the argument and can just evaluate the variable normally.


Index: CMakeLists.txt
===================================================================
RCS file: /cvsroot/CMake/CMake/Tests/MacroTest/CMakeLists.txt,v
retrieving revision 1.7
retrieving revision 1.8
diff -C 2 -d -r1.7 -r1.8
*** CMakeLists.txt	25 Mar 2008 15:26:58 -0000	1.7
--- CMakeLists.txt	25 Mar 2009 14:36:59 -0000	1.8
***************
*** 87,88 ****
--- 87,93 ----
  
  ADD_EXECUTABLE(MacroTest macroTest.c)
+ 
+ MACRO(GET_CURRENT_FILE var)
+   SET(${var} ${CMAKE_CURRENT_LIST_FILE})
+ ENDMACRO(GET_CURRENT_FILE)
+ INCLUDE(context.cmake)

--- NEW FILE: context.cmake ---
GET_CURRENT_FILE(current_file)
IF(NOT "${current_file}" STREQUAL "${CMAKE_CURRENT_LIST_FILE}")
  MESSAGE(FATAL_ERROR
    "Macro file context is broken.  Expected:\n"
    "  ${CMAKE_CURRENT_LIST_FILE}\n"
    "but got:\n"
    "  ${current_file}\n"
    "from the macro."
    )
ENDIF(NOT "${current_file}" STREQUAL "${CMAKE_CURRENT_LIST_FILE}")



More information about the Cmake-commits mailing list