[CMake] How to add a target link library, but only for a custom configuration ?
Glenn Coombs
glenn.coombs at gmail.com
Thu May 5 06:51:48 EDT 2011
Thanks for that link Michael. It doesn't please me, but I can confirm that
it does work :-) It's a nice hack around a deficiency in cmake. I ended up
using this code:
# First create a dummy library to hang the pthreads
# dependency on via the IMPORTED_LINK_INTERFACE_LIBRARIES property.
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/pthreads_dummy.c "")
add_library(pthreads_dummy STATIC
${CMAKE_CURRENT_BINARY_DIR}/pthreads_dummy.c)
# make sure the dummy library gets built
add_dependencies(systemc pthreads_dummy)
# export the dummy library so we can include it as an imported target
export(TARGETS pthreads_dummy NAMESPACE imported FILE
importedpthreads_dummy.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/importedpthreads_dummy.cmake)
# use the imported target to add pthread dependency for the DEBUGPTHREADS
config
set_target_properties(importedpthreads_dummy
PROPERTIES
IMPORTED_LINK_INTERFACE_LIBRARIES_DEBUGPTHREADS ${PTHREADS_LIBRARIES})
target_link_libraries(myLib importedpthreads_dummy)
which is a lot of extra lines when all I really want is something like this:
target_link_libraries(myLib CONFIG DebugPthreads pthreads)
--
Glenn
On 26 April 2011 15:15, Michael Hertling <mhertling at online.de> wrote:
>
> There is a possibility with an intermediate empty static library which
> gets reimported into the project and equipped with the target property
> IMPORTED_LINK_INTERFACE_LIBRARIES_<CONFIG>, but I don't know if that
> approach will please you... ;) Anyway, see [1] for the details.
>
> Regards,
>
> Michael
>
> [1] http://www.mail-archive.com/cmake@cmake.org/msg34680.html
>
> PS: Empty static libraries aren't allowed on Windows; use
>
> FILE(WRITE ${CMAKE_BINARY_DIR}/dummy.c "")
> ADD_LIBRARY(dummy STATIC dummy.c)
>
> to satisfy the Visual Studio tools.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110505/ea7532fc/attachment-0001.htm>
More information about the CMake
mailing list