Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add zigcc-based cmake toolchains and presets for cross-compilation #106

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
cmake_minimum_required(VERSION 3.2)
project(fzf LANGUAGES C)

set(ENABLE_TESTING FALSE CACHE BOOL "Build unit tests for this project")

add_library(${PROJECT_NAME} SHARED "src/fzf.c")

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

install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_BINARY_DIR})

if(ENABLE_TESTING)
add_library(examiner examiner/src/examiner.c)
target_include_directories(examiner PUBLIC examiner/src)

add_executable(${PROJECT_NAME}_test test/test.c)
target_link_libraries(${PROJECT_NAME}_test PRIVATE ${PROJECT_NAME} examiner)

include(CTest)
add_test(NAME ${PROJECT_NAME}_test COMMAND ${PROJECT_NAME}_test)
endif()
9 changes: 8 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
{
"version": 1,
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 19,
"patch": 0
},
"include": [
"cmake/presets/x86_64-linux-gnu.json",
"cmake/presets/x86_64-linux-musl.json",
"cmake/presets/aarch64-linux-gnu.json",
"cmake/presets/aarch64-macos-none.json",
"cmake/presets/x86_64-windows-gnu.json"
],
"configurePresets": [
{
"name": "base",
Expand Down
41 changes: 41 additions & 0 deletions cmake/presets/aarch64-linux-gnu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 19,
"patch": 0
},
"configurePresets": [
{
"name": "aarch64-linux-gnu",
"hidden": false,
"binaryDir": "${sourceDir}/build",
"toolchainFile": "cmake/toolchains/aarch64-linux-gnu.cmake",
"cacheVariables": {
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "aarch64-linux-gnu",
"configurePreset": "aarch64-linux-gnu"
}
],
"workflowPresets": [
{
"name": "aarch64-linux-gnu",
"steps": [
{
"type": "configure",
"name": "aarch64-linux-gnu"
},
{
"type": "build",
"name": "aarch64-linux-gnu"
}
]
}
]
}
41 changes: 41 additions & 0 deletions cmake/presets/aarch64-macos-none.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 19,
"patch": 0
},
"configurePresets": [
{
"name": "aarch64-macos-none",
"hidden": false,
"binaryDir": "${sourceDir}/build",
"toolchainFile": "cmake/toolchains/aarch64-macos-none.cmake",
"cacheVariables": {
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "aarch64-macos-none",
"configurePreset": "aarch64-macos-none"
}
],
"workflowPresets": [
{
"name": "aarch64-macos-none",
"steps": [
{
"type": "configure",
"name": "aarch64-macos-none"
},
{
"type": "build",
"name": "aarch64-macos-none"
}
]
}
]
}
41 changes: 41 additions & 0 deletions cmake/presets/x86_64-linux-gnu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 19,
"patch": 0
},
"configurePresets": [
{
"name": "x86_64-linux-gnu",
"hidden": false,
"binaryDir": "${sourceDir}/build",
"toolchainFile": "cmake/toolchains/x86_64-linux-gnu.cmake",
"cacheVariables": {
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "x86_64-linux-gnu",
"configurePreset": "x86_64-linux-gnu"
}
],
"workflowPresets": [
{
"name": "x86_64-linux-gnu",
"steps": [
{
"type": "configure",
"name": "x86_64-linux-gnu"
},
{
"type": "build",
"name": "x86_64-linux-gnu"
}
]
}
]
}
41 changes: 41 additions & 0 deletions cmake/presets/x86_64-linux-musl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 19,
"patch": 0
},
"configurePresets": [
{
"name": "x86_64-linux-musl",
"hidden": false,
"binaryDir": "${sourceDir}/build",
"toolchainFile": "cmake/toolchains/x86_64-linux-musl.cmake",
"cacheVariables": {
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "x86_64-linux-musl",
"configurePreset": "x86_64-linux-musl"
}
],
"workflowPresets": [
{
"name": "x86_64-linux-musl",
"steps": [
{
"type": "configure",
"name": "x86_64-linux-musl"
},
{
"type": "build",
"name": "x86_64-linux-musl"
}
]
}
]
}
41 changes: 41 additions & 0 deletions cmake/presets/x86_64-windows-gnu.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 19,
"patch": 0
},
"configurePresets": [
{
"name": "x86_64-windows-gnu",
"hidden": false,
"binaryDir": "${sourceDir}/build",
"toolchainFile": "cmake/toolchains/x86_64-windows-gnu.cmake",
"cacheVariables": {
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
"CMAKE_BUILD_TYPE": "Release"
}
}
],
"buildPresets": [
{
"name": "x86_64-windows-gnu",
"configurePreset": "x86_64-windows-gnu"
}
],
"workflowPresets": [
{
"name": "x86_64-windows-gnu",
"steps": [
{
"type": "configure",
"name": "x86_64-windows-gnu"
},
{
"type": "build",
"name": "x86_64-windows-gnu"
}
]
}
]
}
9 changes: 9 additions & 0 deletions cmake/toolchains/aarch64-linux-gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "aarch64")

set(CMAKE_C_COMPILER "zig" cc -target aarch64-linux-gnu)
set(CMAKE_CXX_COMPILER "zig" c++ -target aarch64-linux-gnu)

set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar.sh")
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib.sh")
9 changes: 9 additions & 0 deletions cmake/toolchains/aarch64-macos-none.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(CMAKE_SYSTEM_NAME "Darwin")
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "aarch64")

set(CMAKE_C_COMPILER "zig" cc -target aarch64-macos-none)
set(CMAKE_CXX_COMPILER "zig" c++ -target aarch64-macos-none)

set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar.sh")
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib.sh")
9 changes: 9 additions & 0 deletions cmake/toolchains/x86_64-linux-gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

set(CMAKE_C_COMPILER "zig" cc -target x86_64-linux-gnu)
set(CMAKE_CXX_COMPILER "zig" c++ -target x86_64-linux-gnu)

set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar.sh")
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib.sh")
9 changes: 9 additions & 0 deletions cmake/toolchains/x86_64-linux-musl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

set(CMAKE_C_COMPILER "zig" cc -target x86_64-linux-musl)
set(CMAKE_CXX_COMPILER "zig" c++ -target x86_64-linux-musl)

set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar.sh")
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib.sh")
9 changes: 9 additions & 0 deletions cmake/toolchains/x86_64-windows-gnu.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
set(CMAKE_SYSTEM_NAME "Windows")
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "x86_64")

set(CMAKE_C_COMPILER "zig" cc -target x86_64-windows-gnu)
set(CMAKE_CXX_COMPILER "zig" c++ -target x86_64-windows-gnu)

set(CMAKE_AR "${CMAKE_CURRENT_LIST_DIR}/zig-ar.sh")
set(CMAKE_RANLIB "${CMAKE_CURRENT_LIST_DIR}/zig-ranlib.sh")
2 changes: 2 additions & 0 deletions cmake/toolchains/zig-ar.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
zig ar "$@"
2 changes: 2 additions & 0 deletions cmake/toolchains/zig-ranlib.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
zig ranlib "$@"