Hello,

I am having trouble with a conditional generator expression inside target link 
libraries, which seems to expand incorrectly (or at least not the way I expect).

In short, I have a list of libraries that is found by a CMake module. The list 
is composed of a number of elements each preceded by "optimized" or "debug", 
depending on if there are built for release or debug. These libraries should 
only be included if a boolean is set to true. I have tried to write a generator 
expression which only includes the list of libraries if this variable is set. 
But it seems that this expression gets expanded wrong.

If I try to condense the problem to a minimum example, it would be something 
like this:

LIST(APPEND MYLIB_LIBRARIES optimized foo)
LIST(APPEND MYLIB_LIBRARIES debug foo_d)

TARGET_LINK_LIBRARIES(target_name
    PUBLIC
        $<$<BOOL:TRUE>:${MYLIB_LIBRARIES}>
)

This generator expression makes my target depend of the following libraries for 
the release build:
foo.lib & optimized.lib

And for the debug build:
foo_d.lib, foo.lib & optimized.lib

Which is obviously incorrect.

Replacing the generator expression with an IF-statement instead works. But I 
would like to stick to generator expressions if possible to keep my CMake code 
consistent.

How should I rewrite my generator expression to get the correct expansion?

Regards,
Björn

-- 

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

Reply via email to