[CMake] Reusing an already built object
Naram Qashat
cyberbotx at cyberbotx.com
Tue Oct 13 13:38:38 EDT 2009
Michael Wild wrote:
>
> On 13. Oct, 2009, at 0:13, Naram Qashat wrote:
>
>> Say I have a main executable and a number of shared libraries that
>> rely on that executable. Say I have a certain C++ source that is
>> required to be built by not only the main executable, but also every
>> single shared library (the source in question is a Windows-specific
>> file to handle memory allocations). I have found that when using a
>> Visual Studio generator, CMake causes the source file to be rebuilt
>> for every single shared library, causing an increase in build time.
>> Is there an easy way to have the object file not be rebuilt every
>> single time, but be reused for all the shared libraries? The source
>> file is included in the main executable through add_executable(), and
>> it's added to each of the shared libraries through add_library().
>>
>> Thanks,
>> Naram Qashat
>>
>
> How about using a static library?
>
> add_library( common STATIC common.c )
> add_executable( super super.c )
> target_link_libraries( super common )
> add_library( duper SHARED duper.c )
> target_link_libraries( duper common )
>
> However, are you going to link your executable against any of the shared
> libraries? If used in this way, you would get linking errors (unless the
> functions in common.c are static).
I'd rather not introduce a static library for this, unless there is no other
way. There must be some way to reuse the object file without the use of a
static library, I can't see this being some limitation of CMake. But then
again, I don't know enough about how CMake creates it's build system to know if
there is a way or not, besides your suggestion of using a static library.
Thanks,
Naram
> Michael
>
More information about the CMake
mailing list