CMake: Is there anyway to force linking libraries?

2019-07-26 14:11发布

问题:

Is there anyway to force linking libraries again. This would be useful when some libraries have changed but there is no change in any of the source codes of current project. I am looking for something like this:

make link

回答1:

CMake should be able to relink automatically when a particular library changes if you follow the tips here: http://www.cmake.org/pipermail/cmake/2010-November/041072.html

The main idea is to give a full path to target_link_libraries(), rather than just the library name. If you give a full path, CMake will actually inspect the file for modification and relink if it has changed.

If you prefer to explicitly trigger relinking yourself, you can use add_custom_command to make a command like make link which will remove the executable and then trigger a regular make to rebuild it.