<div dir="ltr">Can you / did you try this on Windows? I don't see any reason why it wouldn't work, but I remember having difficulty with all this CMake some time ago.</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 5, 2017 at 1:50 PM Shoaib Meenai via lldb-commits <<a href="mailto:lldb-commits@lists.llvm.org">lldb-commits@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: smeenai<br>
Date: Tue Dec 5 13:49:56 2017<br>
New Revision: 319840<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=319840&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=319840&view=rev</a><br>
Log:<br>
[CMake] Use PRIVATE in target_link_libraries for executables<br>
<br>
We currently use target_link_libraries without an explicit scope<br>
specifier (INTERFACE, PRIVATE or PUBLIC) when linking executables.<br>
Dependencies added in this way apply to both the target and its<br>
dependencies, i.e. they become part of the executable's link interface<br>
and are transitive.<br>
<br>
Transitive dependencies generally don't make sense for executables,<br>
since you wouldn't normally be linking against an executable. This also<br>
causes issues for generating install export files when using<br>
LLVM_DISTRIBUTION_COMPONENTS. For example, clang has a lot of LLVM<br>
library dependencies, which are currently added as interface<br>
dependencies. If clang is in the distribution components but the LLVM<br>
libraries it depends on aren't (which is a perfectly legitimate use case<br>
if the LLVM libraries are being built static and there are therefore no<br>
run-time dependencies on them), CMake will complain about the LLVM<br>
libraries not being in export set when attempting to generate the<br>
install export file for clang. This is reasonable behavior on CMake's<br>
part, and the right thing is for LLVM's build system to explicitly use<br>
PRIVATE dependencies for executables.<br>
<br>
Unfortunately, CMake doesn't allow you to mix and match the keyword and<br>
non-keyword target_link_libraries signatures for a single target; i.e.,<br>
if a single call to target_link_libraries for a particular target uses<br>
one of the INTERFACE, PRIVATE, or PUBLIC keywords, all other calls must<br>
also be updated to use those keywords. This means we must do this change<br>
in a single shot. I also fully expect to have missed some instances; I<br>
tested by enabling all the projects in the monorepo (except dragonegg),<br>
and configuring both with and without shared libraries, on both Darwin<br>
and Linux, but I'm planning to rely on the buildbots for other<br>
configurations (since it should be pretty easy to fix those).<br>
<br>
Even after this change, we still have a lot of target_link_libraries<br>
calls that don't specify a scope keyword, mostly for shared libraries.<br>
I'm thinking about addressing those in a follow-up, but that's a<br>
separate change IMO.<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D40823" rel="noreferrer" target="_blank">https://reviews.llvm.org/D40823</a><br>
<br>
<br>
Modified:<br>
lldb/trunk/cmake/modules/AddLLDB.cmake<br>
lldb/trunk/unittests/CMakeLists.txt<br>
lldb/trunk/unittests/Interpreter/CMakeLists.txt<br>
<br>
Modified: lldb/trunk/cmake/modules/AddLLDB.cmake<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/modules/AddLLDB.cmake?rev=319840&r1=319839&r2=319840&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/cmake/modules/AddLLDB.cmake?rev=319840&r1=319839&r2=319840&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/cmake/modules/AddLLDB.cmake (original)<br>
+++ lldb/trunk/cmake/modules/AddLLDB.cmake Tue Dec 5 13:49:56 2017<br>
@@ -92,7 +92,7 @@ function(add_lldb_executable name)<br>
list(APPEND LLVM_LINK_COMPONENTS ${ARG_LINK_COMPONENTS})<br>
add_llvm_executable(${name} ${ARG_UNPARSED_ARGUMENTS})<br>
<br>
- target_link_libraries(${name} ${ARG_LINK_LIBS})<br>
+ target_link_libraries(${name} PRIVATE ${ARG_LINK_LIBS})<br>
set_target_properties(${name} PROPERTIES<br>
FOLDER "lldb executables")<br>
<br>
<br>
Modified: lldb/trunk/unittests/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/CMakeLists.txt?rev=319840&r1=319839&r2=319840&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/CMakeLists.txt?rev=319840&r1=319839&r2=319840&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/unittests/CMakeLists.txt (original)<br>
+++ lldb/trunk/unittests/CMakeLists.txt Tue Dec 5 13:49:56 2017<br>
@@ -44,7 +44,7 @@ function(add_lldb_unittest test_name)<br>
POST_BUILD<br>
COMMAND "${CMAKE_COMMAND}" -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/Inputs)<br>
<br>
- target_link_libraries(${test_name} ${ARG_LINK_LIBS})<br>
+ target_link_libraries(${test_name} PRIVATE ${ARG_LINK_LIBS})<br>
endfunction()<br>
<br>
function(add_unittest_inputs test_name inputs)<br>
<br>
Modified: lldb/trunk/unittests/Interpreter/CMakeLists.txt<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/CMakeLists.txt?rev=319840&r1=319839&r2=319840&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/lldb/trunk/unittests/Interpreter/CMakeLists.txt?rev=319840&r1=319839&r2=319840&view=diff</a><br>
==============================================================================<br>
--- lldb/trunk/unittests/Interpreter/CMakeLists.txt (original)<br>
+++ lldb/trunk/unittests/Interpreter/CMakeLists.txt Tue Dec 5 13:49:56 2017<br>
@@ -8,5 +8,6 @@ add_lldb_unittest(InterpreterTests<br>
)<br>
<br>
target_link_libraries(InterpreterTests<br>
+ PRIVATE<br>
${PYTHON_LIBRARY}<br>
)<br>
<br>
<br>
_______________________________________________<br>
lldb-commits mailing list<br>
<a href="mailto:lldb-commits@lists.llvm.org" target="_blank">lldb-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits</a><br>
</blockquote></div>