Interface target link order issue
I use system libraries and interface targets in one project. And I found that all libraries for interface targets goes after other system libraries during linking ignoring order in target_link_libraries.
Here is a small sample which reproduces this issue (also attached):
CMakeLists.txt:
cmake_minimum_required (VERSION 3.7)
project(app)
add_library(foo INTERFACE IMPORTED)
set_target_properties(foo PROPERTIES INTERFACE_LINK_LIBRARIES liba)
add_executable(app main.cpp)
target_link_libraries(app foo libb)
foo is interface target which has INTERFACE_LINK_LIBRARIES
property set to liba
.
I suppose that link order shall be liba
and then libb
but there is the result command line:
/usr/bin/c++ CMakeFiles/app.dir/main.cpp.o -o app -llibb -lliba
Why does link order differs from expected?
PS. Don't pay attention that those libraries don't exist. It's just to show the issue.
Edited by Craig Scott