nicolasff / webdis

A Redis HTTP interface with JSON output
https://webd.is
BSD 2-Clause "Simplified" License
2.82k stars 307 forks source link

cmake: initial build/tests for webdis #242

Open snikulov opened 5 months ago

snikulov commented 5 months ago

Added initial build generation with CMake for webdis What you need for using - cmake, gcc, make or ninja

How to use

in webdis repository cmake -S. -Bbuild [optional configuration parameters] to generate webdis build

where -DCMAKE_BUILD_TYPE=Debug|Release to select build target (Debug by default) -DWITH_OPENSSL=ON|OFF to add/disable OpenSSL support (Enabled by default) -DWITH_OWN_HIREDIS=ON|OFF to use own sources or system packaged hiredis library (Disabled, and thus used system library related to #238) -DWITH_TESTS=ON|OFF to enable/disable tests (Enabled by default) -GNinja - for ninja-build tool usage instead of make (without this option makefile build generated)

cmake --build build to build webdis service ctest -VV --test-dir build to run tests

Optional TODO:

  1. can be added into CI
  2. not tested with MacOS (I don't have one)
  3. check with conan/vcpkg package managers
  4. libjansson also can be excluded from build in favor of system pre-installed (related to #239)
  5. pubsub test currently commented out because of #149

Here how it looks

╭─> ~/.../webdis ‹dev/cmake-build●› 
╰─$ cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=Release -GNinja
-- The C compiler identification is GNU 7.5.0
-- The CXX compiler identification is GNU 7.5.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/lib64/ccache/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/lib64/ccache/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE  
-- Found OpenSSL: /usr/lib64/libcrypto.so (found version "1.1.1l")  
-- Checking for modules 'libevent;libevent_openssl;libevent_pthreads'
--   Found libevent, version 2.1.8-stable
--   Found libevent_openssl, version 2.1.8-stable
--   Found libevent_pthreads, version 2.1.8-stable
-- Checking for modules 'hiredis;hiredis_ssl'
--   Found hiredis, version 1.1.0
--   Found hiredis_ssl, version 1.1.0
-- Found Python: /home/snikulov/bin/python3 (found version "3.11.5") found components: Interpreter 
-- =======================================
-- Configured project: webdis
-- ======= Project variables =============
-- CMAKE_BUILD_TYPE="Release"
-- CMAKE_C_COMPILER="/usr/lib64/ccache/cc" ; CMAKE_C_FLAGS=" -Wall -Wextra -pedantic"
-- WITH_OWN_HIREDIS="OFF" ; WITH_MSGPACK="ON" ; WITH_OPENSSL="ON" ; WITH_TESTS="ON"
-- 
 Properties for TARGET webdis:
   webdis.COMPILE_DEFINITIONS = "_POSIX_C_SOURCE=200809L;HAVE_SSL=1;MSGPACK=1"
   webdis.COMPILE_OPTIONS = <NOTFOUND>

-- ======= System discovered variables =============
-- OPENSSL_FOUND="TRUE" ; OPENSSL_VERSION="1.1.1l"
-- hiredis_FOUND="1" ; hiredis_hiredis_VERSION="1.1.0"
-- libevent_FOUND="1" ; libevent_libevent_VERSION="2.1.8-stable"
-- msgpack_FOUND="1" ; msgpack_VERSION="4.0.0"
-- =======================================
-- Configuring done (0.9s)
-- Generating done (0.0s)
-- Build files have been written to: /home/snikulov/work/github/webdis/build
╭─> ~/.../webdis ‹dev/cmake-build●› 
╰─$ cmake --build build
[9/34] Building C object CMakeFiles/webdis.dir/src/jansson/src/load.c.o
/.../webdis/src/jansson/src/load.c: In function ‘stream_unget’:
/.../webdis/src/jansson/src/load.c:179:49: warning: unused parameter ‘c’ [-Wunused-parameter]
 static void stream_unget(stream_t *stream, char c)
                                                 ^
/.../webdis/src/jansson/src/load.c: In function ‘lex_unget_unsave’:
/...//webdis/src/jansson/src/load.c:211:10: warning: variable ‘d’ set but not used [-Wunused-but-set-variable]
     char d;
          ^
[34/34] Linking C executable webdis
╭─> ~/.../webdis ‹dev/cmake-build●› 
╰─$ ctest --output-on-failure --test-dir build     
Internal ctest changing into directory: /.../webdis/build
Test project /.../webdis/build
    Start 1: test_run_webdis_start
1/5 Test #1: test_run_webdis_start ............   Passed    0.00 sec
    Start 3: test_basic
2/5 Test #3: test_basic .......................   Passed    0.11 sec
    Start 4: test_limits
3/5 Test #4: test_limits ......................   Passed    0.27 sec
    Start 5: test_bench
4/5 Test #5: test_bench .......................   Passed   11.03 sec
    Start 2: test_run_webdis_stop
5/5 Test #2: test_run_webdis_stop .............   Passed    0.02 sec

100% tests passed, 0 tests failed out of 5

Total Test time (real) =  11.43 sec
╭─> ~/.../webdis ‹dev/cmake-build●›