Skip to content

Commit

Permalink
cmake: introduce cmake support
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
aikuchin committed Mar 4, 2024
1 parent 77ec0b5 commit 9414fb6
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
$<$<C_COMPILER_ID:GNU>:
-Wno-error=unused-value
-Wno-error=unused-result
-Wno-error=strict-aliasing
>

# enable additional warnings to enforce coding standards
-Wmissing-prototypes
-Wmissing-declarations
$<$<C_COMPILER_ID:Clang>:
-Wmissing-variable-declarations
-Wzero-length-array
>
$<$<C_COMPILER_ID:GNU>:
-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
)

0 comments on commit 9414fb6

Please sign in to comment.