Re: [CMake] foreach() bug?
alexandre.feb...@thomsonreuters.com wrote: Ok, thanks for the info. Can I expect this "IN" mode to be delivered in 2.6.5? Probably not. It's currently experimental, and we might still change how it works. -Brad ___ 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
Re: [CMake] foreach() bug?
Ok, thanks for the info. Can I expect this "IN" mode to be delivered in 2.6.5? Alexandre -Original Message- From: Brad King [mailto:brad.k...@kitware.com] alexandre.feb...@thomsonreuters.com wrote: > foreach(arg ${list}) [snip] > The empty element has been discarded by foreach(). Is this the wanted > behaviour? If it is, how can I manage empty elements when I need them? The foreach command never even sees the empty arguments. By the time ${list} is evaluated the empty elements are gone. This is for language consistency. No one would want add_executable(myexe ${srcs}) to try to add "" as a source file if srcs has an empty element. In CMake HEAD from CVS there is an "IN" mode for foreach that supports explicitly named lists: set(my_list "a;b;;c;d") foreach(arg IN LISTS my_list) ... endforeach() For now you need to use the list() command. You can iterate over a range of the list size with foreach(arg RANGE ...). -Brad This email was sent to you by Thomson Reuters, the global news and information company. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters. ___ 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
Re: [CMake] foreach() bug?
alexandre.feb...@thomsonreuters.com wrote: foreach(arg ${list}) [snip] The empty element has been discarded by foreach(). Is this the wanted behaviour? If it is, how can I manage empty elements when I need them? The foreach command never even sees the empty arguments. By the time ${list} is evaluated the empty elements are gone. This is for language consistency. No one would want add_executable(myexe ${srcs}) to try to add "" as a source file if srcs has an empty element. In CMake HEAD from CVS there is an "IN" mode for foreach that supports explicitly named lists: set(my_list "a;b;;c;d") foreach(arg IN LISTS my_list) ... endforeach() For now you need to use the list() command. You can iterate over a range of the list size with foreach(arg RANGE ...). -Brad ___ 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
Re: [CMake] foreach() bug?
Bill, it seems this policy doesn't affect foreach(): macro(test pol) cmake_policy(SET CMP0007 ${pol}) set(list) list(APPEND list A B "" C D) list(LENGTH list len) message("List: ${list} (length=${len})") foreach(arg ${list}) message("List elem: ${arg}") endforeach() endmacro() test(OLD) test(NEW) returns: List: A;B;;C;D (length=4) List elem: A List elem: B List elem: C List elem: D List: A;B;;C;D (length=5) List elem: A List elem: B List elem: C List elem: D Alexandre -Original Message- From: Bill Hoffman [mailto:bill.hoff...@kitware.com] This is related to this policy: http://www.cmake.org/cmake/help/cmake2.6docs.html#policy:CMP0007 -Bill This email was sent to you by Thomson Reuters, the global news and information company. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters. ___ 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
Re: [CMake] foreach() bug?
Denis Scherbakov wrote: The only solution I see is to use LIST(GET... But you'll need to get LIST length somehow... This is related to this policy: http://www.cmake.org/cmake/help/cmake2.6docs.html#policy:CMP0007 -Bill ___ 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
Re: [CMake] foreach() bug?
The only solution I see is to use LIST(GET... But you'll need to get LIST length somehow... Denis --- On Tue, 5/5/09, alexandre.feb...@thomsonreuters.com wrote: > From: alexandre.feb...@thomsonreuters.com > > Subject: Re: [CMake] foreach() bug? > To: cmake@cmake.org > Date: Tuesday, May 5, 2009, 9:41 AM > ping? > > > > Hi, > > > > this code: > > > > list(APPEND list A B "" C D) > > message("List: ${list}") > > foreach(arg ${list}) > > message("List elem: ${arg}") > > endforeach() > > > > has the following result: > > > > List: A;B;;C;D > > List elem: A > > List elem: B > > List elem: C > > List elem: D > > > > The empty element has been discarded by foreach(). Is this > the wanted > behaviour? If it is, how can I manage empty elements when I > need them? > > > > thanks > > Alexandre > > > > This email was sent to you by Thomson Reuters, the global > news and information company. > Any views expressed in this message are those of the > individual sender, except where the sender specifically > states them to be the views of Thomson Reuters. > > ___ > 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 ___ 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
Re: [CMake] foreach() bug?
ping? Hi, this code: list(APPEND list A B "" C D) message("List: ${list}") foreach(arg ${list}) message("List elem: ${arg}") endforeach() has the following result: List: A;B;;C;D List elem: A List elem: B List elem: C List elem: D The empty element has been discarded by foreach(). Is this the wanted behaviour? If it is, how can I manage empty elements when I need them? thanks Alexandre This email was sent to you by Thomson Reuters, the global news and information company. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters. ___ 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
[CMake] foreach() bug?
Hi, this code: list(APPEND list A B "" C D) message("List: ${list}") foreach(arg ${list}) message("List elem: ${arg}") endforeach() has the following result: List: A;B;;C;D List elem: A List elem: B List elem: C List elem: D The empty element has been discarded by foreach(). Is this the wanted behaviour? If it is, how can I manage empty elements when I need them? thanks Alexandre This email was sent to you by Thomson Reuters, the global news and information company. Any views expressed in this message are those of the individual sender, except where the sender specifically states them to be the views of Thomson Reuters. ___ 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
Re: [CMake] foreach: bug or feature?
Hi Andreas, The thing is that I was hoping that I would not have to check explicitly for any missing arguments to DEPENDS. But of course it is very wise to check and report this error. It was more that I was baffled by the behaviour of foreach(). I'll have to work around this feature ;-) Best regards, Marcel Loose. On Wed, 2009-04-29 at 15:11 +0200, Andreas Pakulat wrote: > On 29.04.09 14:58:00, Marcel Loose wrote: > > Hi Andreas, > > > > Seems we disagree about the intuitiveness of the API. Maybe I've done > > too much C/C++ programming ;-) > > Hmm, I'm doing mostly C++ as well :) > > > I stumbled upon this problem while I was trying to parse the input > > arguments to a macro(add_package _name). This macro can be used as > > follows: add_package(name [version] [DEPENDS depend depend ...]) > > I wanted to get all the arguments after DEPENDS. Here's a simplified > > version of the macro. > > > > macro(add_package _name) > > set(_args ${ARGN}) > > list(FIND _args DEPENDS _start) > > list(LENGTH _args _stop) > > math(EXPR _start "${_start}+1") > > math(EXPR _stop "${_stop}-1") > > message(STATUS "_index = ${_start}") > > message(STATUS "_length = ${_stop}") > > foreach(idx RANGE ${_start} ${_stop}) > > list(GET _args ${idx} _arg) > > message(STATUS "_args[${idx}] = ${_arg}") > > endforeach(idx RANGE ${_start} ${_stop}) > > endmacro(add_package _name) > > > > While testing boundary condition, I noted that this macro fails when > > there are no arguments after DEPENDS. In that case start > stop, so I > > did not expect CMake to enter the foreach loop at all. But it did, and > > triggered a list index out of range error. Now, that's what I found > > counter-intuitive. > > Well, but the bug is in your macro, it doesn't check that there's at least > one dependency listed, while apparently thats a requirement. And in this > case you wouldn't have won a lot if RANGE would bail out if start is larger > than stop or simply switches them, you'd still have to dig into your macro > and add some debug prints to find out why start/stop don't have the > expected value. > > Andreas > ___ 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
Re: [CMake] foreach: bug or feature?
On 29.04.09 14:58:00, Marcel Loose wrote: > Hi Andreas, > > Seems we disagree about the intuitiveness of the API. Maybe I've done > too much C/C++ programming ;-) Hmm, I'm doing mostly C++ as well :) > I stumbled upon this problem while I was trying to parse the input > arguments to a macro(add_package _name). This macro can be used as > follows: add_package(name [version] [DEPENDS depend depend ...]) > I wanted to get all the arguments after DEPENDS. Here's a simplified > version of the macro. > > macro(add_package _name) > set(_args ${ARGN}) > list(FIND _args DEPENDS _start) > list(LENGTH _args _stop) > math(EXPR _start "${_start}+1") > math(EXPR _stop "${_stop}-1") > message(STATUS "_index = ${_start}") > message(STATUS "_length = ${_stop}") > foreach(idx RANGE ${_start} ${_stop}) > list(GET _args ${idx} _arg) > message(STATUS "_args[${idx}] = ${_arg}") > endforeach(idx RANGE ${_start} ${_stop}) > endmacro(add_package _name) > > While testing boundary condition, I noted that this macro fails when > there are no arguments after DEPENDS. In that case start > stop, so I > did not expect CMake to enter the foreach loop at all. But it did, and > triggered a list index out of range error. Now, that's what I found > counter-intuitive. Well, but the bug is in your macro, it doesn't check that there's at least one dependency listed, while apparently thats a requirement. And in this case you wouldn't have won a lot if RANGE would bail out if start is larger than stop or simply switches them, you'd still have to dig into your macro and add some debug prints to find out why start/stop don't have the expected value. Andreas -- Never reveal your best argument. ___ 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
Re: [CMake] foreach: bug or feature?
Hi Andreas, Seems we disagree about the intuitiveness of the API. Maybe I've done too much C/C++ programming ;-) I stumbled upon this problem while I was trying to parse the input arguments to a macro(add_package _name). This macro can be used as follows: add_package(name [version] [DEPENDS depend depend ...]) I wanted to get all the arguments after DEPENDS. Here's a simplified version of the macro. macro(add_package _name) set(_args ${ARGN}) list(FIND _args DEPENDS _start) list(LENGTH _args _stop) math(EXPR _start "${_start}+1") math(EXPR _stop "${_stop}-1") message(STATUS "_index = ${_start}") message(STATUS "_length = ${_stop}") foreach(idx RANGE ${_start} ${_stop}) list(GET _args ${idx} _arg) message(STATUS "_args[${idx}] = ${_arg}") endforeach(idx RANGE ${_start} ${_stop}) endmacro(add_package _name) While testing boundary condition, I noted that this macro fails when there are no arguments after DEPENDS. In that case start > stop, so I did not expect CMake to enter the foreach loop at all. But it did, and triggered a list index out of range error. Now, that's what I found counter-intuitive. Best regards, Marcel Loose. On Wed, 2009-04-29 at 14:14 +0200, Andreas Pakulat wrote: > On 29.04.09 13:56:12, Marcel Loose wrote: > > Hi all, > > > > foreach(cnt RANGE 3 1) > > message(STATUS "${cnt}") > > endforeach(cnt RANGE 3 1) > > > > produces the output > > -- 3 > > -- 2 > > -- 1 > > > > Apparently, CMake decides to count backward whenever stop > start. > > > > I find this a little counter-intuitive; > > I find this rather intuitive. Its still a valid range. > > I'm assuming you've stumbled over this will looking for the cause of a > problem you have? Can you explain what problem that is? > > Andreas > ___ 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
Re: [CMake] foreach: bug or feature?
On 29.04.09 13:56:12, Marcel Loose wrote: > Hi all, > > foreach(cnt RANGE 3 1) > message(STATUS "${cnt}") > endforeach(cnt RANGE 3 1) > > produces the output > -- 3 > -- 2 > -- 1 > > Apparently, CMake decides to count backward whenever stop > start. > > I find this a little counter-intuitive; I find this rather intuitive. Its still a valid range. I'm assuming you've stumbled over this will looking for the cause of a problem you have? Can you explain what problem that is? Andreas -- Change your thoughts and you change your world. ___ 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
[CMake] foreach: bug or feature?
Hi all, foreach(cnt RANGE 3 1) message(STATUS "${cnt}") endforeach(cnt RANGE 3 1) produces the output -- 3 -- 2 -- 1 Apparently, CMake decides to count backward whenever stop > start. I find this a little counter-intuitive; counting now starts at stop and stops at start (confusing isn't it). Why not let the third optional parameter step denote the fact that I want to count down. This requires that step can have a negative value, which currently isn't allowed. My suggestion would be: 1) Always start counting at start and stop counting at stop. This implies that if start > stop, the loop will not be executed at all. 2) Let step determine the increment that is applied to cnt with each iteration. Variable step may be negative; in that case, the net effect is that cnt is decremented with each iteration, and the loop is only executed if start > stop. So, for example: foreach(cnt RANGE 3 1 -1) message(STATUS "${cnt}") endforeach(cnt 3 1 -1) would then produce the output -- 3 -- 2 -- 1 B.T.W.: Is there a reason for counting up to and including stop, instead of the more usual up to? Kind regards, Marcel Loose. ___ 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