diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a4e9d0..23b5f65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 @@ -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() diff --git a/CMakePresets.json b/CMakePresets.json index 9368829..b95adbf 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -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", diff --git a/cmake/presets/aarch64-linux-gnu.json b/cmake/presets/aarch64-linux-gnu.json new file mode 100644 index 0000000..c1cfb98 --- /dev/null +++ b/cmake/presets/aarch64-linux-gnu.json @@ -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" + } + ] + } + ] +} diff --git a/cmake/presets/aarch64-macos-none.json b/cmake/presets/aarch64-macos-none.json new file mode 100644 index 0000000..3adaeef --- /dev/null +++ b/cmake/presets/aarch64-macos-none.json @@ -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" + } + ] + } + ] +} diff --git a/cmake/presets/x86_64-linux-gnu.json b/cmake/presets/x86_64-linux-gnu.json new file mode 100644 index 0000000..b0c5532 --- /dev/null +++ b/cmake/presets/x86_64-linux-gnu.json @@ -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" + } + ] + } + ] +} diff --git a/cmake/presets/x86_64-linux-musl.json b/cmake/presets/x86_64-linux-musl.json new file mode 100644 index 0000000..c40f2c2 --- /dev/null +++ b/cmake/presets/x86_64-linux-musl.json @@ -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" + } + ] + } + ] +} diff --git a/cmake/presets/x86_64-windows-gnu.json b/cmake/presets/x86_64-windows-gnu.json new file mode 100644 index 0000000..3c42d25 --- /dev/null +++ b/cmake/presets/x86_64-windows-gnu.json @@ -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" + } + ] + } + ] +} diff --git a/cmake/toolchains/aarch64-linux-gnu.cmake b/cmake/toolchains/aarch64-linux-gnu.cmake new file mode 100644 index 0000000..2e4a4c1 --- /dev/null +++ b/cmake/toolchains/aarch64-linux-gnu.cmake @@ -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") diff --git a/cmake/toolchains/aarch64-macos-none.cmake b/cmake/toolchains/aarch64-macos-none.cmake new file mode 100644 index 0000000..5930fa5 --- /dev/null +++ b/cmake/toolchains/aarch64-macos-none.cmake @@ -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") diff --git a/cmake/toolchains/x86_64-linux-gnu.cmake b/cmake/toolchains/x86_64-linux-gnu.cmake new file mode 100644 index 0000000..0829011 --- /dev/null +++ b/cmake/toolchains/x86_64-linux-gnu.cmake @@ -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") diff --git a/cmake/toolchains/x86_64-linux-musl.cmake b/cmake/toolchains/x86_64-linux-musl.cmake new file mode 100644 index 0000000..6ae640d --- /dev/null +++ b/cmake/toolchains/x86_64-linux-musl.cmake @@ -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") diff --git a/cmake/toolchains/x86_64-windows-gnu.cmake b/cmake/toolchains/x86_64-windows-gnu.cmake new file mode 100644 index 0000000..480c2f4 --- /dev/null +++ b/cmake/toolchains/x86_64-windows-gnu.cmake @@ -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") diff --git a/cmake/toolchains/zig-ar.sh b/cmake/toolchains/zig-ar.sh new file mode 100755 index 0000000..3d69448 --- /dev/null +++ b/cmake/toolchains/zig-ar.sh @@ -0,0 +1,2 @@ +#!/bin/sh +zig ar "$@" diff --git a/cmake/toolchains/zig-ranlib.sh b/cmake/toolchains/zig-ranlib.sh new file mode 100755 index 0000000..5caa38e --- /dev/null +++ b/cmake/toolchains/zig-ranlib.sh @@ -0,0 +1,2 @@ +#!/bin/sh +zig ranlib "$@"