
With this commit, users are able to build valkey using `CMake`. ## Example usage: Build `valkey-server` in Release mode with TLS enabled and using `jemalloc` as the allocator: ```bash mkdir build-release cd $_ cmake .. -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/tmp/valkey-install \ -DBUILD_MALLOC=jemalloc -DBUILD_TLS=1 make -j$(nproc) install # start valkey /tmp/valkey-install/bin/valkey-server ``` Build `valkey-unit-tests`: ```bash mkdir build-release-ut cd $_ cmake .. -DCMAKE_BUILD_TYPE=Release \ -DBUILD_MALLOC=jemalloc -DBUILD_UNIT_TESTS=1 make -j$(nproc) # Run the tests ./bin/valkey-unit-tests ``` Current features supported by this PR: - Building against different allocators: (`jemalloc`, `tcmalloc`, `tcmalloc_minimal` and `libc`), e.g. to enable `jemalloc` pass `-DBUILD_MALLOC=jemalloc` to `cmake` - OpenSSL builds (to enable TLS, pass `-DBUILD_TLS=1` to `cmake`) - Sanitizier: pass `-DBUILD_SANITIZER=<address|thread|undefined>` to `cmake` - Install target + redis symbolic links - Build `valkey-unit-tests` executable - Standard CMake variables are supported. e.g. to install `valkey` under `/home/you/root` pass `-DCMAKE_INSTALL_PREFIX=/home/you/root` Why using `CMake`? To list *some* of the advantages of using `CMake`: - Superior IDE integrations: cmake generates the file `compile_commands.json` which is required by `clangd` to get a compiler accuracy code completion (in other words: your VScode will thank you) - Out of the source build tree: with the current build system, object files are created all over the place polluting the build source tree, the best practice is to build the project on a separate folder - Multiple build types co-existing: with the current build system, it is often hard to have multiple build configurations. With cmake you can do it easily: - It is the de-facto standard for C/C++ project these days More build examples: ASAN build: ```bash mkdir build-asan cd $_ cmake .. -DBUILD_SANITIZER=address -DBUILD_MALLOC=libc make -j$(nproc) ``` ASAN with jemalloc: ```bash mkdir build-asan-jemalloc cd $_ cmake .. -DBUILD_SANITIZER=address -DBUILD_MALLOC=jemalloc make -j$(nproc) ``` As seen by the previous examples, any combination is allowed and co-exist on the same source tree. ## Valkey installation With this new `CMake`, it is possible to install the binary by running `make install` or creating a package `make package` (currently supported on Debian like distros) ### Example 1: build & install using `make install`: ```bash mkdir build-release cd $_ cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/valkey-install -DCMAKE_BUILD_TYPE=Release make -j$(nproc) install # valkey is now installed under $HOME/valkey-install ``` ### Example 2: create a `.deb` installer: ```bash mkdir build-release cd $_ cmake .. -DCMAKE_BUILD_TYPE=Release make -j$(nproc) package # ... CPack deb generation output sudo gdebi -n ./valkey_8.1.0_amd64.deb # valkey is now installed under /opt/valkey ``` ### Example 3: create installer for non Debian systems (e.g. FreeBSD or macOS): ```bash mkdir build-release cd $_ cmake .. -DCMAKE_BUILD_TYPE=Release make -j$(nproc) package mkdir -p /opt/valkey && ./valkey-8.1.0-Darwin.sh --prefix=/opt/valkey --exclude-subdir # valkey-server is now installed under /opt/valkey ``` Signed-off-by: Eran Ifrah <eifrah@amazon.com>
45 lines
1.2 KiB
CMake
45 lines
1.2 KiB
CMake
project(lualib)
|
|
|
|
set(LUA_SRC_DIR "${CMAKE_CURRENT_LIST_DIR}/src")
|
|
set(LUA_SRCS
|
|
${LUA_SRC_DIR}/fpconv.c
|
|
${LUA_SRC_DIR}/lbaselib.c
|
|
${LUA_SRC_DIR}/lmathlib.c
|
|
${LUA_SRC_DIR}/lstring.c
|
|
${LUA_SRC_DIR}/lparser.c
|
|
${LUA_SRC_DIR}/ldo.c
|
|
${LUA_SRC_DIR}/lzio.c
|
|
${LUA_SRC_DIR}/lmem.c
|
|
${LUA_SRC_DIR}/strbuf.c
|
|
${LUA_SRC_DIR}/lstrlib.c
|
|
${LUA_SRC_DIR}/lundump.c
|
|
${LUA_SRC_DIR}/lua_cmsgpack.c
|
|
${LUA_SRC_DIR}/loslib.c
|
|
${LUA_SRC_DIR}/lua_struct.c
|
|
${LUA_SRC_DIR}/ldebug.c
|
|
${LUA_SRC_DIR}/lobject.c
|
|
${LUA_SRC_DIR}/ldump.c
|
|
${LUA_SRC_DIR}/lua_cjson.c
|
|
${LUA_SRC_DIR}/ldblib.c
|
|
${LUA_SRC_DIR}/ltm.c
|
|
${LUA_SRC_DIR}/ltable.c
|
|
${LUA_SRC_DIR}/lstate.c
|
|
${LUA_SRC_DIR}/lua_bit.c
|
|
${LUA_SRC_DIR}/lua.c
|
|
${LUA_SRC_DIR}/loadlib.c
|
|
${LUA_SRC_DIR}/lcode.c
|
|
${LUA_SRC_DIR}/lapi.c
|
|
${LUA_SRC_DIR}/lgc.c
|
|
${LUA_SRC_DIR}/lvm.c
|
|
${LUA_SRC_DIR}/lfunc.c
|
|
${LUA_SRC_DIR}/lauxlib.c
|
|
${LUA_SRC_DIR}/ltablib.c
|
|
${LUA_SRC_DIR}/linit.c
|
|
${LUA_SRC_DIR}/lopcodes.c
|
|
${LUA_SRC_DIR}/llex.c
|
|
${LUA_SRC_DIR}/liolib.c)
|
|
|
|
add_library(lualib STATIC "${LUA_SRCS}")
|
|
target_include_directories(lualib PUBLIC "${LUA_SRC_DIR}")
|
|
target_compile_definitions(lualib PRIVATE ENABLE_CJSON_GLOBAL)
|