# CMake: Improve usage of \`llvm-config\`, esp\. for consistent linking · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/3f640ef3d20db848a4d38299cb66db8a3c14b3b1)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 3f640ef3d20db848a4d38299cb66db8a3c14b3b1

Requested commit: 3f640ef3d20db848a4d38299cb66db8a3c14b3b1

Commit: 3f640ef3d20db848a4d38299cb66db8a3c14b3b1

Tree: 609b61c97b9a96a8dbcf7160cb73513c497d8b76

Author: Cody Tapscott

Committer: Cody Tapscott

## Message

```
CMake: Improve usage of `llvm-config`, esp. for consistent linking

This commit reworks the LLVM/Clang/LLD discovery process for CMake. The
biggest changes are that:
  1. We search for LLVM from most preferred directory to least, skipping
     any `llvm-config` that is the wrong version, or that doesn't
     support the requested link mode ("static" or "shared").
  2. `ZIG_PREFER_CLANG_CPP_DYLIB` has been renamed to `ZIG_SHARED_LLVM`,
     to better align with `ZIG_STATIC_LLVM`.
  3. We only search for LLVM in the same directory alongside LLVM.
  4. LLVM's link mode is forwarded to Clang, so that we can look for the
     appropriate shared/static libraries.
  5. We use `--link-static` when querying `--system-libs` from llvm-config,
     so that this will include libz and other dependencies for
     statically linking LLD

```

## Parents

- [460211431f407c9f707e3ac3bbff61610a487926](https://git.cafe/gitcafe/zig/commit/460211431f407c9f707e3ac3bbff61610a487926?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/3f640ef3d20db848a4d38299cb66db8a3c14b3b1?format=markdown)
