[CMake] Relink on library rebuild dilema
Michael Hertling
mhertling at online.de
Mon Nov 29 06:52:27 EST 2010
On 11/29/2010 05:05 AM, Bill Hoffman wrote:
> On 11/28/2010 3:19 AM, Sebastian Schaetz wrote:
>> Michael Hertling<mhertling at ...> writes:
>>
>>> 1) In the top-level CMakeLists.txt, you might say
>>>
>>> SET_SOURCE_FILES_PROPERTIES(
>>> main.cpp PROPERTIES OBJECT_DEPENDS
>>> ${CMAKE_CURRENT_BINARY_DIR}/kernels/libkernel_executable.a
>>> )
>>>
>>> When libkernel_executable.a has changed, this results in recompiling
>>> main.cpp - a penalty - and the desired relinking of main_target. If
>>> main.cpp's recompilation is expensive you may possibly add an empty
>>> cpp file to main_target's sources and impose the property on that.
>>>
>>
>> Wow, those suggestions all sound great and I'm completely unfamiliar with them
>> (so I think there's a good chance they will work). I will try them as soon as
>> possible! Thanks a lot for the suggestions.
>>
>
> No need for all the complication...
>
> If you already know where the library is going to be:
>
> ${CMAKE_CURRENT_BINARY_DIR}/kernels/libkernel_executable.a
>
> Then link directly to the full path:
>
> target_link_libraries(main_target
> ${CMAKE_CURRENT_BINARY_DIR}/kernels/libkernel_executable.a)
>
> Now the makefiles will depend on that file and it will relink when that
> .a changes. This is why link_directories/*link_libraries without a
> full path to the library is almost always a bad idea...
Oops, the simplest solution at all. ~8) Thanks for pointing it out, Bill.
Perhaps, this is a good opportunity to ask a related question: Some
time ago, there has been an issue with special linker scripts which
are part of a project. Of course, one would like to see the linker
triggered when these scripts change, and the best solution I have
found so far is - just like suggested to the OP -
- a dummy source file to impose the OBJECT_DEPENDS property on, or
- a dummy static library that is invalidated when the scripts change
and (mis)used to force a dependency of the link line on the scripts.
Both alternatives are not really satisfying, so I wonder if there is any
smarter and more direct possibility to establish a file-level dependency
of the link line on an arbitrary file that's not mentioned as a library
in TARGET_LINK_LIBRARIES(). For Makefiles, this involves just a single
additional line.
Regards,
Michael
More information about the CMake
mailing list