Skip to content

Commit 411d5fc

Browse files
committed
add cmake toolchains for cross-compilation
1 parent 9bc8237 commit 411d5fc

14 files changed

+275
-1
lines changed

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
cmake_minimum_required(VERSION 3.2)
22
project(fzf LANGUAGES C)
33

4+
set(ENABLE_TESTING FALSE CACHE BOOL "Build unit tests for this project")
5+
46
add_library(${PROJECT_NAME} SHARED "src/fzf.c")
57

68
target_include_directories(${PROJECT_NAME} PUBLIC
@@ -26,3 +28,14 @@ if (NOT CMAKE_SYSTEM_NAME STREQUAL "Windows")
2628
endif()
2729

2830
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_BINARY_DIR})
31+
32+
if(ENABLE_TESTING)
33+
add_library(examiner examiner/src/examiner.c)
34+
target_include_directories(examiner PUBLIC examiner/src)
35+
36+
add_executable(${PROJECT_NAME}_test test/test.c)
37+
target_link_libraries(${PROJECT_NAME}_test PRIVATE ${PROJECT_NAME} examiner)
38+
39+
include(CTest)
40+
add_test(NAME ${PROJECT_NAME}_test COMMAND ${PROJECT_NAME}_test)
41+
endif()

CMakePresets.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
{
2-
"version": 1,
2+
"version": 6,
33
"cmakeMinimumRequired": {
44
"major": 3,
55
"minor": 19,
66
"patch": 0
77
},
8+
"include": [
9+
"cmake/presets/x86_64-linux-gnu.json",
10+
"cmake/presets/x86_64-linux-musl.json",
11+
"cmake/presets/aarch64-linux-gnu.json",
12+
"cmake/presets/aarch64-macos-none.json",
13+
"cmake/presets/x86_64-windows-gnu.json"
14+
],
815
"configurePresets": [
916
{
1017
"name": "base",
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 19,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "aarch64-linux-gnu",
11+
"hidden": false,
12+
"binaryDir": "${sourceDir}/build",
13+
"toolchainFile": "cmake/toolchains/aarch64-linux-gnu.cmake",
14+
"cacheVariables": {
15+
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
16+
"CMAKE_BUILD_TYPE": "Release"
17+
}
18+
}
19+
],
20+
"buildPresets": [
21+
{
22+
"name": "aarch64-linux-gnu",
23+
"configurePreset": "aarch64-linux-gnu"
24+
}
25+
],
26+
"workflowPresets": [
27+
{
28+
"name": "aarch64-linux-gnu",
29+
"steps": [
30+
{
31+
"type": "configure",
32+
"name": "aarch64-linux-gnu"
33+
},
34+
{
35+
"type": "build",
36+
"name": "aarch64-linux-gnu"
37+
}
38+
]
39+
}
40+
]
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 19,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "aarch64-macos-none",
11+
"hidden": false,
12+
"binaryDir": "${sourceDir}/build",
13+
"toolchainFile": "cmake/toolchains/aarch64-macos-none.cmake",
14+
"cacheVariables": {
15+
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
16+
"CMAKE_BUILD_TYPE": "Release"
17+
}
18+
}
19+
],
20+
"buildPresets": [
21+
{
22+
"name": "aarch64-macos-none",
23+
"configurePreset": "aarch64-macos-none"
24+
}
25+
],
26+
"workflowPresets": [
27+
{
28+
"name": "aarch64-macos-none",
29+
"steps": [
30+
{
31+
"type": "configure",
32+
"name": "aarch64-macos-none"
33+
},
34+
{
35+
"type": "build",
36+
"name": "aarch64-macos-none"
37+
}
38+
]
39+
}
40+
]
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 19,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "x86_64-linux-gnu",
11+
"hidden": false,
12+
"binaryDir": "${sourceDir}/build",
13+
"toolchainFile": "cmake/toolchains/x86_64-linux-gnu.cmake",
14+
"cacheVariables": {
15+
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
16+
"CMAKE_BUILD_TYPE": "Release"
17+
}
18+
}
19+
],
20+
"buildPresets": [
21+
{
22+
"name": "x86_64-linux-gnu",
23+
"configurePreset": "x86_64-linux-gnu"
24+
}
25+
],
26+
"workflowPresets": [
27+
{
28+
"name": "x86_64-linux-gnu",
29+
"steps": [
30+
{
31+
"type": "configure",
32+
"name": "x86_64-linux-gnu"
33+
},
34+
{
35+
"type": "build",
36+
"name": "x86_64-linux-gnu"
37+
}
38+
]
39+
}
40+
]
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 19,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "x86_64-linux-musl",
11+
"hidden": false,
12+
"binaryDir": "${sourceDir}/build",
13+
"toolchainFile": "cmake/toolchains/x86_64-linux-musl.cmake",
14+
"cacheVariables": {
15+
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
16+
"CMAKE_BUILD_TYPE": "Release"
17+
}
18+
}
19+
],
20+
"buildPresets": [
21+
{
22+
"name": "x86_64-linux-musl",
23+
"configurePreset": "x86_64-linux-musl"
24+
}
25+
],
26+
"workflowPresets": [
27+
{
28+
"name": "x86_64-linux-musl",
29+
"steps": [
30+
{
31+
"type": "configure",
32+
"name": "x86_64-linux-musl"
33+
},
34+
{
35+
"type": "build",
36+
"name": "x86_64-linux-musl"
37+
}
38+
]
39+
}
40+
]
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": 6,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 19,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "x86_64-windows-gnu",
11+
"hidden": false,
12+
"binaryDir": "${sourceDir}/build",
13+
"toolchainFile": "cmake/toolchains/x86_64-windows-gnu.cmake",
14+
"cacheVariables": {
15+
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
16+
"CMAKE_BUILD_TYPE": "Release"
17+
}
18+
}
19+
],
20+
"buildPresets": [
21+
{
22+
"name": "x86_64-windows-gnu",
23+
"configurePreset": "x86_64-windows-gnu"
24+
}
25+
],
26+
"workflowPresets": [
27+
{
28+
"name": "x86_64-windows-gnu",
29+
"steps": [
30+
{
31+
"type": "configure",
32+
"name": "x86_64-windows-gnu"
33+
},
34+
{
35+
"type": "build",
36+
"name": "x86_64-windows-gnu"
37+
}
38+
]
39+
}
40+
]
41+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(CMAKE_SYSTEM_NAME "Linux")
2+
set(CMAKE_SYSTEM_VERSION 1)
3+
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
4+
5+
set(CMAKE_C_COMPILER "zig" cc -target aarch64-linux-gnu)
6+
set(CMAKE_CXX_COMPILER "zig" c++ -target aarch64-linux-gnu)
7+
8+
set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar.sh")
9+
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib.sh")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(CMAKE_SYSTEM_NAME "Darwin")
2+
set(CMAKE_SYSTEM_VERSION 1)
3+
set(CMAKE_SYSTEM_PROCESSOR "aarch64")
4+
5+
set(CMAKE_C_COMPILER "zig" cc -target aarch64-macos-none)
6+
set(CMAKE_CXX_COMPILER "zig" c++ -target aarch64-macos-none)
7+
8+
set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar.sh")
9+
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib.sh")
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
set(CMAKE_SYSTEM_NAME "Linux")
2+
set(CMAKE_SYSTEM_VERSION 1)
3+
set(CMAKE_SYSTEM_PROCESSOR "x86_64")
4+
5+
set(CMAKE_C_COMPILER "zig" cc -target x86_64-linux-gnu)
6+
set(CMAKE_CXX_COMPILER "zig" c++ -target x86_64-linux-gnu)
7+
8+
set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar.sh")
9+
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib.sh")

0 commit comments

Comments
 (0)