[CMake] relinking

Alexandru Ciobanu aciobanu at matrox.com
Wed Jun 27 10:03:22 EDT 2007


Hi!

I am using CMake to build three libraries. They are located
in separate folders (with separata CMakeLists.txt):

libA/
   ./CmakeLists.txt

libB/
   ./CmakeLists.txt

libC/
   ./CmakeLists.txt

All the problems are caused by the circular dependency among
these libraries:
    libA - depends on libB and libC
    libB - depends on libA and libC
    libC - depends on libA and libB


I am able to build them with CMake, but that involves compiling
the source files two times (for each library). It is done this way:

in libA/CmakeLists.txt
     add_library ( libA_tmp ${srcA} )

     add_library ( libA ${srcA} )
     target_link_libraries ( libA libB libC )

in libB/CmakeLists.txt
     add_library ( libB_tmp ${srcB} )
     target_link_libraries ( libB_tmp libA_tmp )

     add_library ( libB ${srcB} )
     target_link_libraries ( libB libA_tmp libC_tmp )

in libC/CmakeLists.txt
     add_library ( libC_tmp ${srcC} )
     target_link_libraries ( libC_tmp libA_tmp )

     add_library ( libC ${srcC} )
     target_link_libraries ( libC libA_tmp libB_tmp )

In a nutshell:
   1. I build tmp version of all the libs ( having a few undefined 
references )
   2. I link agains the tmp versions of the libs to build the final 
(complete) library

The problem:
   I have to build each library from sources two times each.

Is there a way to reuse the generated *.o files from the first 
add_library() clause?
What I am looking for is something like this (for libA):

     add_library ( libA_tmp ${srcA} )

     # get list of generated object files in ${objA}

     # now only linking will be done ( no recompile )
     add_library ( libA ${objA} )
     target_link_libraries ( libA libB libC )

So, is there a simple way to achieve this? Or I would have to generate the
list of objects from the list of source files by hand?

sincerely,
Alexandru Ciobanu


More information about the CMake mailing list