https://github.com/widberg/cmake-toolchain-example
A simple example of how to use CMake's toolchain functionality to build and use Clang for a Windows target from a foreign host.
https://github.com/widberg/cmake-toolchain-example
Last synced: 3 months ago
JSON representation
A simple example of how to use CMake's toolchain functionality to build and use Clang for a Windows target from a foreign host.
- Host: GitHub
- URL: https://github.com/widberg/cmake-toolchain-example
- Owner: widberg
- Created: 2022-07-04T19:41:25.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-07-05T00:08:33.000Z (almost 4 years ago)
- Last Synced: 2025-10-26T23:41:33.959Z (8 months ago)
- Language: CMake
- Size: 2.93 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# CMake Toolchain Example
This repository is a simple example of how to use CMake's toolchain functionality to build and use Clang for a Windows target from a foreign host.
For a more complex example that is still easy to understand check out [SerenityOS](https://github.com/SerenityOS/serenity/tree/master/Toolchain).
Note: Using the Visual Studio generator will not work since it [silently ignores the toolchain file settings for CMAKE_C_COMPILER and CMAKE_CXX_COMPILER](https://gitlab.kitware.com/cmake/cmake/-/issues/23385). I recommend using the Ninja generator.
## Getting Started
### Checkout
```sh
git clone https://github.com/widberg/cmake-toolchain-example.git --recursive --shallow-submodules
cd cmake-toolchain-example
```
### Build
You need to re-configure the build from scratch when the toolchain file changes.
```sh
mkdir build
cd build
cmake .. -GNinja
cmake --build .
```
### Run
```sh
D:\cmake-toolchain-example\build>example.exe
Hello, World! (14.0.6 (https://github.com/llvm/llvm-project.git f28c006a5895fc0e329fe15fead81e37457cb1d1))
```
You can see that regardless of which compiler was initially used on the foreign host, the built Clang toolchain was used to compile the executable for Windows.