[CMake] Sharing sources between two targets

J Decker d3ck0r at gmail.com
Mon Apr 22 15:52:56 EDT 2013


to use the same sources in multiple outputs, with different compile
options, I make a copy of the file (copy_if_different) into the binary, and
then specify that for the related projects.

EXECUTE_PROCESS(COMMAND cmake -E copy_if_different
${CMAKE_SOURCE_DIR}/${VECTLIB_SOURCES}
${CMAKE_BINARY_DIR}/src/vectlib/vectlib_double.cpp )

it's quite happy to make any missing path parts... can do something to
extract original path parts so you can make it be a similar relative path
in the binary.


On Mon, Apr 22, 2013 at 11:45 AM, Nick Gnedin <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
>
> 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>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20130422/66846d1d/attachment.htm>


More information about the CMake mailing list