From 5f4686920d3615187c53f3064eb7f1345b2203b2 Mon Sep 17 00:00:00 2001 From: Brad King Date: Wed, 25 Mar 2009 10:37:04 -0400 Subject: 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. --- Source/cmCommandArgumentParserHelper.cxx | 6 +----- Tests/MacroTest/CMakeLists.txt | 5 +++++ Tests/MacroTest/context.cmake | 10 ++++++++++ 3 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 Tests/MacroTest/context.cmake diff --git a/Source/cmCommandArgumentParserHelper.cxx b/Source/cmCommandArgumentParserHelper.cxx index c67f884..4eec953 100644 --- a/Source/cmCommandArgumentParserHelper.cxx +++ b/Source/cmCommandArgumentParserHelper.cxx @@ -115,11 +115,7 @@ char* cmCommandArgumentParserHelper::ExpandVariable(const char* var) { return 0; } - if(this->FileName && strcmp(var, "CMAKE_CURRENT_LIST_FILE") == 0) - { - return this->AddString(this->FileName); - } - else if(this->FileLine >= 0 && strcmp(var, "CMAKE_CURRENT_LIST_LINE") == 0) + if(this->FileLine >= 0 && strcmp(var, "CMAKE_CURRENT_LIST_LINE") == 0) { cmOStringStream ostr; ostr << this->FileLine; diff --git a/Tests/MacroTest/CMakeLists.txt b/Tests/MacroTest/CMakeLists.txt index d0220ff..7ec50c7 100644 --- a/Tests/MacroTest/CMakeLists.txt +++ b/Tests/MacroTest/CMakeLists.txt @@ -86,3 +86,8 @@ ELSE(SOME_CHECK) ENDIF(SOME_CHECK) ADD_EXECUTABLE(MacroTest macroTest.c) + +MACRO(GET_CURRENT_FILE var) + SET(${var} ${CMAKE_CURRENT_LIST_FILE}) +ENDMACRO(GET_CURRENT_FILE) +INCLUDE(context.cmake) diff --git a/Tests/MacroTest/context.cmake b/Tests/MacroTest/context.cmake new file mode 100644 index 0000000..f4d7035 --- /dev/null +++ b/Tests/MacroTest/context.cmake @@ -0,0 +1,10 @@ +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}") -- cgit v0.12