# Genex unexpected behavior

**URL:** <https://discourse.cmake.org/t/genex-unexpected-behavior/3598>\
**Category:** Code\
**Tags:** os:windows, gen:vs\
**Created:** [June 20, 2021, 8:38am UTC](https://discourse.cmake.org/t/genex-unexpected-behavior/3598 "2021-06-20T08:38:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)\
**Post date:** [June 20, 2021, 8:38am UTC](https://discourse.cmake.org/t/genex-unexpected-behavior/3598/1 "2021-06-20T08:38:42Z")

</div>

This is an example code that creates in windows two static libraries a.lib and b.lib while b.lib is a superset of a.lib with additional custom objects.  
I know that this could have been done in a simpler way - although this is to demonstrate the unexpected behavior of some genex, here is the code:

set( custom\_objs b.obj)  
add\_library(a OBJECT a.cpp)  
add\_custom\_target(b ALL  
DEPENDS a  
COMMAND ${CMAKE\_COMMAND} -E echo “lib /OUT:b.lib ${custom\_objs} $\<JOIN:\<TARGET\_OBJECTS:a\>, \>”  
COMMAND lib /OUT:b.lib ${custom\_objs} $\<JOIN:\<TARGET\_OBJECTS:a\>, \>)

The custom target has two commands the first dump the lib command, the second executes.  
Well the genex: $Join:..... displays correctly a.obj while in the second command it does not expanded it at all.

Why is it so?  
Thanks,  
Serge

---

<div class="post-metadata">

**Author:** ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)\
**Post date:** [June 20, 2021, 9:28am UTC](https://discourse.cmake.org/t/genex-unexpected-behavior/3598/2 "2021-06-20T09:28:22Z")

</div>

The quotes are not interpreted by the command line tool, but already by CMake.  
They are needed for CMakes function argument parser to not interpret the space ` ` as delimiter in arguments.

So the right solution is `"$<JOIN:$<TARGET_OBJECTS:a>, >"`, otherwise you end up with two function arguments `$<JOIN:$<TARGET_OBJECTS:a>,` and `>`

P.S. The missing `$` before `<TARGET_OBJECTS>` is causing a CMake error.  
And I strongly suggest to use CMake `add_library` instead of creating custom targets.

---

<div class="post-metadata">

**Author:** ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)\
**Post date:** [June 20, 2021, 3:36pm UTC](https://discourse.cmake.org/t/genex-unexpected-behavior/3598/3 "2021-06-20T15:36:50Z")

</div>

Thanks Joseph for your answer - so genex work only inside quotes - I missed this detail.  
Also yes you are right, a $ was missing in my above example.

Thanks again.

---

<div class="post-metadata">

**Author:** ![jtxa](https://discourse.cmake.org/user_avatar/discourse.cmake.org/jtxa/32/1535_2.png) [@jtxa](https://discourse.cmake.org/u/jtxa)\
**Post date:** [June 20, 2021, 7:23pm UTC](https://discourse.cmake.org/t/genex-unexpected-behavior/3598/4 "2021-06-20T19:23:16Z")

</div>

Not GenEx in general.  
It’s the whitespace parsed by the CMake language interpreter as delimiter between arguments.

---

<div class="post-metadata">

**Author:** ![serge](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/5f8ce5/32.png) [@serge](https://discourse.cmake.org/u/serge)\
**Post date:** [June 21, 2021, 12:54pm UTC](https://discourse.cmake.org/t/genex-unexpected-behavior/3598/5 "2021-06-21T12:54:21Z")

</div>

Got it, thanks.
