[Cmake] separate compiling and linking

Andy Cedilnik andy.cedilnik at kitware.com
Tue, 27 Apr 2004 14:04:33 -0400


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.