[Cmake] separate compiling and linking

Iker Arizmendi iker at research.att.com
Tue, 27 Apr 2004 14:43:10 -0400


Haven't tried it out yet, but it assumes that all
subdirectory sources have unique names (Bill's earlier
dir1rules.cmake file should take care of that), and that
they all have a [.c|.cxx|.cpp] suffix. The list of
valid suffixes can always be extended to account for
new file types used to generate c and c++ files
(eg, ".l", ".y", ".moc", etc), but that would require
that subdirectory authors modify the top-level CMake
file.

Perhaps the following could get around that. If
the files (following from Bill's earlier email):

    dir1/dir1rules.cmake
    dir2/dir1rules.cmake

provide the list of objects that are generated by the
subdirectory (say DIR1_OBJS) in addition to the list
of sources then could the following work?

    INCLUDE(dir1/dir1rules.cmake)
    INCLUDE(dir2/dir2rules.cmake)
    SET(BIG_LIB_OBJS ${DIR1_OBJS} ${DIR2_OBJS})
    SET_SOURCE_FILES_PROPERTIES(${BIG_LIB_OBJS}
                                PROPERTIES GENERATED 1)
    ADD_LIBRARY(BigLib ${BIG_LIB_OBJS})

Each subdirectory would still need a "dummy" library
to force object file generation, but the top
level directory would not need to build the object
files again (nor be aware of any source file
extensions).

Iker


Andy Cedilnik wrote:
> Hi Iker,
> 
> How about something like this:
> 
> MACRO(CONVERT_TO_OBJECTS var srcs)
>   SET(${var})
>   FOREACH(src ${srcs})
>     STRING(REGEX REPLACE
>            "${CMAKE_CURRENT_SOURCE_DIR}"
>            "${CMAKE_CURRENT_BINARY_DIR}"
>            obj "${src}")
>     STRING(REGEX REPLACE
>            ".c[xp]*$" ".obj" obj "${obj}")
>     SET(${var} ${${var}} ${obj})
>   ENDFOREACH(src)
> ENDMACRO(CONVERT_TO_OBJECTS)
> 
> SET(all_object_files)
> FOREACH(cnt 1 2 3 4 5 ...)
>   ADD_LIBRARY(lib${cnt}dummy ${lib${cnt}_srcs})
>   CONVERT_TO_OBJECTS(lib${cnt}objs "${lib${cnt}_srcs}")
>   SET_SOURCE_FILES_PROPERTIES(${lib${cnt}objs} PROPERTIES GENERATED 1)
>   SET(all_object_files ${all_object_files} ${lib${cnt}objs})
> ENDFOREACH(cnt)
> 
> ADD_LIBRARY(fullLibrary ${all_object_files})
> 
> 		Andy
> 
> On Tue, 2004-04-27 at 12:59, Iker Arizmendi wrote:
> 
>>That's what I do at the moment. The problem is that
>>I have no easy way to get at the .o files in each of
>>the subdirectories that has a dummy library in order
>>to create a big library.
>>
>>Bill has suggested using the source files in each of
>>the component subdirectories to derive the name of
>>the objects. However, this doesn't work for
>>subdirectories that create objects from non-standard
>>sources (eg, from generated files with weird extensions).
>>
>>Ideally something like so would be the ticket (I think):
>>
>>    SUBDIRS(lib1dir lib2dir)
>>    FILES(GLOB_RECURSE DOT_OS ${CMAKE_CURRENT_BINARY_DIR}/*.o)
>>    ADD_LIBRARY(biglib ${DOT_OS})
>>
>>So that the top-level directory wouldn't have to know
>>anything about how the underlying object files are created.
>>But as Bill pointed out, this doesn't work because
>>no objects files are created until after CMake is run.
> 
> 
> 
> _______________________________________________
> Cmake mailing list
> Cmake at www.cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
> 

-- 
Iker Arizmendi
AT&T Labs - Research
Speech and Image Processing Lab
e: iker at research.att.com
w: http://research.att.com