Skip to content

Commit 0184e26

Browse files
committed
Reorganize toolchain files
1 parent 21be12c commit 0184e26

15 files changed

+23834
-15
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ Reference: https://zig.news/kristoff/cross-compile-a-c-c-project-with-zig-3599
77
## Building
88

99
- [Install zig](https://ziglang.org/learn/getting-started/#installing-zig) in your PATH (`choco install zig` on Windows)
10-
- `cmake -B build-aarch64 -G Ninja -DCMAKE_TOOLCHAIN_FILE=cmake/zig-toolchain-aarch64.cmake`
10+
- `cmake -B build-aarch64 -G Ninja --toolchain aarch64-linux-gnu.cmake`
1111
- `cmake --build build-arch64`
1212

13-
You can create toolchains for other triples like this. Here is an example to build for Windows on ARM64:
13+
You can create toolchains for other triples as well, just create a file named `aarch64-windows-gnu.cmake` with the following contents to build for Windows on ARM64:
1414

1515
```cmake
16-
set(ZIG_TARGET "aarch64-windows-gnu")
17-
include(${CMAKE_CURRENT_LIST_DIR}/zig-toolchain.cmake)
16+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/zig-toolchain.cmake)
1817
```
1918

2019
## clangd

aarch64-linux-gnu.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/zig-toolchain.cmake)

aarch64-windows-gnu.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/zig-toolchain.cmake)

cmake/zig-toolchain-aarch64.cmake

Lines changed: 0 additions & 2 deletions
This file was deleted.

cmake/zig-toolchain-riscv64.cmake

Lines changed: 0 additions & 2 deletions
This file was deleted.

cmake/zig-toolchain-uefi64.cmake

Lines changed: 0 additions & 2 deletions
This file was deleted.

cmake/zig-toolchain-win64.cmake

Lines changed: 0 additions & 2 deletions
This file was deleted.

cmake/zig-toolchain-winarm64.cmake

Lines changed: 0 additions & 2 deletions
This file was deleted.

cmake/zig-toolchain.cmake

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ if(CMAKE_GENERATOR MATCHES "Visual Studio")
44
message(FATAL_ERROR "Visual Studio generator not supported, use: cmake -G Ninja")
55
endif()
66

7+
if(NOT DEFINED ZIG_TARGET)
8+
get_filename_component(PARENT_LIST_DIR "${CMAKE_PARENT_LIST_FILE}" DIRECTORY)
9+
string(FIND "${CMAKE_CURRENT_LIST_DIR}" "${PARENT_LIST_DIR}" POS)
10+
if(POS EQUAL 0)
11+
get_filename_component(ZIG_TARGET "${CMAKE_PARENT_LIST_FILE}" NAME_WE)
12+
endif()
13+
endif()
14+
715
if(NOT ZIG_TARGET MATCHES "^([a-zZ-Z0-9_]+)-([a-zZ-Z0-9_]+)-([a-zZ-Z0-9_]+)$")
8-
message(FATAL_ERROR "Expected -DZIG_TARGET=<arch>-<os>-<abi>")
16+
message(FATAL_ERROR "Expected ZIG_TARGET=<arch>-<os>-<abi>")
917
endif()
1018

1119
set(ZIG_ARCH ${CMAKE_MATCH_1})

riscv64-freestanding-none.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/zig-toolchain.cmake)

x86_64-linux-gnu.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/zig-toolchain.cmake)

x86_64-linux-musl.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/zig-toolchain.cmake)

x86_64-uefi-gnu.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/zig-toolchain.cmake)

x86_64-windows-gnu.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include(${CMAKE_CURRENT_LIST_DIR}/cmake/zig-toolchain.cmake)

0 commit comments

Comments
 (0)