forked from nemuTUI/nemu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
351 lines (309 loc) · 11.5 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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
cmake_minimum_required(VERSION 2.8.12)
project(nemu C)
set(CMAKE_COLOR_MAKEFILE OFF)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH}
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
include(GNUInstallDirs)
include(CheckSymbolExists)
include(BuildQEMU)
include(BuildNcurses)
include(FindPkgConfig)
include(FindOpenSSL)
include(FindIntl)
set(CMAKE_C_FLAGS_SANITIZER "-g -fsanitize=address -fsanitize=pointer-compare -fsanitize=pointer-subtract -fsanitize=leak -fsanitize=undefined -fno-omit-frame-pointer" CACHE STRING
"Flags used by the C compiler during sanitizer build."
FORCE)
set(CMAKE_EXE_LINKER_FLAGS_SANITIZER
"" CACHE STRING
"Flags used for linking binaries during sanitizer build."
FORCE)
set(CMAKE_SHARED_LINKER_FLAGS_SANITIZER
"" CACHE STRING
"Flags used by the shared libraries linker during sanitizer build."
FORCE)
mark_as_advanced(
CMAKE_C_FLAGS_SANITIZER
CMAKE_EXE_LINKER_FLAGS_SANITIZER
CMAKE_SHARED_LINKER_FLAGS_SANITIZER)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS Debug Release RelWithDebInfo MinSizeRel Sanitizer)
set(CMAKE_BUILD_TYPE "${CMAKE_BUILD_TYPE}" CACHE STRING
"Build type, options are: Debug Release RelWithDebInfo MinSizeRel Sanitizer."
FORCE)
if(CMAKE_SYSTEM_NAME STREQUAL Linux)
set(NM_OS_LINUX TRUE)
elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(NM_OS_FREEBSD TRUE)
else()
message(FATAL_ERROR "Build on ${CMAKE_SYSTEM_NAME} is not supported")
endif()
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE
"Release"
CACHE STRING "Choose the type of build" FORCE)
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release"
"MinSizeRel" "RelWithDebInfo")
endif()
if(NOT NM_CUSTOM_SYS_INCLUDE)
set(NM_CUSTOM_SYS_INCLUDE
""
CACHE PATH "Path to additional system include directory" FORCE)
else()
include_directories(SYSTEM ${NM_CUSTOM_SYS_INCLUDE})
endif()
option(NM_WITH_OVF_SUPPORT "Build with OVF support" ON)
option(NM_WITH_NETWORK_MAP "Build with exporting network map to SVG" OFF)
option(NM_WITH_DBUS "Build with D-Bus support" OFF)
option(NM_WITH_QEMU "Build with embedded QEMU" OFF)
option(NM_WITH_NCURSES "Build with embedded statically linked ncurses" OFF)
option(NM_WITH_REMOTE "Build with remote control" OFF)
include_directories(src)
aux_source_directory(src SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
if(NM_WITH_NCURSES)
set(PATCH_COMMAND patch)
if(NOT CPACK_RPM_PACKAGE_SOURCES)
build_ncurses()
endif()
add_dependencies(${PROJECT_NAME} libncurses libform libpanel)
set(CURSES_LIBRARIES libncurses libform libpanel)
add_definitions(-DNM_WITH_NCURSES)
else()
set(CURSES_NEED_NCURSES TRUE)
set(CURSES_NEED_WIDE TRUE)
find_package(Curses REQUIRED)
if(CURSES_HAVE_CURSES_H)
add_definitions(-DCURSES_HAVE_CURSES_H="${CURSES_HAVE_CURSES_H}")
endif()
if(CURSES_HAVE_NCURSES_CURSES_H)
add_definitions(-DCURSES_HAVE_NCURSES_CURSES_H="${CURSES_HAVE_NCURSES_CURSES_H}")
endif()
if(CURSES_HAVE_NCURSES_H)
add_definitions(-DCURSES_HAVE_NCURSES_H="${CURSES_HAVE_NCURSES_H}")
endif()
if(CURSES_HAVE_NCURSES_NCURSES_H)
add_definitions(-DCURSES_HAVE_NCURSES_NCURSES_H="${CURSES_HAVE_NCURSES_NCURSES_H}")
endif()
endif()
find_package(Sqlite3 REQUIRED)
find_package(Threads REQUIRED)
find_package(RT REQUIRED)
find_package(libusb-1.0 REQUIRED)
find_package(UDev REQUIRED)
find_package(Intl REQUIRED)
pkg_check_modules(JSONC REQUIRED json-c)
target_link_libraries(
${PROJECT_NAME} ${CURSES_LIBRARIES} ${SQLITE3_LIBRARIES} ${JSONC_LINK_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT} ${LIBUSB_1_LIBRARIES} ${UDEV_LIBRARIES}
${RT_LIBRARY} ${Intl_LIBRARIES})
include_directories(${CURSES_INCLUDE_PATH} ${SQLITE3_INCLUDE_DIR}
${UDEV_INCLUDE_DIR} ${JSONC_INCLUDE_DIRS} ${Intl_INCLUDE_DIRS})
include_directories(SYSTEM ${LIBUSB_1_INCLUDE_DIRS})
add_definitions(-DNM_FULL_DATAROOTDIR="${CMAKE_INSTALL_FULL_DATAROOTDIR}")
add_definitions(-DNM_FULL_LOCALEDIR="${CMAKE_INSTALL_FULL_LOCALEDIR}")
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99)
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD_REQUIRED ON)
set_property(
TARGET ${PROJECT_NAME}
APPEND_STRING
PROPERTY COMPILE_FLAGS "-Wall -Wextra -Wformat-security -pedantic -std=c99 ")
set_property(
TARGET ${PROJECT_NAME}
APPEND_STRING
PROPERTY LINK_FLAGS_RELEASE "-s")
set(NM_WITH_SENDFILE FALSE)
set(NM_DEFAULT_VMDIR "nemu_vm" CACHE STRING
"Default VM directory with subdirectories in users home dir")
set(NM_DEFAULT_VNC "/usr/bin/vncviewer" CACHE STRING
"Default VNC client")
set(NM_DEFAULT_DBFILE ".nemu.db" CACHE STRING
"Default database file name with subdirectories in users home dir")
set(NM_DEFAULT_SPICE "/usr/bin/remote-viewer" CACHE STRING
"Default SPICE client")
set(NM_DEFAULT_QEMUDIR "/usr/bin" CACHE STRING
"Default qemu binaries directory path")
if(NM_OS_LINUX)
add_definitions(-DNM_OS_LINUX)
try_compile(
NET_IF
"${CMAKE_CURRENT_BINARY_DIR}/CMake_Tests"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Tests/net_if.c"
COMPILE_DEFINITIONS "-Wall -Wextra -pedantic -Werror")
if(NOT NET_IF)
add_definitions(-DNM_NET_IF_FIX)
endif()
try_compile(
SENDFILE
"${CMAKE_CURRENT_BINARY_DIR}/CMake_Tests"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/Tests/sendfile.c"
COMPILE_DEFINITIONS "-Wall -Wextra -pedantic -Werror")
if(SENDFILE)
set(NM_WITH_SENDFILE TRUE)
add_definitions(-DNM_WITH_SENDFILE)
endif()
if(NM_CUSTOM_SYS_INCLUDE)
check_symbol_exists(
RTM_NEWLINKPROP "${NM_CUSTOM_SYS_INCLUDE}/linux/rtnetlink.h"
NM_WITH_NEWLINKPROP)
else()
check_symbol_exists(RTM_NEWLINKPROP "linux/rtnetlink.h" NM_WITH_NEWLINKPROP)
endif()
if(NM_WITH_NEWLINKPROP)
set(NM_WITH_NEWLINKPROP TRUE)
add_definitions(-DNM_WITH_NEWLINKPROP)
else()
set(NM_WITH_NEWLINKPROP FALSE)
endif()
elseif(NM_OS_FREEBSD)
add_definitions(-DNM_OS_FREEBSD -D_BSD_SOURCE)
set(NM_WITH_NETWORK_MAP FALSE)
find_package(Intl REQUIRED)
target_link_libraries(${PROJECT_NAME} ${Intl_LIBRARIES})
endif()
if(NM_WITH_OVF_SUPPORT)
find_package(LibXml2 REQUIRED)
find_package(LibArchive REQUIRED)
target_link_libraries(${PROJECT_NAME} ${LIBXML2_LIBRARIES}
${LibArchive_LIBRARY})
include_directories(${LIBXML2_INCLUDE_DIR} ${LibArchive_INCLUDE_DIR})
add_definitions(-DNM_WITH_OVF_SUPPORT)
endif()
if(NM_WITH_NETWORK_MAP)
find_package(Graphviz REQUIRED)
target_link_libraries(${PROJECT_NAME} ${GRAPHVIZ_LIBRARIES})
include_directories(${GRAPHVIZ_INCLUDE_DIRS})
add_definitions(-DNM_WITH_NETWORK_MAP)
endif()
if(NM_WITH_DBUS)
find_package(DBus REQUIRED)
target_link_libraries(${PROJECT_NAME} ${DBUS_LIBRARIES})
include_directories(${DBUS_INCLUDE_DIR} ${DBUS_ARCH_INCLUDE_DIR})
add_definitions(-DNM_WITH_DBUS)
endif()
if(NM_WITH_REMOTE)
find_package(OpenSSL 1.1 REQUIRED)
target_link_libraries(${PROJECT_NAME} ssl)
target_link_libraries(${PROJECT_NAME} crypto)
include_directories(${OPENSSL_INCLUDE_DIR})
add_definitions(-DNM_WITH_REMOTE)
endif()
if(NM_WITH_QEMU)
set(PATCH_COMMAND patch)
if(NOT NM_QEMU_TARGET_LIST)
set(NM_QEMU_TARGET_LIST
"x86_64-softmmu,i386-softmmu"
CACHE STRING "List of embedded QEMU targets" FORCE)
endif()
if(NOT CPACK_RPM_PACKAGE_SOURCES)
build_qemu()
endif()
set(NM_DEFAULT_QEMUDIR "${CMAKE_INSTALL_FULL_DATAROOTDIR}/nemu/qemu/bin" CACHE STRING
"Default qemu binaries directory path" FORCE)
add_definitions(-DNM_WITH_QEMU)
endif()
if(NOT GIT_TAG_VERSION)
execute_process(
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/sh/git_get_version.sh
${CMAKE_CURRENT_SOURCE_DIR} OUTPUT_VARIABLE GIT_TAG_VERSION)
endif()
if(NOT GIT_TAG_VERSION STREQUAL "")
message(STATUS "Build from git, version:${GIT_TAG_VERSION}")
add_definitions(-DNM_VERSION="${GIT_TAG_VERSION}")
endif()
string(TIMESTAMP BUILD_DATE "%Y-%m-%d")
add_definitions(-DNM_DEFAULT_VMDIR="${NM_DEFAULT_VMDIR}")
add_definitions(-DNM_DEFAULT_VNC="${NM_DEFAULT_VNC}")
add_definitions(-DNM_DEFAULT_DBFILE="${NM_DEFAULT_DBFILE}")
add_definitions(-DNM_DEFAULT_SPICE="${NM_DEFAULT_SPICE}")
add_definitions(-DNM_DEFAULT_QEMUDIR="${NM_DEFAULT_QEMUDIR}")
add_subdirectory(lang)
add_dependencies(${PROJECT_NAME} lang)
add_subdirectory(man)
add_dependencies(${PROJECT_NAME} man)
add_subdirectory(test)
# configure install
set(NEMU_CONFIG_SOURCE "${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_NAME}.cfg.sample")
set(NEMU_DB_UPGRADE_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/sh/upgrade_db.sh")
set(NEMU_NON_ROOT_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/sh/setup_nemu_nonroot.sh")
set(NEMU_MACVTAP_UDEV_RULE
"${CMAKE_CURRENT_SOURCE_DIR}/sh/42-net-macvtap-perm.rules")
set(NEMU_NTTY_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/sh/ntty")
set(NEMU_BASH_AUTOCOMPLETE "${CMAKE_CURRENT_SOURCE_DIR}/sh/nemu.bash")
install(TARGETS ${PROJECT_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR})
install(
FILES ${NEMU_CONFIG_SOURCE}
PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nemu/templates/config)
install(
FILES ${NEMU_MACVTAP_UDEV_RULE}
PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ
DESTINATION share/nemu/scripts)
install(
FILES ${NEMU_DB_UPGRADE_SCRIPT} ${NEMU_NON_ROOT_SCRIPT}
PERMISSIONS
OWNER_EXECUTE
OWNER_WRITE
OWNER_READ
GROUP_EXECUTE
GROUP_READ
WORLD_EXECUTE
WORLD_READ
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nemu/scripts)
install(
FILES ${NEMU_BASH_AUTOCOMPLETE}
PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nemu/scripts)
install(
FILES ${NEMU_NTTY_SCRIPT}
PERMISSIONS
OWNER_EXECUTE
OWNER_WRITE
OWNER_READ
GROUP_EXECUTE
GROUP_READ
WORLD_EXECUTE
WORLD_READ
DESTINATION ${CMAKE_INSTALL_BINDIR})
if(NM_WITH_QEMU)
install(
DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/qemu/${CMAKE_INSTALL_FULL_DATAROOTDIR}/nemu/qemu/
USE_SOURCE_PERMISSIONS
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/nemu/qemu)
endif()
install(
FILES ${NEMU_BASH_AUTOCOMPLETE}
PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ
DESTINATION ${CMAKE_INSTALL_FULL_DATAROOTDIR}/bash-completion/completions
RENAME "nemu")
# uninstall target
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" IMMEDIATE @ONLY)
add_custom_target(
uninstall COMMAND ${CMAKE_COMMAND} -P
${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake)
add_subdirectory(pkg/linux/rpm)
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")
message(STATUS "Install prefix: ${CMAKE_INSTALL_PREFIX}")
message(STATUS "Default VM directory name: ${NM_DEFAULT_VMDIR}")
message(STATUS "Default VNC client ${NM_DEFAULT_VNC}")
message(STATUS "Default database name: ${NM_DEFAULT_DBFILE}")
message(STATUS "Default SPICE client ${NM_DEFAULT_SPICE}")
message(STATUS "Default qemu binaries directory path: ${NM_DEFAULT_QEMUDIR}")
if(NM_CUSTOM_SYS_INCLUDE)
message(
STATUS "Additional system include directory: ${NM_CUSTOM_SYS_INCLUDE}")
endif()
message(STATUS "Using sendfile: ${NM_WITH_SENDFILE}")
message(
STATUS
"Using alternative names for network interfaces: ${NM_WITH_NEWLINKPROP}")
message(STATUS "OVF support: ${NM_WITH_OVF_SUPPORT}")
message(STATUS "Network map export: ${NM_WITH_NETWORK_MAP}")
message(STATUS "D-Bus support: ${NM_WITH_DBUS}")
message(STATUS "Remote control support: ${NM_WITH_REMOTE}")
message(STATUS "Embedded QEMU: ${NM_WITH_QEMU}")
if(NM_WITH_QEMU)
message(STATUS "Embedded QEMU targets: ${NM_QEMU_TARGET_LIST}")
endif()
message(STATUS "Embedded ncurses: ${NM_WITH_NCURSES}")