From 9414fb6496dfb8ea4e770eb0a362be5497220475 Mon Sep 17 00:00:00 2001 From: Anton Kuchin Date: Fri, 1 Mar 2024 18:01:07 +0100 Subject: [PATCH] cmake: introduce cmake support Cmake is used by NBS releases, so allow building the library with it. To build the library with cmake: cmake -S . -B build -G Ninja -DCMAKE_C_COMPILER=clang && ninja -C build Signed-off-by: Anton Kuchin --- CMakeLists.txt | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..564181b --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,63 @@ +cmake_minimum_required(VERSION 3.15) + +project(yc-libvhost-server C) + +if(UNIX AND NOT APPLE) + set(LINUX TRUE) +endif() + +if(NOT LINUX) + message(FATAL_ERROR "Unsupported platform") +endif() + +set(LIBVHOST_LOG_VERBOSITY "LOG_INFO" CACHE STRING "Libvhost log verbosity") +message("Compiler ${CMAKE_C_COMPILER}") +message("Libvhost log verbosity: ${LIBVHOST_LOG_VERBOSITY}") + +add_library(vhost-server) +add_compile_definitions(_GNU_SOURCE LOG_VERBOSITY=${LIBVHOST_LOG_VERBOSITY}) +target_compile_options(vhost-server PRIVATE + -Wall + -Werror + -Wextra + -Wno-unused-parameter + -g + -O2 + + # make these warinings non-falal in gcc + $<$: + -Wno-error=unused-value + -Wno-error=unused-result + -Wno-error=strict-aliasing + > + + # enable additional warnings to enforce coding standards + -Wmissing-prototypes + -Wmissing-declarations + $<$: + -Wmissing-variable-declarations + -Wzero-length-array + > + $<$: + -Wzero-length-bounds + > +) +target_include_directories(vhost-server PUBLIC + include +) +target_include_directories(vhost-server PRIVATE + ./ +) +target_sources(vhost-server PRIVATE + blockdev.c + event.c + fs.c + logging.c + memlog.c + memmap.c + server.c + vdev.c + virtio/virt_queue.c + virtio/virtio_blk.c + virtio/virtio_fs.c +)