<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/60610>60610</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
LLVM should correctly export CMake targets in a relocatable manner
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
rnichollx
</td>
</tr>
</table>
<pre>
LLVM should correctly export CMake targets.
Each library should be exported using CMake's built-in functions. The manual construction of LLVMConfig creates some issues: Namely, the provided targets don't work unless you manually attach ${LLVM_INCLUDE_DIR} to your target include directories. This is wrong behavior because the export set becomes non-relocatable.
Example scenario:
Server 1 builds llvm-x86_64 in /var/opt/jenkins/workspace_23098402/llvm-build
Exports the CMake build target package
Server 2 imports the a package built against that build tree to
/var/opt/jenkins/workspace_29083421/dep/llvm-x86_64
Then compilation fails with an error similar to
Error: Include directory /var/opt/jenkins/workspace_23098402/llvm-sources/include does not exist
Or just fails to find the include directory during compilation (depends on generator and such), or, worst case, finds the one installed at /usr/local/include/llvm instead of the target you are building against and your project is corrupted because the header versions don't match the TUs you are linking against. :)
This happens because adding ${LLVM_INCLUDE_DIRECTORIES} to a target's include directories evaluates the variable and thus sticks an absolute path into the include directories of the target, which of course makes the target non-relocatable between machines.
Best solution is to add separate include directories per-target to LLVM, but since that would require splitting up the llvm source directories a fair bit, a better solution would be to create an interface target e.g. LLVMHeaders which has target_include_directories attach the headers directory to itself (making sure to use generator expressions to set build and install interfaces separately) then have every LLVM target link against that target with PUBLIC privacy. e.g.
```
target_link_libraries(LLVMIR PUBLIC LLVMHeaders)
```
Then use built-in functions of CMake like export to get this functionality by using export sets so the build tree becomes relocatable.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJycVstu40oO_Rp5Q8RQSo4fCy86D2MCpLsH3enZBpREW9UpV2mKlB3__YAl-dWTxb0XMAzY9eDh4eFhIbPdeKJldnef3T2Os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