Le jeu. 4 oct. 2018 à 16:06, Björn Blissing <bjorn.bliss...@vti.se> a écrit :
> 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}> > > ) > I don't quite understand your usage here. The genex $<BOOL:TRUE> is always true? You must have something like: $<$<BOOL:${CONDVAR}>:${MYLIB_LIBRARIES}> with CONDVAR computed before that to HOLD TRUE/1 or FALSE/0 or something similar? I would try to build a proper MYLIBS_DEBUG and MYLIBS_OPTIMIZED list out of your MYLIB_LIBRARIES var and then: target_link_libraries(target_name PUBLIC $<$<CONFIG:Debug>:${MYLIBS_DEBUG}> $<$<CONFIG:Release>:${MYLIBS_OPTIMIZED}> which may be easier to read. Or may be I missed something in your explanation. > > 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 > -- Eric
-- 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