Skip to content

Commit 9d079d3

Browse files
committed
Restructure README
1 parent 054b2df commit 9d079d3

File tree

2 files changed

+266
-386
lines changed

2 files changed

+266
-386
lines changed

BUILDING.md

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
# Building the library
2+
3+
cglm can be built using one of the following build systems:
4+
5+
## CMake (All platforms)
6+
```bash
7+
$ mkdir build
8+
$ cd build
9+
$ cmake .. # [Optional] -DCGLM_SHARED=ON
10+
$ make
11+
$ sudo make install # [Optional]
12+
```
13+
14+
### Options with defaults
15+
16+
```CMake
17+
option(CGLM_SHARED "Shared build" ON)
18+
option(CGLM_STATIC "Static build" OFF)
19+
option(CGLM_USE_C99 "" OFF) # C11
20+
option(CGLM_USE_TEST "Enable Tests" OFF) # for make check - make test
21+
```
22+
23+
### Including in a CMake project
24+
25+
#### Header only
26+
27+
This requires no building or installation of cglm.
28+
29+
* Example:
30+
31+
``` cmake
32+
cmake_minimum_required(VERSION 3.8.2)
33+
34+
project(<Your Project Name>)
35+
36+
add_executable(${PROJECT_NAME} src/main.c)
37+
target_link_libraries(${LIBRARY_NAME} PRIVATE
38+
cglm_headers)
39+
40+
add_subdirectory(external/cglm/ EXCLUDE_FROM_ALL)
41+
```
42+
43+
#### Linked
44+
45+
* Example:
46+
```cmake
47+
cmake_minimum_required(VERSION 3.8.2)
48+
49+
project(<Your Project Name>)
50+
51+
add_executable(${PROJECT_NAME} src/main.c)
52+
target_link_libraries(${LIBRARY_NAME} PRIVATE
53+
cglm)
54+
55+
add_subdirectory(external/cglm/)
56+
57+
# or you can use find_package to configure cglm
58+
```
59+
60+
### Using CMake to build for WebAssembly
61+
62+
Since math functions like `sinf` are used, this can not be targeted at `wasm32-unknown-unknown`, one of [wasi-sdk](https://github.com/WebAssembly/wasi-sdk) or [emscripten](https://github.com/emscripten-core/emsdk) should be used.
63+
64+
Should note that shared build is not yet supported for WebAssembly.
65+
66+
For [simd128](https://github.com/WebAssembly/simd) support, add `-msimd128` to `CMAKE_C_FLAGS`, in command line `-DCMAKE_C_FLAGS="-msimd128"`.
67+
68+
For tests, the cmake option `CGLM_USE_TEST` would still work, you'll need a wasi runtime for running tests, see our [ci config file](.github/workflows/cmake-wasm.yml) for a detailed example.
69+
70+
#### WASI SDK
71+
72+
```bash
73+
$ cmake .. \
74+
-DCMAKE_TOOLCHAIN_FILE=/path/to/wasi-sdk-19.0/share/cmake/wasi-sdk.cmake \
75+
-DWASI_SDK_PREFIX=/path/to/wasi-sdk-19.0
76+
```
77+
78+
Where `/path/to/wasi-sdk-19.0/` is the path to extracted [wasi sdk](https://github.com/WebAssembly/wasi-sdk).
79+
80+
In this case it would by default make a static build.
81+
82+
#### Emscripten
83+
84+
```bash
85+
$ emcmake cmake .. \
86+
-DCMAKE_EXE_LINKER_FLAGS="-s STANDALONE_WASM" \
87+
-DCGLM_STATIC=ON
88+
```
89+
90+
The `emcmake` here is the cmake wrapper for Emscripten from installed [emsdk](https://github.com/emscripten-core/emsdk).
91+
92+
## Meson (All platforms)
93+
94+
```bash
95+
$ meson build # [Optional] --default-library=static
96+
$ cd build
97+
$ ninja
98+
$ sudo ninja install # [Optional]
99+
```
100+
101+
### Options with Defaults:
102+
103+
```meson
104+
c_std=c11
105+
buildtype=release
106+
default_library=shared
107+
build_tests=true # to run tests: ninja test
108+
```
109+
### Including in a Meson project
110+
* Example:
111+
```meson
112+
# Clone cglm or create a cglm.wrap under <source_root>/subprojects
113+
project('name', 'c')
114+
115+
cglm_dep = dependency('cglm', fallback : 'cglm', 'cglm_dep')
116+
117+
executable('exe', 'src/main.c', dependencies : cglm_dep)
118+
```
119+
120+
## Swift (Swift Package Manager)
121+
122+
Currently only default build options are supported. Add **cglm** dependency to your project:
123+
124+
```swift
125+
...
126+
Package(
127+
...
128+
dependencies: [
129+
...
130+
.package(url: "https://github.com/recp/cglm", .branch("master")),
131+
]
132+
...
133+
)
134+
```
135+
136+
Now add **cgml** as a dependency to your target. Product choices are:
137+
- **cglm** for inlined version of the library which can be linked only statically
138+
- **cglmc** for a compiled version of the library with no linking limitation
139+
140+
```swift
141+
...
142+
.target(
143+
...
144+
dependencies: [
145+
...
146+
.product(name: "cglm", package: "cglm"),
147+
]
148+
...
149+
)
150+
...
151+
```
152+
153+
## Unix (Autotools)
154+
155+
```bash
156+
$ sh autogen.sh
157+
$ ./configure
158+
$ make
159+
$ make check # [Optional]
160+
$ [sudo] make install # [Optional]
161+
```
162+
163+
This will also install pkg-config files so you can use
164+
`pkg-config --cflags cglm` and `pkg-config --libs cglm` to retrieve compiler
165+
and linker flags.
166+
167+
The files will be installed into the given prefix (usually `/usr/local` by
168+
default on Linux), but your pkg-config may not be configured to actually check
169+
there. You can figure out where it's looking by running `pkg-config --variable
170+
pc_path pkg-config` and change the path the files are installed to via
171+
`./configure --with-pkgconfigdir=/your/path`. Alternatively, you can add the
172+
prefix path to your `PKG_CONFIG_PATH` environment variable.
173+
174+
## Windows (MSBuild)
175+
Windows related build file and project files are located in `win` folder,
176+
make sure you are inside `cglm/win` folder.
177+
Code Analysis is enabled, so it may take awhile to build.
178+
179+
```Powershell
180+
$ cd win
181+
$ .\build.bat
182+
```
183+
if `msbuild` won't work (because of multi version VS) then try to build with `devenv`:
184+
```Powershell
185+
$ devenv cglm.sln /Build Release
186+
```
187+
188+
### Running Tests on Windows
189+
190+
You can see test project in same visual studio solution file. It is enough to run that project to run tests.
191+
192+
# Building the documentation
193+
First you need install Sphinx: http://www.sphinx-doc.org/en/master/usage/installation.html
194+
then:
195+
```bash
196+
$ cd docs
197+
$ sphinx-build source build
198+
```
199+
it will compile docs into build folder, you can run index.html inside that function.

0 commit comments

Comments
 (0)