This patch consists of two relatively independent changes:
- first, I teach the standalone build to detect the case when llvm was built in the shared mode and set the appropriate cmake variables to make the add_llvm_*** family of functions link against the shared library. Without these, the we would end up linking against the constituent .a files while other parts of the build (e.g. clang) would pull in the libllvm.so, which resulted in multiply defined symbols.
- second, I add detection code for pthread and dl libraries. This is necessary, because we have direct calls to these libraries (instead of going through llvm) and in the standalone build we cannot rely on llvm to detect these for us. In a standalone non-dylib build this was accidentaly working because these libraries were pulled in as an interface dependency of the .a files, but in a dylib build these are no longer part of the link interface, and so we need to add them explicitly.
Why UNIX here?
Why CMAKE_THREAD_PREFER_PTHREAD? It looks like used only on IRIX and that one is not going anywhere nowadays. (And certainly similarly to other commercial OSes, due to legal work/removing not-owned code, it's not possible to push it to Open-Source).
Assuming that system_libs can accept "-pthreads", this patch looks good to me.