[cmake-developers] [CMake 0014727]: libraries list in target_link_libraries() may be optimized
Mantis Bug Tracker
mantis at public.kitware.com
Sun Feb 2 22:57:10 EST 2014
The following issue has been SUBMITTED.
======================================================================
http://www.cmake.org/Bug/view.php?id=14727
======================================================================
Reported By: NAKAMURA Takumi
Assigned To:
======================================================================
Project: CMake
Issue ID: 14727
Category: CMake
Reproducibility: always
Severity: feature
Priority: normal
Status: new
======================================================================
Date Submitted: 2014-02-02 22:57 EST
Last Modified: 2014-02-02 22:57 EST
======================================================================
Summary: libraries list in target_link_libraries() may be
optimized
Description:
See "suboptimal" cases.
The document says,
"Repeated calls for the same <target> append items in the order called."
I understand they are expected behaviors.
That said, I wish add_executable() (and add_library(MODULE|SHARED)) may have an
option to optimize link order.
FYI, redundant target_link_libraries() for add_library() doesn't cause
suboptimal link order in most cases. See the case in baz.
Consider cases;
1) To add user-customized target_link_libraries() after a certain macro that
contains add_executable() and its target_link_libraries().
2) I'd like to write, in target_link_libraries(),
not "tuned" list of libraries,
but "actually used in SOURCES" list of libraries.
I am planning to write "auto dependencies scanner and generator"
FYI, one of my issues is in LLVM.
For example clang/tools/clang-format/CMakeLists.txt
https://github.com/chapuni/clang/blob/master/tools/clang-format/CMakeLists.txt
add_executable(clang-format) emits optimal list of libraries only when;
target_link_libraries(clang-format clangFormat)
In this case, clanbBasic, clangLex, clangRewriteCore, clangTooling, and
LLVMSupport are *actually referenced* from ClangFormat.cpp.
Steps to Reproduce:
add_library(foo foo.c)
add_library(bar bar.c)
target_link_libraries(bar foo)
add_library(baz baz.c)
target_link_libraries(baz foo)
target_link_libraries(baz bar)
target_link_libraries(baz foo bar)
add_executable(foobar foobar.c)
if(0)
# suboptimal -- libfoo.a libbaz.a libbar.a libfoo.a
target_link_libraries(foobar foo baz)
elseif(0)
# suboptimal -- libfoo.a libbaz.a libbar.a libfoo.a
target_link_libraries(foobar foo)
target_link_libraries(foobar baz)
elseif(0)
# suboptimal -- libbaz.a libbaz.a libbaz.a libbar.a libfoo.a
target_link_libraries(foobar baz)
target_link_libraries(foobar baz baz)
else()
# optimal -- libbaz.a libbar.a libfoo.a
target_link_libraries(foobar baz)
endif()
======================================================================
Issue History
Date Modified Username Field Change
======================================================================
2014-02-02 22:57 NAKAMURA TakumiNew Issue
======================================================================
More information about the cmake-developers
mailing list