- Identify MLIR targets
- Optionally don't build tools
- per-project installation directory (useful for standalone)
FWIW this isn't quite enough for MLIR standalone but helps get things there. One issue is that the use of LLVM's TableGen.cmake instead of our own means that mlir-tblgen wants to be installed to LLVM_TOOLS_INSTALL_DIR which isn't great when building MLIR separately from LLVM (and keeping installation paths separate, such as for packaging purposes).
The cmake bits are certainly copies of equivalents in LLVM, which I don't love but seems to be what other projects do as well.
(IIRC, similarly, downstream projects using MLIR that try using a standalone-built MLIR will have trouble finding its mlir-tblgen if not among the LLVM tools? Maybe that's just the way I've temporarily resolved the above issue)
Cmake is dangerous. Knowing more or less makes no difference :)
This looks good to me and has needed to be done for a while. We may want to tweak the macro more but having it is step one. Thank you.
Are you able to land or do you need assistance with that?
TableGen is special ina few ways that I would need to take a closer look at to identify issues. Happy to do so, but can we summarize problems on the discussion to look more at of needed?
Thanks for the review!
Honestly, I thought you might be right :)...
However I believe that this does apply here: using add_llvm_tool/add_llvm_executable from an already installed LLVM causes those targets to try to be installed to LLVM's tool bin directory, which when packaging isn't always appropriate (or writable).
LLVM_TOOLS_INSTALL_DIR is set in the generated LLVMConfig.cmake using this template:
The code added in this change uses CMAKE_INSTALL_BINDIR which is what that variable defaults to in LLVM's build: https://github.com/llvm/llvm-project/blob/cbfa85734632ad7f961b18539464e7e870f80fd6/llvm/CMakeLists.txt#L307 .
I think this also means downstream projects using MLIR's version will work standalone more easily too, but I forget if I tested that.
As for TableGen I'll get back to you. Basically more bits where it expects/searches/generates targets using LLVM paths or so, but I didn't find a good way to fix that served all use cases. For now I think I copy the installed cmake modules, sed-fu them, and point projects at that. I'll try to bring it up for discussion with more details soon!