[CMake] relinking
Alexandru Ciobanu
aciobanu at matrox.com
Wed Jun 27 11:35:59 EDT 2007
Hi, James!
Thanks for referring me to the Chicken system. Their CMakeLists.txt is a
good read on how things should flow.
Now regarding the relinking problem, I wish I could change the whole setup,
but it's an older corporate system.
And since the circular dependencies are so bad, it is (sort-of) OK to employ
dirty tricks. ;)
I've solved my problem by creating the list of objects files given the list
of source files, using a path like this as prefix:
${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/${target}.dir/${src_path}/${src_name}${CMAKE_CXX_OUTPUT_EX
Looks evil, but it saves me 10min in build time, as I use this ${obj}
list to relink directly. =)
Alex Ciobanu
James Bigler wrote:
> Hi,
>
> Alexandru Ciobanu wrote:
>> 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?
>
> I'm not sure about the object file thing. I know that where the
> object files get placed is not exposed in the CMake API, but there are
> examples of this being done (I think the Chicken language build does
> something like this).
>
> Taking that aside, one would ask why you have three separate libraries
> that depend on the contents of each other. If it's possible why not
> make just a single library from the sources in A, B and C? I've done
> this in my project for sources that span several directories.
>
> Another possibility is to create a fourth single library from that
> links against lib{A,B,C}_tmp and use that single library in place of
> lib{A,B,C} thus resolves all the dependencies.
>
> In general, I've been more happy avoiding circular library
> dependencies than trying to support them. Some operating systems can
> get really cranky trying to do this.
>
> James
> _______________________________________________
> CMake mailing list
> CMake at cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
>
>
More information about the CMake
mailing list