On Tue, May 7, 2019 at 12:27 AM Tadeusz A. Kadłubowski <
tadeusz.kadlubow...@pix4d.com> wrote:

> Hi,
>
> I have an `INTERFACE IMPORTED` library target that depends on a bunch
> of optional dependencies. Please see the snippet below:
>
> cmake_minimum_required(VERSION 3.14)
>
> add_library(example INTERFACE IMPORTED)
> set_property(TARGET example PROPERTY INTERFACE_LINK_LIBRARIES
> $<$<CONFIG:Debug>:${undefined_dependency_one}
> ${undefined_dependency_two}>
> )
>

If your generator expression contains spaces, you need to surround the
whole expression with quotes:

set_property(TARGET example PROPERTY INTERFACE_LINK_LIBRARIES

"$<$<CONFIG:Debug>:${undefined_dependency_one} ${undefined_dependency_two}>"
)

Note that in this case, the space is unlikely to actually be what you want
because the above would end up adding a single library named

"${undefined_dependency_one} ${undefined_dependency_two}"



> It so happens that both of the optional dependencies
> `${undefined_dependency_one}` and `${undefined_dependency_two}` are
> set to empty/undefined on my system, which is perfectly fine.
>
> I want to do some postprocessing to the dependencies  of my target:
>
> get_target_property(all_dependencies example INTERFACE_LINK_LIBRARIES)
> foreach(lib IN LISTS all_dependencies)
>     message(STATUS "dependency on " ${lib})
> endforeach()
>
> This `foreach()` loop gets confused about the generator expression.
> The output of the `message(STATUS ...)` calls in the snippet above is:
>
> -- dependency on $<$<CONFIG:Debug>:
> -- dependency on >
>
> Please note that the generator expression got mangled into two pieces
> by the `foreach()` loop. I was expecting to see a single line of
> `$<$<CONFIG:Debug>:>`
>
> I experimented with different versions of this test case and found
> variants that do not get mangled in the `foreach()` loop. In a
> modification when there is only one empty/undefined dependency the
> `foreach()` loop works as expected.
>
> set_property(TARGET example PROPERTY INTERFACE_LINK_LIBRARIES
> $<$<CONFIG:Debug>:${undefined_dependency_one}>
> )
>
> A modification in which each empty/undefined dependency is surrounded
> with its own generator expression works correctly too:
>
> set_property(TARGET example PROPERTY INTERFACE_LINK_LIBRARIES
> $<$<CONFIG:Debug>:${undefined_dependency_one}>
> $<$<CONFIG:Debug>:${undefined_dependency_two}>
> )
>

This would be the way to achieve what you seem to be wanting to do.



>
> Is that a bug in how CMake handles generator expressions? Am I
> misunderstanding some CMake language concepts here?
>
> (all code tested with CMake 3.14.3 on Ubuntu 18.04)
>
> I would be grateful on any feedback about what's going on in that
> `foreach` loop.
>

-- 
Craig Scott
Melbourne, Australia
https://crascit.com

Get the hand-book for every CMake user: Professional CMake: A Practical
Guide <https://crascit.com/professional-cmake/>
-- 

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

Reply via email to