[CMake] multiple project hsaring the same files.

Alexander Neundorf a.neundorf-work at gmx.net
Wed Sep 28 10:32:11 EDT 2005


> Von: Amitha Perera <perera at cs.rpi.edu> 
>  
> A simple extension to allow object files to be shared is to allow .o 
> files to be added to the library directly. So: 
>  
> ADD_LIBRARY( A file.c ) 
> ADD_LIBRARY( B file.c ) 
>  
> would cause file.c to be compiled twice. 
>  
> ADD_LIBRARY( A file.c ) 
> ADD_LIBRARY( B file.o ) 
>  
> would cause libB to reuse the existing .o file. 
>  
> ADD_LIBRARY( A file.c ) 
> ADD_LIBRARY( B file.o ) 
> ADD_LIBRARY( C file.o ) 
>  
> would cause the object file to be reused twice. 
>  
> ADD_LIBRARY( A file.c ) 
> ADD_LIBRARY( B file.c ) 
> ADD_LIBRARY( C file.o ) 
>  
> is ambiguious, and is flagged as an error. 
>  
> To get more exotic, maybe some syntax for disambiguating in the 
> latter case: 
>  
> ADD_LIBRARY( A file.c ) 
> ADD_LIBRARY( B file.c ) 
> ADD_LIBRARY( C {B}file.o ) 
 
How about something like: 
 
ADD_OBJECT_COLLECTION(my_stuff MY_STUFF_OBJECTS file.c. foo.c) 
 
-> file.c and foo.c will be compiled into file.o and foo.o, and 
MY_STUFF_OBJECTS will be filled with the list of the names of the 
generated object files: "/somewhere/src/foo.o;/somewhere/src/file.o".  
Not sure if the first parameter is actually needed. 
AFAIK there is currently no way to find out the name of the object file 
if you have only the name of the source file. If this would be possible, 
it might even be possible right now with some clever macro. There is also 
a bug report about this where somebody suggests to implement a property 
for targets so that you can get the list of object files from which the 
target is built. 
 
Then the following would already work without any changes (AFAIK): 
 
ADD_LIBRARY(blah SHARED blah.c ${MY_STUFF_OBJECTS}) 
ADD_BINARY(bar bar.c ${MY_STUFF_OBJECTS}) 
 
Bye 
Alex 
 

-- 
Lust, ein paar Euro nebenbei zu verdienen? Ohne Kosten, ohne Risiko!
Satte Provisionen für GMX Partner: http://www.gmx.net/de/go/partner


More information about the CMake mailing list