| 1 | # Others: Build with CMake |
| 2 | |
| 3 | This document describes how to build Groonga from source with CMake. |
| 4 | |
| 5 | ## Install depended software |
| 6 | |
| 7 | Here is depended software for GNU/Linux, UNIX and Windows. |
| 8 | |
| 9 | ### GNU/Linux or UNIX |
| 10 | |
| 11 | Execute `setup.sh` included in the source code. It exists in the |
| 12 | top directory. |
| 13 | |
| 14 | Example of command execution. |
| 15 | |
| 16 | ```console |
| 17 | $ groonga-*/setup.sh |
| 18 | ``` |
| 19 | |
| 20 | `setup.sh` supports Debian GNU/Linux, Ubuntu, AlmaLinux, and Amazon |
| 21 | Linux 2023. |
| 22 | |
| 23 | #### macOS |
| 24 | |
| 25 | Install [Xcode](https://developer.apple.com/xcode/). |
| 26 | |
| 27 | Execute `setup.sh` included in the source code. It exists in the |
| 28 | top directory. |
| 29 | |
| 30 | Example of command execution. |
| 31 | |
| 32 | ```console |
| 33 | $ groonga-*/setup.sh |
| 34 | ``` |
| 35 | |
| 36 | ### Windows |
| 37 | |
| 38 | Install the followings software: |
| 39 | |
| 40 | - [Microsoft Visual Studio Community](https://visualstudio.microsoft.com/vs/community/) |
| 41 | - [CMake](http://www.cmake.org/) |
| 42 | |
| 43 | ## Download source |
| 44 | |
| 45 | You can download the latest source archive from packages.groonga.org: |
| 46 | https://packages.groonga.org/source/groonga/groonga-latest.tar.gz |
| 47 | |
| 48 | ### GNU/Linux or UNIX |
| 49 | |
| 50 | ```console |
| 51 | $ wget https://packages.groonga.org/source/groonga/groonga-latest.tar.gz |
| 52 | $ tar xvf groonga-latest.tar.gz |
| 53 | ``` |
| 54 | |
| 55 | ### Windows |
| 56 | |
| 57 | You can download the latest zipped source archive from |
| 58 | packages.groonga.org: |
| 59 | https://packages.groonga.org/source/groonga/groonga-latest.zip |
| 60 | |
| 61 | Then extract it. |
| 62 | |
| 63 | (cmake-run)= |
| 64 | |
| 65 | ## Run `cmake` |
| 66 | |
| 67 | You need to generate build files such as `build.ninja` for your |
| 68 | environment. |
| 69 | |
| 70 | You can custom your build configuration by passing options to `cmake`. |
| 71 | |
| 72 | Command example for GNU/Linux or UNIX. |
| 73 | |
| 74 | ```console |
| 75 | $ cmake -S <Groonga source code directory path> -B <Build directory path> --preset=release-maximum |
| 76 | ``` |
| 77 | |
| 78 | - `-S` option |
| 79 | |
| 80 | - Specify the path of the Groonga source code directory |
| 81 | - Specify the directory from which you downloaded and extracted the files |
| 82 | |
| 83 | - `-B` option |
| 84 | - Specify the directory to be used for build |
| 85 | - Specify a build-only directory outside of Groonga's source code directory |
| 86 | |
| 87 | (cmake-presets)= |
| 88 | |
| 89 | ### CMake presets |
| 90 | |
| 91 | Using CMake version 3.21.0 or higher, some presets for various build |
| 92 | configurations are provided. We have provided a combination of |
| 93 | frequently used CMake options, so you can basically use this |
| 94 | presets. Use CMake options only if you want to make custom |
| 95 | settings. You can get a list of the available presets using `cmake |
| 96 | --list-presets` . |
| 97 | |
| 98 | ```console |
| 99 | $ cmake --list-presets |
| 100 | Available configure presets: |
| 101 | |
| 102 | "debug-default" - Optional features may not be enabled (debug build) |
| 103 | "release-default" - Optional features may not be enabled (release build) |
| 104 | "release-with-debug-info-default" - Optional features may not be enabled (release build with debug info) |
| 105 | "debug-maximum" - Enable all features (debug build) |
| 106 | "release-maximum" - Enable all features (release build) |
| 107 | "release-with-debug-info-maximum" - Enable all features (release build with debug info) |
| 108 | "doc" - For documentation |
| 109 | "memory-debug" - For memory debug |
| 110 | "benchmark" - For benchmark |
| 111 | ``` |
| 112 | |
| 113 | (cmake-options)= |
| 114 | |
| 115 | ### CMake options |
| 116 | |
| 117 | This section describes important options of CMake. |
| 118 | |
| 119 | #### `-G GENERATOR` |
| 120 | |
| 121 | Specify a generator. |
| 122 | |
| 123 | The default is depending on the system. |
| 124 | |
| 125 | You can check the default generator and available generators by `cmake |
| 126 | --help`. |
| 127 | |
| 128 | ```console |
| 129 | $ cmake --help |
| 130 | ... |
| 131 | The following generators are available on this platform (* marks default): |
| 132 | Green Hills MULTI = Generates Green Hills MULTI files |
| 133 | (experimental, work-in-progress). |
| 134 | * Unix Makefiles = Generates standard UNIX makefiles. |
| 135 | Ninja = Generates build.ninja files. |
| 136 | Ninja Multi-Config = Generates build-<Config>.ninja files. |
| 137 | Watcom WMake = Generates Watcom WMake makefiles. |
| 138 | CodeBlocks - Ninja = Generates CodeBlocks project files. |
| 139 | CodeBlocks - Unix Makefiles = Generates CodeBlocks project files. |
| 140 | CodeLite - Ninja = Generates CodeLite project files. |
| 141 | CodeLite - Unix Makefiles = Generates CodeLite project files. |
| 142 | Eclipse CDT4 - Ninja = Generates Eclipse CDT 4.0 project files. |
| 143 | Eclipse CDT4 - Unix Makefiles= Generates Eclipse CDT 4.0 project files. |
| 144 | Kate - Ninja = Generates Kate project files. |
| 145 | Kate - Unix Makefiles = Generates Kate project files. |
| 146 | Sublime Text 2 - Ninja = Generates Sublime Text 2 project files. |
| 147 | Sublime Text 2 - Unix Makefiles |
| 148 | ``` |
| 149 | |
| 150 | Here is an example how to specify `Unix Makefiles` on GNU/Linux or UNIX. |
| 151 | |
| 152 | ```console |
| 153 | $ cmake . -G "Unix Makefiles" |
| 154 | ``` |
| 155 | |
| 156 | Here is an example how to specify `Visual Studio 17 2022 x64` as a |
| 157 | generator on Windows. You can specify a target platform name |
| 158 | (architecture) with the `-A` option. |
| 159 | |
| 160 | ```pwsh-session |
| 161 | > cmake . -G "Visual Studio 17 2022" -A x64 |
| 162 | ``` |
| 163 | |
| 164 | #### `-DCMAKE_INSTALL_PREFIX` |
| 165 | |
| 166 | Specify a directory to install Groonga. |
| 167 | |
| 168 | The default is depending on the system, e.g. `/usr/local` or |
| 169 | `C:/Program Files/groonga`. |
| 170 | |
| 171 | Here is an example how to specify `/tmp/local/` as an install |
| 172 | directory on GNU/Linux or UNIX. |
| 173 | |
| 174 | ```console |
| 175 | $ cmake . -DCMAKE_INSTALL_PREFIX="/tmp/local/" |
| 176 | ``` |
| 177 | |
| 178 | Here is an example how to specify `C:\Groonga` as an install directory |
| 179 | on Windows. |
| 180 | |
| 181 | ```pwsh-session |
| 182 | > cmake . -DCMAKE_INSTALL_PREFIX="C:\Groonga" |
| 183 | ``` |
| 184 | |
| 185 | #### `-DGRN_WITH_MRUBY` |
| 186 | |
| 187 | Enables mruby support. |
| 188 | |
| 189 | You can use the {doc}`/reference/sharding` plugin and |
| 190 | {doc}`/reference/commands/ruby_eval` with the mruby support. |
| 191 | |
| 192 | The default is `OFF`. |
| 193 | |
| 194 | Groonga builds bundled mruby if the mruby support is enabled. In order |
| 195 | to build mruby, you must install some required libraries. See the |
| 196 | [mruby compile |
| 197 | guide](https://github.com/mruby/mruby/blob/master/doc/guides/compile.md) |
| 198 | for more details. |
| 199 | |
| 200 | Here is an example how to enable the mruby support. |
| 201 | |
| 202 | ```console |
| 203 | $ cmake . -DGRN_WITH_MRUBY=ON |
| 204 | ``` |
| 205 | |
| 206 | #### `-DGRN_WITH_APACHE_ARROW` |
| 207 | |
| 208 | Enables Apache Arrow support. |
| 209 | |
| 210 | In addition to using Apache Arrow IPC streaming format output, you can |
| 211 | also use multithreading processing that is used in |
| 212 | {ref}`select-n-workers` and |
| 213 | {doc}`/reference/functions/query_parallel_or` with the Apache Arrow |
| 214 | support. |
| 215 | |
| 216 | The default is `OFF`. |
| 217 | |
| 218 | You can install Apache Arrow following to [the official installation |
| 219 | procedure](https://arrow.apache.org/install/). |
| 220 | |
| 221 | Here is an example how to enable the Apache Arrow support. |
| 222 | |
| 223 | ```console |
| 224 | $ cmake . -DGRN_WITH_APACHE_ARROW=ON |
| 225 | ``` |
| 226 | |
| 227 | ```{note} |
| 228 | |
| 229 | If you install Apache Arrow manually, you need to use the |
| 230 | {ref}`cmake-options-cmake-prefix-path` option. |
| 231 | |
| 232 | ``` |
| 233 | |
| 234 | (cmake-options-cmake-prefix-path)= |
| 235 | |
| 236 | #### `-DCMAKE_PREFIX_PATH=PATHS` |
| 237 | |
| 238 | Adds search paths for `.cmake` files. |
| 239 | |
| 240 | You can specify multiple path separating them with `:` on GNU/Linux or |
| 241 | UNIX, `;` on Windows. |
| 242 | |
| 243 | In case of using libraries installed via a package manager, you do not |
| 244 | need to specify this parameter. It is because `.cmake` files for those |
| 245 | libraries are in the default search paths of CMake. |
| 246 | |
| 247 | In case of using libraries installed in non-system directories such as |
| 248 | `/usr`, you need to specify `.cmake` file paths of those libraries by |
| 249 | this parameter. |
| 250 | |
| 251 | Here is an example how to specify a `.cmake` file path for |
| 252 | `/tmp/local/lib/cmake/Arrow/ArrowConfig.cmake` on GNU/Linux or UNIX. |
| 253 | |
| 254 | ```console |
| 255 | $ cmake . -DCMAKE_PREFIX_PATH="/tmp/local" |
| 256 | ``` |
| 257 | |
| 258 | Here is an example how to specify a `.cmake` file path for |
| 259 | `C:\arrow\lib\cmake\Arrow\ArrowConfig.cmake` on Windows. |
| 260 | |
| 261 | ```pwsh-session |
| 262 | > cmake . -DCMAKE_PREFIX_PATH="C:\arrow" |
| 263 | ``` |
| 264 | |
| 265 | (cmake-build-and-install)= |
| 266 | |
| 267 | ## Build and install Groonga |
| 268 | |
| 269 | Now, you can build Groonga. |
| 270 | |
| 271 | ### GNU/Linux or UNIX |
| 272 | |
| 273 | Here is a command line to build and install Groonga. |
| 274 | |
| 275 | ```console |
| 276 | $ cmake --build <Build directory path> |
| 277 | $ sudo cmake --install <Build directory path> |
| 278 | ``` |
| 279 | |
| 280 | ### Windows |
| 281 | |
| 282 | Here is how it is to do it when Visual Studio is specified as the |
| 283 | generator, like `-G "Visual Studio 17 2022"` . |
| 284 | |
| 285 | You can use Visual Studio or `cmake --build`. |
| 286 | |
| 287 | Here is a command line to build and install Groonga by `cmake |
| 288 | --build`. |
| 289 | |
| 290 | ```pwsh-session |
| 291 | > cmake --build . --config Release |
| 292 | > cmake --build . --config Release --target Install |
| 293 | ``` |
| 294 | |
| 295 | You should specify `--config Debug` instead of `--config Release` when |
| 296 | debugging. |