# Genex JOIN combined with TARGET\_OBJECTS unexpected behavior

**URL:** https://discourse.cmake.org/t/genex-join-combined-with-target-objects-unexpected-behavior/3673
**Category:** Code
**Tags:** os:windows
**Created:** [July 2, 2021, 6:28am UTC](https://discourse.cmake.org/t/genex-join-combined-with-target-objects-unexpected-behavior/3673 "2021-07-02T06:28:43Z")
**Posts on this page:** 4
**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: [July 2, 2021, 6:28am UTC](https://discourse.cmake.org/t/genex-join-combined-with-target-objects-unexpected-behavior/3673/1 "2021-07-02T06:28:43Z")

</div>

1. xxx is a custom target with custom link command
2. xlib is an OBJECT library with say two objects a.obj and b.obj

I am using the following code:

add\_custom\_command(  
TARGET xxx  
PRE\_BUILD  
COMMENT ${CMAKE\_COMMAND} -E echo “$\<TARGET\_OBJECTS:${xlib}\>” \>\> listfile.txt  
COMMAND ${CMAKE\_COMMAND} -E echo “$\<TARGET\_OBJECTS:${xlib}\>” \>\> listfile.txt)

In this case the list file is constructed as expected with the following content:  
a.obj;b.obj  
The comment generated is also as expected.

Although we need the list file not to have those ; character and with a new line between each file so I thought to use the JOIN function in the following way:

add\_custom\_command(  
TARGET xxx  
PRE\_BUILD  
COMMENT ${CMAKE\_COMMAND} -E echo “$\<JOIN:$\<TARGET\_OBJECTS:${xlib}\>,\n\>” \>\> listfile.txt  
COMMAND ${CMAKE\_COMMAND} -E echo “$\<JOIN:$\<TARGET\_OBJECTS:${xlib}\>,\n\>” \>\> listfile.txt)

Well in this case the comment generated is as expected but the list file is empty…  
Any idea will be welcome.

Thanks,  
Serge

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [July 2, 2021, 8:45am UTC](https://discourse.cmake.org/t/genex-join-combined-with-target-objects-unexpected-behavior/3673/2 "2021-07-02T08:45:46Z")

</div>

I think the problem is not on `$<JOIN:...>` but rather on the `\n` character.  
For example, with “Unix Makefiles” generator, the makefile generated is erroneous because the `\n` character introduce unexpected new lines.

The best way to solve this is to create a small script (`CMake` script is OK) to generate the `listfile.txt` with the expected format.

---

<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: [July 2, 2021, 11:15am UTC](https://discourse.cmake.org/t/genex-join-combined-with-target-objects-unexpected-behavior/3673/3 "2021-07-02T11:15:16Z")

</div>

Thanks Mark  
and yes you are right when trying with some other character, it does the job.  
There is no way to encode a special character in the JOIN expression above?

---

<div class="post-metadata">

### Author: ![marc.chevrier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/ecb155/32.png) [@marc.chevrier](https://discourse.cmake.org/u/marc.chevrier)
#### Post date: [July 2, 2021, 11:47am UTC](https://discourse.cmake.org/t/genex-join-combined-with-target-objects-unexpected-behavior/3673/4 "2021-07-02T11:47:02Z")

</div>

No, there is no mechanism for that. Use a script instead.
