[CMake] Sharing sources between two targets

David Cole dlrdave at aol.com
Mon Apr 22 15:09:58 EDT 2013


No, it doesn't double anything.

Without the outside_deps, the executable wouldn't link if it needed 
something from them.

With them, it will link, and be as small a size as the linker can make 
it. (Assuming a release build, where the linker leaves out what it 
doesn't need...)



-----Original Message-----
From: Nick Gnedin <ngnedin at gmail.com>
Cc: CMake ML <cmake at cmake.org>
Sent: Mon, Apr 22, 2013 2:55 pm
Subject: Re: [CMake] Sharing sources between two targets



That doubles the size of the executable, because if I do something like
that:

ADD_LIBRARY(temp STATIC ${sources})
TARGET_LINK_LIBRARIES(temp outside_deps)

ADD_EXECUTABLE(code main.cpp)
TARGET_LINK_LIBRARIES(code temp)

then TARGET_LINK_LIBRARIES(...) also add outside_deps as link libraries
for code, so they end up included twice.



On 04/22/2013 01:50 PM, Jean-Christophe Fillion-Robin wrote:
> Hi Nick,
>
> What about creating a static library that would be linked against both
> the executable and the library ?
>
> Hth
> Jc
>
>
> On Mon, Apr 22, 2013 at 2:45 PM, Nick Gnedin <ngnedin at gmail.com
> <mailto:ngnedin at gmail.com>> wrote:
>
>
>     Folks,
>
>     I am using CMake to create 2 targets - a stand-alone executable 
and
>     a library that can be imported by Python. Both share most of the
>     sources. If I just specify them as two separate targets, each will
>     compile all the sources, so most of the source files end up 
compiled
>     twice.
>
>     Is there a way to share the compiled sources between the two
>     targets? I can create an intermediate library, but that is less
>     convenient since the executable will then depend on it. What I 
would
>     really like is to have a self-contained executable and a separate
>     library that use the same object files.
>
>     Many thanks for any hint,
>
>     Nick Gnedin
>     --
>
>     Powered by www.kitware.com <http://www.kitware.com>
>
>     Visit other Kitware open-source projects at
>     http://www.kitware.com/__opensource/opensource.html
>     <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
>     <http://www.cmake.org/Wiki/CMake_FAQ>
>
>     Follow this link to subscribe/unsubscribe:
>     http://www.cmake.org/mailman/__listinfo/cmake
>     <http://www.cmake.org/mailman/listinfo/cmake>
>
>
>
>
> --
> +1 919 869 8849
--

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

  


More information about the CMake mailing list