[Cmake] separate compiling and linking

William A. Hoffman billlist at nycap.rr.com
Mon, 26 Apr 2004 16:08:35 -0400


This can not be done in 1.8, but cvs cmake can add .o files as part
of the build.   You could not find the .o files from cmake, but
you could generate the list of names from the source list.
Since cmake is not actually doing the builds, there is no way
for cmake to glob the .o files as they will not exist until cmake
is long gone.  So, you would have to create them yourself:

SET(SOURCES foo.cxx;bar.cxx)
FOREACH(s ${SOURCES})
  STRING(REGEX REPLACE ".cxx" ".o" obj ${s})
  SET(OBJS ${OBJS};${obj})
ENDFOREACH(s)

Then add the dummy libraries, and use ADD_DEPENDENCY to make
sure that the dummy libraries get built before the end library, and
it might work....


Of course, you will have to be careful about .obj and .o.

-Bill


At 01:30 PM 4/26/2004, Iker Arizmendi wrote:
>The trouble with this approach is that each of
>the "components" can use the same filename for
>things that are common to most components. For
>example, common.cpp or utils.cpp. In addition,
>things get a little messier when the components also
>make use of flex/bison (which may also have common
>names like "parser.y"). In this case the ability
>to "encapsulate" each directory's possibly complex
>build rules would be useful.
>
>I'd like to get something like this to work:
>
>   SUBDIRS (componentOne, componentTwo)
>
>   # This includes both "regular" object files
>   # and objects created through flex/bison
>   FILE(GLOB_RECURSE GEN_OBJ_FILES *.o
>        ${CMAKE_CURRENT_BINARY_DIR}/*.o)
>
>   # Then use something like CMAKE_AR to build
>   # the big library. This would result in a few
>   # wasted calls to ADD_LIBRARY whose only purpose
>   # would be to compile the sources.
>
>At the moment it doesn't seem to work since the file
>glob doesn't "wait" for the SUBDIRS directive to
>finish building each of the subdirectories. Is there
>some way to accomplish this?
>
>Thanks,
>Iker
>
>
>
>
>
>William A. Hoffman wrote:
>>You could do something like this:
>>LibTopDir CMakeLists.txt:
>>INCLUDE(LibComponentOne/CMakeLists.txt)
>>INCLUDE(LibComponentTwo/CMakeLists.txt)
>>ADD_LIBRARY(BigLib ${LibOneSources} ${LibTwoSources})
>>So, remove the SUBDIRS command and only set a list of files in each LibDir.
>>-Bill
>>At 10:21 PM 4/23/2004, Iker Arizmendi wrote:
>>
>>>Given the following configuration:
>>>
>>>LibTopDir
>>>|
>>>|--->CMakeLists.txt
>>>|
>>>|--->LibComponentOne
>>>|    |--> CMakeLists.txt
>>>|    |--> One.cpp, One.h, ...
>>>|
>>>|--->LibComponentTwo
>>>|    |--> CMakeLists.txt
>>>|    |--> Two.cpp, Two.h, ...
>>>
>>>
>>>Is there a clean way to instruct CMake to _compile_
>>>component objects in their respective directories
>>>but to link them into a single library at the
>>>LibTopDir level? I'm currently building a separate
>>>library (with ADD_LIBRARY) for each "component" to
>>>keep each one's source and build rules isolated from
>>>the rest. But in the end all of these libraries are
>>>used together by our client applications so it would
>>>make sense to just produce a single library instead
>>>of having client apps deal with the clutter.
>>>
>>>Thanks,
>>>Iker
>>>
>>>-- Iker Arizmendi
>>>AT&T Labs - Research
>>>Speech and Image Processing Lab
>>>e: iker at research.att.com
>>>w: http://research.att.com
>>>
>>>
>>>
>>>_______________________________________________
>>>Cmake mailing list
>>>Cmake at www.cmake.org
>>>http://www.cmake.org/mailman/listinfo/cmake
>>
>>_______________________________________________
>>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
>
>
>_______________________________________________
>Cmake mailing list
>Cmake at www.cmake.org
>http://www.cmake.org/mailman/listinfo/cmake