<div dir="ltr"><div><div>Hello,</div><div><br></div>I'd like to understand how CMake orders the libraries in <span style="font-family:monospace">LLVM_LINK_COMPONENTS</span> for proper linking in the build command, and especially why it repeats some of them. This is in the context of a patch to link NVPTX libraries into bugpoint (<a href="https://reviews.llvm.org/D32003">D32003</a>) for Polly when <font face="monospace">LLVM_POLLY_LINK_INTO_TOOLS=ON </font>and <span style="font-family:monospace">POLLY_ENABLE_GPGPU_CODEGEN=ON.</span></div><div><br></div><div>This patch <a href="https://reviews.llvm.org/D31859">D31859</a> initialises the NVPTX backend within Polly when <span style="font-family:monospace">POLLY_ENABLE_GPGPU_CODEGEN=ON</span> and requires the NVPTX libraries to be linked into the application or library that also links to Polly, e.g. <span style="font-family:monospace">opt, bugpoint</span>. <font face="monospace">opt</font> already links to the backend by adding <span style="font-family:monospace">${LLVM_TARGETS_TO_BUILD</span><span style="font-family:monospace">}</span> to <span style="font-family:monospace">LLVM_LINK_COMPONENTS</span>. I had attempted to link NVPTX into bugpoint in similar ways (<a href="https://reviews.llvm.org/D32003#728913">D32003#728913</a>) and the build kept failing, before finding out that <span style="font-family:monospace">add_llvm_tool</span> was linking the libraries in <span style="font-family:monospace">LLVM_LINK_COMPONENTS</span> to bugpoint. It seemed that CMake was processing LLVM_LINK_COMPONENTS on bugpoint's files before it did on Polly, and hence optimised out <span style="font-family:monospace">COMPONENTS</span> (e.g. NVPTX) which weren't required by bugpoint although required by Polly. Please correct me if I'm wrong here.</div><div><br></div><div>Is it possible to indicate to CMake to delay ordering the libraries in <span style="font-family:monospace">LLVM_LINK_COMPONENTS</span> till Polly is linked to bugpoint ?</div><div>Or link Polly to bugpoint before the <span style="font-family:monospace">LINK_COMPONENTS</span> ?</div><div>Or link NVPTX to bugpoint even if it didn't contain any calls to the NVPTX back-end (like -Wl,--no-as-needed) ?</div><div><br></div><div><a href="https://reviews.llvm.org/D32003#725937">Previous versions</a> of the patch had <font face="monospace">target_link_libraries( bugpoint LLVMNVPTXTargetInfo ...)</font> right after <span style="font-family:monospace">target_link_libraries( bugpoint<span class="inbox-inbox-Apple-converted-space"> Polly)</span></span> which did the job, but I was asked find a less complicated way of accomplishing the same thing.</div><div><br></div><div>It was interesting to find to <a href="https://reviews.llvm.org/D32003#728913">some of the libraries repeated in the build command</a>. Can anyone help me understand why this is the case ?</div><div><br></div><div>Thank You,</div><div>Sanjay</div></div>