[CMake] Why are object files built several times?
Bill Hoffman
bill.hoffman at kitware.com
Wed Sep 26 09:19:06 EDT 2007
Andreas Pakulat wrote:
> On 26.09.07 15:13:38, Dizzy wrote:
>
>> On Wednesday 26 September 2007 14:55:52 Joachim Ziegler wrote:
>>
>>> Hello,
>>>
>>> I have two targets that have nearly the same sources:
>>>
>>> ADD_EXECUTABLE(startCompletionServer StartCompletionServer.cpp
>>> ${BASEFILES}) ADD_EXECUTABLE(test-adler32 test-adler32.cpp ${BASEFILES})
>>>
>>> I wonder why every object file belonging to the BASEFILES is built
>>> twice, once for the first target, once again for the second. This
>>> doubles my compile time!?
>>>
>> You will notice that cmake is building files inside a build directory
>> different for each target. So it is ment to be that way (normally you may
>> have different compile flags for different targets so you want that). If you
>> do not want that then just put your BASEFILES in a "convenience library" and
>> reuse it from both targets such as:
>>
>
> Note that this creates a static convenience library which is not
> portable to some architectures without extra compiler flags (need -fPIC
> on amd64 and maybe other 64bit architectures).
>
> Another way is to create a shared lib (and also install that one), but
> don't provide headers for the library and don't give it a SOVERSION so
> people won't link against it.
>
For the example given this is very portable. He is building two
executables and not two shared libraries.
-Bill
More information about the CMake
mailing list