Re: [cmake-developers] $LIST_LENGTH{} syntax

2019-01-22 Thread Ben Boeckel via cmake-developers
On Tue, Jan 22, 2019 at 19:31:43 +0100, tors...@robitzki.de wrote:
> Currently, the Code that evaluates the ${}-Syntax only evaluates the key, if 
> the key is not an empty string:
> 
> const char* cmCommandArgumentParserHelper::ExpandSpecialVariable(
>   const char* key, const char* var)
> {
>   if (!key) {
> return this->ExpandVariable(var);
>   }
>   if (!var) {
> return "";
>   }
>   if (strcmp(key, "ENV") == 0) {
> std::string str;
> if (cmSystemTools::GetEnv(var, str)) {
>   if (this->EscapeQuotes) {
> return this->AddString(cmSystemTools::EscapeQuotes(str));
>   }
>   return this->AddString(str);
> }
> return "";
>   }
>   if (strcmp(key, „CACHE") == 0) {
> 
> …
> 
> so, there seems to be no risk to slow down the ExpandVariable()-Path (but of 
> cause, I would measure the difference).

That's the old (pre-CMP0053) parser. The new code for handling the
`$XXX{` parse switching is in `Source/cmMakefile.cxx:2810` (or so). The
method is `cmMakefile::ExpandVariablesInStringNew`. It is very
performance sensitive (i.e., the old parser is so slow compared to the
new one that running the new one beside it doesn't really affect
performance much and is what allows for CMP0053 warning messages).

--Ben
-- 

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-developers


Re: [cmake-developers] $LIST_LENGTH{} syntax

2019-01-22 Thread Brad King via cmake-developers
On 1/22/19 1:31 PM, tors...@robitzki.de wrote:
> Currently, the Code that evaluates the ${}-Syntax only evaluates the key
> 
> const char* cmCommandArgumentParserHelper::ExpandSpecialVariable(

That's the pre-CMP0053 impl.

See cmMakefile::ExpandVariablesInStringNew for the modern impl.
Only with CMP0053 set to NEW can we consider the new syntax.

-Brad
-- 

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-developers


Re: [cmake-developers] $LIST_LENGTH{} syntax

2019-01-22 Thread Torsten


> Am 22.01.2019 um 17:03 schrieb Brad King :
> 
> Yes, something more extensible would be fine.  We need to be careful
> not to slow down the variable reference syntax parser though.

Currently, the Code that evaluates the ${}-Syntax only evaluates the key, if 
the key is not an empty string:

const char* cmCommandArgumentParserHelper::ExpandSpecialVariable(
  const char* key, const char* var)
{
  if (!key) {
return this->ExpandVariable(var);
  }
  if (!var) {
return "";
  }
  if (strcmp(key, "ENV") == 0) {
std::string str;
if (cmSystemTools::GetEnv(var, str)) {
  if (this->EscapeQuotes) {
return this->AddString(cmSystemTools::EscapeQuotes(str));
  }
  return this->AddString(str);
}
return "";
  }
  if (strcmp(key, „CACHE") == 0) {

…

so, there seems to be no risk to slow down the ExpandVariable()-Path (but of 
cause, I would measure the difference).

kind regards,

Torsten


signature.asc
Description: Message signed with OpenPGP
-- 

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-developers


Re: [cmake-developers] $LIST_LENGTH{} syntax

2019-01-22 Thread Brad King via cmake-developers
On 1/22/19 10:55 AM, Marc CHEVRIER wrote:
> What about introducing a syntax similar to the version comparison:
> 
>   * LENGTH_EQUAL
>   * LENGTH_GREATER
>   * LENGTH_LOWER
>   * etc…
> 
> To use it:
> if (my_list LENGTH_EQUAL 1)
>   # do my stuff
> endif()

That's where this thread started.  Every new if() operator potentially
requires a policy, and there may be other places that the length of
a list is useful.

> Or introduce a more general syntax for list management as part
> of an expression:
> $LIST{,[,,…]}
> 
> Where ,  and  use same semantic as list command.
> To use it:
> of ($LIST{LENGTH,my_list} EQUAL 1)
>   # do my stuff
> endif()

Yes, something more extensible would be fine.  We need to be careful
not to slow down the variable reference syntax parser though.

-Brad
-- 

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-developers


Re: [cmake-developers] $LIST_LENGTH{} syntax (was: Support for list length expression in if()-command?)

2019-01-22 Thread Robert Maynard via cmake-developers
I like some syntax that looks like $LEN{}.

I would love to keep the $...{ syntax open for future exentsion such
as easy target property set/get ( $[prop_name]{target} ) . This seems
to be okay as $ENV, and $CACHE only work on variables, so therefore
adding $LEN that also only works on variables seems reasonable.

On Tue, Jan 22, 2019 at 7:46 AM Brad King via cmake-developers
 wrote:
>
> On 1/22/19 7:40 AM, Daniel Franke wrote:
> > Whats about a Syntax like
> >
> > ${list::LENGTH}
>
> That would require dispatch after matching `${VAR}` syntax, and
> that lookup is one of the hottest paths according to profiling.
> We already have $ENV{} and $CACHE{} syntax.
>
> -Brad
> --
>
> 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-developers
-- 

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-developers


Re: [cmake-developers] real functions (was: $LIST_LENGTH{} syntax)

2019-01-22 Thread Marc CHEVRIER
I am not convince that the proposed syntax is a good idea because it introduce 
a new syntax just to solve one action on a list.

What about introducing a syntax similar to the version comparison:

• LENGTH_EQUAL
• LENGTH_GREATER
• LENGTH_LOWER
• etc…

To use it:
if (my_list LENGTH_EQUAL 1)
  # do my stuff
endif()

Or introduce a more general syntax for list management as part of an expression:
$LIST{,[,,…]}

Where ,  and  use same semantic as list command.
To use it:
of ($LIST{LENGTH,my_list} EQUAL 1)
  # do my stuff
endif()

The advantage of this syntax is extensibility: More  can be added and more 
commands can be introduced (for example $STRING{…}).

Le 22 janv. 2019 à 16:37 +0100, Brad King via cmake-developers 
, a écrit :
> On 1/22/19 10:28 AM, tors...@robitzki.de wrote:
> > With `$CACHE{VAR}` and `$ENV{VAR}` we already have the syntax for calling a 
> > „function“.
>
> No, there is no obvious way to pass arguments, handle nested quoting, etc.
> The language was not designed for that. That is a big can of worms I'd rather
> not open just to solve the list length problem which is already only 2 lines.
>
> > Once we have this, it would be possible to define $LIST_LENGTH in the CMake 
> > language
>
> Not as efficiently as a dedicated syntax for the only language construct
> we have that resembles a data structure.
>
> -Brad
> --
>
> 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-developers
-- 

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-developers


Re: [cmake-developers] real functions (was: $LIST_LENGTH{} syntax)

2019-01-22 Thread Torsten


> Am 22.01.2019 um 16:37 schrieb Brad King :
> 
> On 1/22/19 10:28 AM, tors...@robitzki.de wrote:
>> With `$CACHE{VAR}` and `$ENV{VAR}` we already have the syntax for calling a 
>> „function“.
> 
> No, there is no obvious way to pass arguments, handle nested quoting, etc.

Jep, you are right. I’ve overlooked that nested aspect.

> The language was not designed for that.  That is a big can of worms I'd rather
> not open just to solve the list length problem which is already only 2 lines.

Ok, I understand this.


signature.asc
Description: Message signed with OpenPGP
-- 

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-developers


Re: [cmake-developers] real functions (was: $LIST_LENGTH{} syntax)

2019-01-22 Thread Brad King via cmake-developers
On 1/22/19 10:28 AM, tors...@robitzki.de wrote:
> With `$CACHE{VAR}` and `$ENV{VAR}` we already have the syntax for calling a 
> „function“. 

No, there is no obvious way to pass arguments, handle nested quoting, etc.
The language was not designed for that.  That is a big can of worms I'd rather
not open just to solve the list length problem which is already only 2 lines.

> Once we have this, it would be possible to define $LIST_LENGTH in the CMake 
> language

Not as efficiently as a dedicated syntax for the only language construct
we have that resembles a data structure.

-Brad
-- 

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-developers


Re: [cmake-developers] real functions (was: $LIST_LENGTH{} syntax)

2019-01-22 Thread Torsten


> Am 22.01.2019 um 13:33 schrieb Brad King :
> 
> On 1/22/19 7:09 AM, tors...@robitzki.de wrote:
> 
>> How about adding the ability to add such function? Like:
>> 
>> procedure(LIST_LENGTH list)
>>  list(LENGTH list length)
>>  return(${length})
>> endprocedure()
> 
> We don't have a syntax for invoking functions with return values.
> That’s a whole other discussion.

With `$CACHE{VAR}` and `$ENV{VAR}` we already have the syntax for calling a 
„function“. What is missing, is a command to define a function and a command to 
specify the return value of a function.

Once we have this, it would be possible to define $LIST_LENGTH in the CMake 
language itself. And real functions with return values could make writing in 
CMake language much more easier.



signature.asc
Description: Message signed with OpenPGP
-- 

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-developers


Re: [cmake-developers] $LIST_LENGTH{} syntax (was: Support for list length expression in if()-command?)

2019-01-22 Thread Brad King via cmake-developers
On 1/22/19 7:40 AM, Daniel Franke wrote:
> Whats about a Syntax like
> 
> ${list::LENGTH}

That would require dispatch after matching `${VAR}` syntax, and
that lookup is one of the hottest paths according to profiling.
We already have $ENV{} and $CACHE{} syntax.

-Brad
-- 

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-developers


Re: [cmake-developers] $LIST_LENGTH{} syntax (was: Support for list length expression in if()-command?)

2019-01-22 Thread Brad King via cmake-developers
On 1/22/19 7:09 AM, tors...@robitzki.de wrote:
>> Am 22.01.2019 um 12:42 schrieb Brad King:
>> Rather than a special `if` syntax, perhaps we could introduce an
>> explicit `$LIST_LENGTH{mylist}` syntax.  One would need to experiment
>> to see if modifying the variable expansion parser (under CMP0053 NEW
>> behavior only) to support this would have a significant performance
>> impact.
> 
> What would be a good experiment setup?

Using `cmake -P test.cmake` to run a script that does a lot of
variable evaluations without the proposed syntax, and later with it.

> How about adding the ability to add such function? Like:
> 
> procedure(LIST_LENGTH list)
>   list(LENGTH list length)
>   return(${length})
> endprocedure()

We don't have a syntax for invoking functions with return values.
That's a whole other discussion.

-Brad
-- 

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-developers


Re: [cmake-developers] Support for list length expression in if()-command?

2019-01-22 Thread Torsten


> Am 22.01.2019 um 12:42 schrieb Brad King :
> 
> 
> Rather than a special `if` syntax, perhaps we could introduce an
> explicit `$LIST_LENGTH{mylist}` syntax.  One would need to experiment
> to see if modifying the variable expansion parser (under CMP0053 NEW
> behavior only) to support this would have a significant performance
> impact.

What would be a good experiment setup? Timing the CMake configuration process 
itself (I mean the time it takes the configuration step, when building CMake 
with CMake).

How about adding the ability to add such function? Like:

procedure(LIST_LENGTH list)
  list(LENGTH list length)
  return(${length})
endprocedure()


signature.asc
Description: Message signed with OpenPGP
-- 

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-developers


Re: [cmake-developers] Support for list length expression in if()-command?

2019-01-22 Thread Brad King via cmake-developers
On 1/22/19 3:08 AM, tors...@robitzki.de wrote:
> three use cases:
> 
> - Checking for empty lists (I’ve showed him that this can be done
>   by a string compare).
> - Checking for lists having more than 1 entry
> - Checking for equal size of two lists. For example, if you want
>   to pass pairs or tuples to a function. (example: f(firsts seconds))

Rather than a special `if` syntax, perhaps we could introduce an
explicit `$LIST_LENGTH{mylist}` syntax.  One would need to experiment
to see if modifying the variable expansion parser (under CMP0053 NEW
behavior only) to support this would have a significant performance
impact.

-Brad
-- 

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-developers


Re: [cmake-developers] Support for list length expression in if()-command?

2019-01-22 Thread Torsten
Hi Brad,

> Am 14.01.2019 um 12:44 schrieb Brad King :
> 
> I've almost never needed to test the length of a list in CMake
> code.  It's not very common in my experience.  What is your
> customer trying to do?

Sorry for the late response! I’ve asked him. Mainly, he has three use cases:

- Checking for empty lists (I’ve showed him that this can be done by a string 
compare).
- Checking for lists having more than 1 entry
- Checking for equal size of two lists. For example, if you want to pass pairs 
or tuples to a function. (example: f(firsts seconds))

regards,

Torsten




signature.asc
Description: Message signed with OpenPGP
-- 

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-developers