rename A_VERSION_{C,EX} to A_VERSION_{0,1,2,3,4}
[liba.git] / README.md
blob4b7ea63979b051520abf3c9aa955653a9fb32977
1 # An algorithm library {#mainpage}
3 [![docs](https://github.com/tqfx/liba/actions/workflows/docs.yml/badge.svg)](https://github.com/tqfx/liba/actions/workflows/docs.yml)
4 [![conan](https://github.com/tqfx/liba/actions/workflows/conan.yml/badge.svg)](https://github.com/tqfx/liba/actions/workflows/conan.yml)
5 [![xmake](https://github.com/tqfx/liba/actions/workflows/xmake.yml/badge.svg)](https://github.com/tqfx/liba/actions/workflows/xmake.yml)
6 [![meson](https://github.com/tqfx/liba/actions/workflows/meson.yml/badge.svg)](https://github.com/tqfx/liba/actions/workflows/meson.yml)
7 [![wasm](https://github.com/tqfx/liba/actions/workflows/wasm.yml/badge.svg)](https://github.com/tqfx/liba/actions/workflows/wasm.yml)
8 [![msvc](https://github.com/tqfx/liba/actions/workflows/msvc.yml/badge.svg)](https://github.com/tqfx/liba/actions/workflows/msvc.yml)
9 [![linux](https://github.com/tqfx/liba/actions/workflows/linux.yml/badge.svg)](https://github.com/tqfx/liba/actions/workflows/linux.yml)
10 [![macos](https://github.com/tqfx/liba/actions/workflows/macos.yml/badge.svg)](https://github.com/tqfx/liba/actions/workflows/macos.yml)
11 [![mingw](https://github.com/tqfx/liba/actions/workflows/mingw.yml/badge.svg)](https://github.com/tqfx/liba/actions/workflows/mingw.yml)
12 [![msys2](https://github.com/tqfx/liba/actions/workflows/msys2.yml/badge.svg)](https://github.com/tqfx/liba/actions/workflows/msys2.yml)
13 [![freebsd](https://github.com/tqfx/liba/actions/workflows/freebsd.yml/badge.svg)](https://github.com/tqfx/liba/actions/workflows/freebsd.yml)
15 ## documentation
17 - [C/C++](https://tqfx.org/liba/)
18 - [Lua](https://tqfx.org/liba/lua/)
19 - [Java](https://tqfx.org/liba/java/)
20 - [Rust](https://tqfx.org/liba/rust/liba/)
22 ## required tools
24 - C/C++ compiler: [tcc](https://bellard.org/tcc) or [gnu](https://gcc.gnu.org) or [llvm](https://clang.llvm.org) or [msvc](https://visualstudio.microsoft.com/visual-cpp-build-tools) etc
26 ## optional tools
28 - [lua](https://www.lua.org)
29 - [java](https://www.oracle.com/java)
30 - [rust](https://www.rust-lang.org)
31 - [emsdk](https://emscripten.org)
32 - [xmake](https://xmake.io)
33 - [cmake](https://cmake.org)
34 - [conan](https://conan.io)
35 - [vcpkg](https://vcpkg.io)
36 - [meson](https://mesonbuild.com)
37 - [python](https://www.python.org)
38 - [quickjs](https://github.com/bellard/quickjs)
40 ## build
42 ### xmake
44 ```bash
45 xmake f
46 xmake
47 xmake i
48 ```
50 ### cmake
52 ```bash
53 cmake -S . -B build
54 cmake --build build
55 cmake --install build
56 ```
58 ### meson
60 ```bash
61 meson setup build
62 meson install -C build
63 ```
65 ### vcpkg
67 ```bash
68 cmake -S . -B build -DLIBA_VCPKG=1
69 ```
71 ```bash
72 cp -r build/vcpkg/* $VCPKG_INSTALLATION_ROOT
73 ```
75 ```pwsh
76 cp -r -Force build/vcpkg/* $ENV:VCPKG_INSTALLATION_ROOT
77 ```
79 ### conan
81 ```bash
82 conan create .
83 ```
85 ### cargo
87 ```bash
88 cargo build --release
89 ```
91 ### cython
93 ```bash
94 python setup.py build_ext --inplace
95 ```
97 ## usage
99 ### C/C++
101 #### xmake.lua
103 ```lua
104 add_requires("alib") -- static
105 add_requires("liba") -- shared
108 #### CMakeLists.txt
110 ```cmake
111 find_package(liba CONFIG REQUIRED)
112 target_link_libraries(<TARGET> PRIVATE alib) # static
113 target_link_libraries(<TARGET> PRIVATE liba) # shared
116 #### conanfile.txt
118 ```txt
119 [requires]
120 liba/[~0.1]
123 ### Lua
125 ```bash
126 luarocks install liba # release
129 ```bash
130 luarocks install liba --dev # latest
133 #### main.lua
135 ```lua
136 local liba = require("liba")
137 print("version", liba.VERSION)
140 ### Java
142 #### Main.java
144 ```java
145 public class Main {
146     public static void main(String[] args) {
147         System.out.println("version " + liba.VERSION);
148     }
152 ### Rust
154 #### Cargo.toml
156 ```bash
157 cargo add liba # release
160 ```bash
161 cargo add --git https://github.com/tqfx/liba.git # latest
164 #### main.rs
166 ```rs
167 use liba;
168 fn main() {
169     println!(
170         "version {}.{}.{}+{}",
171         liba::version::major(),
172         liba::version::minor(),
173         liba::version::patch(),
174         liba::version::tweak()
175     );
179 ### Python
181 ```bash
182 export LIBA_OPENMP=1
183 pip install liba # release
186 ```bash
187 pip install git+https://github.com/tqfx/liba.git # latest
190 #### main.py
192 ```py
193 import liba
194 print("version", liba.VERSION)
197 ### JavaScript
199 ```bash
200 npm i @tqfx/liba
203 #### index.js
205 ```js
206 import liba from "@tqfx/liba";
207 console.log("version", liba.VERSION);
210 ### QuickJS
212 #### main.js
214 ```js
215 import * as liba from "liba.so";
216 console.log("version", liba.VERSION);
219 ## Copyright {#copyright}
221 Copyright (C) 2020-present tqfx, All rights reserved.
223 This Source Code Form is subject to the terms of the Mozilla Public
224 License, v. 2.0. If a copy of the MPL was not distributed with this
225 file, You can obtain one at <https://mozilla.org/MPL/2.0/>.