-
Notifications
You must be signed in to change notification settings - Fork 3
/
CMakeLists.txt
180 lines (148 loc) · 6.26 KB
/
CMakeLists.txt
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# ==============================================================================
# CMakeLists.txt
#
# Copyright (C) 2019 xcp-ng-xapi-storage
# Copyright (C) 2019 Vates SAS
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# ==============================================================================
cmake_minimum_required(VERSION 3.13.1)
# ------------------------------------------------------------------------------
project(xcp-ng-xapi-storage VERSION 1.0.2 LANGUAGES)
find_package(Python2 COMPONENTS Interpreter REQUIRED)
# ------------------------------------------------------------------------------
# Config.
# ------------------------------------------------------------------------------
set(DATAPATH_PLUGINS
# qdisk
tapdisk
)
set(VOLUME_PLUGINS
org.xen.xapi.storage.zfs-vol
# org.xen.xapi.storage.ext4-ng
# org.xen.xapi.storage.filebased
# org.xen.xapi.storage.nfs-ng
# org.xen.xapi.storage.raw-device
)
set(LIBS_TASKS
libcow/coalesce.py
libcow/db_backup.py
)
# ------------------------------------------------------------------------------
set(STORAGE_LIBS_TARGET "${CMAKE_CURRENT_BINARY_DIR}/xcp-ng-xapi-storage-libs.timestamp")
set(STORAGE_LIBS "${CMAKE_CURRENT_BINARY_DIR}/setup_py")
file(GLOB_RECURSE STORAGE_LIBS_SOURCES "xapi/*.py")
add_custom_command(OUTPUT ${STORAGE_LIBS_TARGET}
COMMAND ${Python2_EXECUTABLE} setup.py install --root "${STORAGE_LIBS}"
COMMAND ${CMAKE_COMMAND} -E touch ${STORAGE_LIBS_TARGET}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS setup.py ${STORAGE_LIBS_SOURCES}
)
add_custom_target(target ALL DEPENDS ${STORAGE_LIBS_TARGET})
# ------------------------------------------------------------------------------
# Install.
# ------------------------------------------------------------------------------
# Not sexy but in our case it's ok. Install in lib, not lib64!
set(CMAKE_SIZEOF_VOID_P 4)
include(GNUInstallDirs)
# Install libs and tasks.
list(JOIN LIBS_TASKS "|" LIBS_TASKS_REGEX)
set(LIBS_TASKS_REGEX "(${LIBS_TASKS_REGEX})$")
install(DIRECTORY "${STORAGE_LIBS}/usr/"
DESTINATION .
PATTERN REGEX ${LIBS_TASKS_REGEX} EXCLUDE
)
install(DIRECTORY "${STORAGE_LIBS}/usr/"
DESTINATION .
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
FILES_MATCHING
PATTERN REGEX ${LIBS_TASKS_REGEX}
)
## Install daemons.
#install(FILES daemons/qemuback/qemuback.py
# DESTINATION ${CMAKE_INSTALL_BINDIR}
# PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
#)
#install(FILES daemons/qemuback/qemuback.service
# DESTINATION ${CMAKE_INSTALL_LIBDIR}/systemd/system
#)
# Install plugins.
set(PLUGINS_INSTALL_PATH "${CMAKE_INSTALL_FULL_LIBEXECDIR}/xapi-storage-script")
# Use an absolute path to create correctly symlinks.
# When cmake is called like this: `/usr/bin/cmake -DCMAKE_INSTALL_PREFIX:PATH=toto`, the prefix path
# is relative. It is absolute when cmake is called: `/usr/bin/cmake -DCMAKE_INSTALL_PREFIX=toto`.
get_filename_component(PLUGINS_INSTALL_PATH ${PLUGINS_INSTALL_PATH} ABSOLUTE BASE_DIR ${CMAKE_CURRENT_BINARY_DIR})
function (install_plugin PLUGIN_NAME IN OUT TYPE)
set(IN "${IN}/${PLUGIN_NAME}")
set(OUT "${OUT}/${PLUGIN_NAME}")
set(BIN_REGEX)
if (TYPE STREQUAL "DATAPATH")
set(BIN_REGEX "${IN}/(datapath|plugin).py$")
else ()
set(BIN_REGEX "${IN}/(sr|volume|plugin).py$")
endif ()
install(DIRECTORY "${IN}/"
DESTINATION ${OUT}
PATTERN REGEX ${BIN_REGEX} EXCLUDE
)
install(DIRECTORY "${IN}/"
DESTINATION ${OUT}
FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE
FILES_MATCHING
PATTERN REGEX ${BIN_REGEX}
)
endfunction ()
function (create_plugin_symlink PLUGIN_NAME TARGET LINK_NAME PLUGINS_DIR)
set(RESULT_SYMLINK RESULT_SYMLINK_${PLUGIN_NAME}_${LINK_NAME})
install(CODE "
# Use DESTDIR if necessary!
set(WORKING_DIRECTORY \"\$ENV{DESTDIR}/${PLUGINS_DIR}/${PLUGIN_NAME}\")
message(\"Create symlink: ${TARGET} ${LINK_NAME} in \${WORKING_DIRECTORY}\")
execute_process(
COMMAND ${CMAKE_COMMAND} -E create_symlink ${TARGET} ${LINK_NAME}
WORKING_DIRECTORY \${WORKING_DIRECTORY}
RESULT_VARIABLE ${RESULT_SYMLINK}
)
if (NOT \"\${${RESULT_SYMLINK}}\" STREQUAL \"0\")
message(FATAL_ERROR \"Failed to create symlink: \${${RESULT_SYMLINK}}...\")
endif ()
")
endfunction ()
foreach (PLUGIN_NAME ${DATAPATH_PLUGINS})
set(IN_PLUGINS_DIR "plugins/datapath")
set(OUT_PLUGINS_DIR "${PLUGINS_INSTALL_PATH}/datapath")
install_plugin(${PLUGIN_NAME} ${IN_PLUGINS_DIR} ${OUT_PLUGINS_DIR} "DATAPATH")
foreach (LINK_NAME activate attach close deactivate detach open)
create_plugin_symlink(${PLUGIN_NAME} "datapath.py" "Datapath.${LINK_NAME}" ${OUT_PLUGINS_DIR})
endforeach ()
create_plugin_symlink(${PLUGIN_NAME} "plugin.py" "Plugin.Query" ${OUT_PLUGINS_DIR})
endforeach ()
foreach (PLUGIN_NAME ${VOLUME_PLUGINS})
set(IN_PLUGINS_DIR "plugins/volume")
set(OUT_PLUGINS_DIR "${PLUGINS_INSTALL_PATH}/volume")
install_plugin(${PLUGIN_NAME} ${IN_PLUGINS_DIR} ${OUT_PLUGINS_DIR} "VOLUME")
foreach (LINK_NAME clone create destroy resize set set_description set_name snapshot stat unset)
create_plugin_symlink(${PLUGIN_NAME} "volume.py" "Volume.${LINK_NAME}" ${OUT_PLUGINS_DIR})
endforeach ()
foreach (LINK_NAME attach create destroy detach ls probe set_description set_name stat)
create_plugin_symlink(${PLUGIN_NAME} "sr.py" "SR.${LINK_NAME}" ${OUT_PLUGINS_DIR})
endforeach ()
foreach (LINK_NAME Query diagnostics)
create_plugin_symlink(${PLUGIN_NAME} "plugin.py" "Plugin.${LINK_NAME}" ${OUT_PLUGINS_DIR})
endforeach ()
endforeach ()
# Install doc.
install(FILES LICENSE README.md
DESTINATION ${CMAKE_INSTALL_DOCDIR}
)