Hey Torsten, Am 21.11.18 um 13:15 schrieb Torsten Robitzki:
Hi, I’ve stumbled over following behavior and now I’m searching for the rules, that explains that behavior:test.cmake: macro(check_argn) message("in macro check_argn ARGN: ${ARGN}") if(ARGN) foreach(item IN LISTS ARGN) message("ARG: ${item}") endforeach(item) message("ARGN: ${ARGN}") endif() endmacro() function(f1 a) message("in function ARGN: ${ARGN}") check_argn() endfunction() f1(1) f1(1 2) This will yield the following output: $ cmake -P ./test.cmake in function ARGN: in macro check_argn ARGN: in function ARGN: 2 in macro check_argn ARGN: ARG: 2 ARGN: I would expect ARGN to behave exactly the same in the macro, as in the function, but apparently there is a difference. Can someone of you explain that to me?
I think the behavior is explained in [1] and [2]. In particular the second section of [2] states that the parameter " [...] such as ARGN are not variables in the usual CMake sense. They are string replacements [...]". And the example at the end of [2] seems to match your test perfectly.
Hope that helps a bit, Andreas [1] https://cmake.org/cmake/help/latest/command/function.html [2] https://cmake.org/cmake/help/latest/command/macro.html
TIA and kind regards, Torsten
-- Powered by www.kitware.com Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ Kitware offers various services to support the CMake community. For more information on each offering, please visit: CMake Support: http://cmake.org/cmake/help/support.html CMake Consulting: http://cmake.org/cmake/help/consulting.html CMake Training Courses: http://cmake.org/cmake/help/training.html Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html Follow this link to subscribe/unsubscribe: https://cmake.org/mailman/listinfo/cmake
