-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathFindublksrv.cmake
More file actions
78 lines (69 loc) · 3.12 KB
/
Copy pathFindublksrv.cmake
File metadata and controls
78 lines (69 loc) · 3.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# ublksrv (ublk userspace library; autotools project, no CMake).
# Only the lib/ directory (pure-C libublksrv) is built:
# - avoids the C++20/-fcoroutines requirement of the ublk CLI tool;
# - libnfs/libiscsi/gnutls only serve its bundled targets, all disabled.
# liburing is built from source by Findliburing.cmake and fed to configure
# via pkg-config/CFLAGS/LDFLAGS (the official build_with_liburing_src flow).
# License: lib/ + include/ublksrv.h are dual MIT/LGPL; linked under MIT.
include(FetchContent)
set(FETCHCONTENT_QUIET false)
if(POLICY CMP0169)
cmake_policy(SET CMP0169 OLD)
endif()
# the autotools build needs extra host tools; fail early with a clear message
find_program(AUTORECONF_EXECUTABLE autoreconf)
find_program(LIBTOOLIZE_EXECUTABLE libtoolize)
find_program(AUTOMAKE_EXECUTABLE automake)
if(NOT AUTORECONF_EXECUTABLE OR NOT LIBTOOLIZE_EXECUTABLE OR NOT AUTOMAKE_EXECUTABLE)
message(FATAL_ERROR
"BUILD_UBLK_FRONTEND requires autotools (autoconf/automake/libtool) "
"to build ublksrv. Install them or configure with -DBUILD_UBLK_FRONTEND=off")
endif()
FetchContent_Declare(
ublksrv
GIT_REPOSITORY https://github.com/ublk-org/ublksrv.git
GIT_TAG f6c643952d1cdc7f6460630638fe6b5454ca1c4d # v1.7
)
FetchContent_GetProperties(ublksrv)
if(NOT ublksrv_POPULATED)
FetchContent_Populate(ublksrv)
endif()
if(NOT TARGET libublksrv_build)
add_custom_command(
OUTPUT ${ublksrv_SOURCE_DIR}/lib/.libs/libublksrv.a
WORKING_DIRECTORY ${ublksrv_SOURCE_DIR}
COMMAND autoreconf -i
COMMAND ${CMAKE_COMMAND} -E env PKG_CONFIG_PATH=${LIBURING_PC_DIR}
./configure
--without-libnfs --without-libiscsi --without-gnutls
# configure appends -fcoroutines whenever $CXX matches *g++*
# (GCC 10+ only, and only the ublk tool needs it, lib/ does not);
# use the name c++ to sidestep that match
CXX=c++
"CFLAGS=-I${LIBURING_INCLUDE_DIRS} -O2"
"CXXFLAGS=-I${LIBURING_INCLUDE_DIRS} -O2"
"LDFLAGS=-L${liburing_SOURCE_DIR}/src"
COMMAND make -C lib -j
DEPENDS ${LIBURING_LIBRARIES}
COMMENT "Building libublksrv (lib/ only) with autotools"
VERBATIM
)
add_custom_target(libublksrv_build DEPENDS ${ublksrv_SOURCE_DIR}/lib/.libs/libublksrv.a)
add_dependencies(libublksrv_build liburing_build)
endif()
set(UBLKSRV_LIBRARIES ${ublksrv_SOURCE_DIR}/lib/.libs/libublksrv.a)
set(UBLKSRV_INCLUDE_DIRS ${ublksrv_SOURCE_DIR}/include)
if(NOT TARGET libublksrv_static)
add_library(libublksrv_static STATIC IMPORTED GLOBAL)
set_target_properties(libublksrv_static PROPERTIES
IMPORTED_LOCATION ${UBLKSRV_LIBRARIES}
INTERFACE_INCLUDE_DIRECTORIES ${UBLKSRV_INCLUDE_DIRS}
# libublksrv.a references liburing symbols; propagate via INTERFACE so
# consumers get the correct link order automatically
INTERFACE_LINK_LIBRARIES liburing_static
)
endif()
add_dependencies(libublksrv_static libublksrv_build)
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ublksrv DEFAULT_MSG UBLKSRV_LIBRARIES UBLKSRV_INCLUDE_DIRS)
mark_as_advanced(UBLKSRV_LIBRARIES UBLKSRV_INCLUDE_DIRS)