enlight planned changes to this revision.
enlight added a comment.

I'll submit a revised patch that contains an explanation of the generator 
expressions to aid future maintainers/contributors.


================
Comment at: cmake/modules/LLDBConfig.cmake:61
@@ +60,3 @@
+      # below, otherwise CMake will replace the whitespace with a semicolon in 
some contexts (which would stuff things up).
+      set (PYTHON_EXECUTABLE 
$<$<CONFIG:Debug>:${PYTHON_DEBUG_EXE}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_EXE}>)
+      set (PYTHON_LIBRARY 
$<$<CONFIG:Debug>:${PYTHON_DEBUG_LIB}>$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_LIB}>)
----------------
zturner wrote:
> enlight wrote:
> > zturner wrote:
> > > This line is hard to parse mentally, and I'm not sure I've seen this kind 
> > > of nested generator expression.  I trust you when you say it's right, but 
> > > can you explain what this does?
> > Sure thing.
> > 
> >   # `$<CONFIG:Debug>` evaluates to `1` when the `Debug` configuration is 
> > being generated, or `0` in all other cases.
> >   # `$<$<CONFIG:Debug>:${PYTHON_DEBUG_EXE}>` expands to 
> > `${PYTHON_DEBUG_EXE}` when the `Debug` configuration is being generated, or 
> > nothing (literally) in all other cases.
> >   # `$<$<NOT:$<CONFIG:Debug>>:${PYTHON_RELEASE_EXE}>` expands to 
> > `${PYTHON_RELEASE_EXE}` when any configuration other than `Debug` is being 
> > generated, or nothing in all other cases.
> > 
> > Since the conditionals in 2 & 3 are mutually exclusive, and a conditional 
> > expression that evaluates to `0` yields no value at all, it's possible to 
> > concatenate them to obtain a single value. This value will be 
> > `${PYTHON_DEBUG_EXE}` when generating the Debug configuration, or 
> > `${PYTHON_RELEASE_EXE}` when generating any other configuration.
> Ahh, I understand.  Is it equivalent to write this:
> 
>     if ($<CONFIG:Debug> == 1)
>       set(PYTHON_EXECUTABLE ${PYTHON_DEBUG_EXE})
>     else()
>       set(PYTHON_EXECUTABLE ${PYTHON_RELEASE_EXE})
>     endif()
> 
> ?  If so, I kind of prefer this way, if nothing else so that other people 
> will be able to understand it in the future if they go to edit this code.
Unfortunately that's not currently possible because the `if` command doesn't 
support generator expressions (not that the docs mention it or anything). So 
while CMake won't complain if you did this:

```
if ($<CONFIG:Debug>)
  set (PYTHON_EXECUTABLE ${PYTHON_DEBUG_EXE})
else ()
  set (PYTHON_EXECUTABLE ${PYTHON_RELEASE_EXE})
endif ()
```

It wouldn't actually work as intended because the `if/else` is only evaluated 
once during the configuration step rather than per-build-configuration (during 
the generation step).


Repository:
  rL LLVM

http://reviews.llvm.org/D13234



_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to