[CMake] Relink on library rebuild dilema

Bill Hoffman bill.hoffman at kitware.com
Sun Nov 28 23:05:53 EST 2010


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...

-Bill




More information about the CMake mailing list