mstorsjo / llvm-mingw

An LLVM/Clang/LLD based mingw-w64 toolchain
Other
1.75k stars 176 forks source link

wrappers: add CMake toolchain files #430

Open nolange opened 1 month ago

nolange commented 1 month ago

Those toolchain files greatly simplify configuring a project to use the llvm-mingw toolchain.

The toolchain file will:

CMake has some quite complete and complex machinery to detect further tools and configuration. Whatever supported in your CMake version should "just work" (eg. C++ Modules one day).

The lookup uses the system clang toolchain as fallback, and does not require any of the wrappers / symlinks in bin. ie. Its possible to delete the bin directory if a matching clang/llvm toolchain is installed.

nolange commented 4 weeks ago

still needs some work

nolange commented 4 weeks ago

Had to fix some issues, mostly on windows (needs to convert to native paths) and some quoting.

Something of note is, that CMake does locate matching tools by searching first for the version-qualified name. For example it will look for llvm-ranlib-18 then llvm-ranlib. Means that is available, a system llvm-ranlib-18 will be used. This is not optimal but is unlikely to cause big trouble.

Still, ideally llvm-mingw could provide llvm-ranlib-18, making these lookup schemes more robust.

nolange commented 2 weeks ago

i dropped the support of using a system clang/llvm installation. its pretty hard to get right on windows, i am not even sure if its bc if bugs or if some antivirus/company it policies intervene in my testing.

nolange commented 1 week ago

I added some more stuff in another branch, primary to add some unit tests:
https://github.com/nolange/llvm-mingw/commits/new_toolchainfile/

There is a subdirectory test/cmake/tests building the existing tests. I am probably biased but this should be way cleaner than the Makefile and offers integration with ctest and all the benefits that come with CMake (like just opening the directory in vscode and have everything setup automatically).

And another test/cmake/template which should serve as a basic project that works with llvm, msvc and a series of IDEs (Visual Studio).