-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
CMakeLists.txt
212 lines (198 loc) · 6.04 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
cmake_minimum_required(VERSION 3.14)
project(growlight VERSION 1.2.38
DESCRIPTION "Block device and filesystem manager"
HOMEPAGE_URL "https://nick-black.com/dankwiki/index.php/Growlight"
LANGUAGES C CXX)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_VISIBILITY_PRESET hidden)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
include(CTest)
include(GNUInstallDirs)
include(FeatureSummary)
include(CMakeDependentOption)
###################### USER-SELECTABLE OPTIONS ###########################
# BUILD_TESTING is defined by CTest
cmake_dependent_option(
USE_DOCTEST "Use doctest to build unit tests" ON
"${BUILD_TESTING}" OFF
)
option(USE_PANDOC "Use pandoc to write man pages" ON)
option(USE_LIBZFS "Use libzfs to manage zpools/ZFS" ON)
#################### END USER-SELECTABLE OPTIONS #########################
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the build mode." FORCE)
endif()
add_compile_definitions(_FORTIFY_SOURCE=2)
add_compile_options(-Wall -Wextra -W -Wshadow -Wformat -fexceptions)
find_package(PkgConfig REQUIRED)
find_package(Threads)
set_package_properties(Threads PROPERTIES TYPE REQUIRED)
find_package(Notcurses 3.0.5 CONFIG)
set_package_properties(Notcurses PROPERTIES TYPE REQUIRED)
pkg_check_modules(LIBATASMART REQUIRED libatasmart>=0.19)
pkg_check_modules(LIBBLKID REQUIRED blkid>=2.20.1)
pkg_check_modules(LIBCAP REQUIRED libcap>=2.24)
pkg_check_modules(LIBCRYPTSETUP REQUIRED libcryptsetup>=2.0.2)
pkg_check_modules(LIBDEVMAPPER REQUIRED devmapper>=1.02.74)
pkg_check_modules(LIBNETTLE REQUIRED nettle>=3.5.1)
pkg_check_modules(LIBPCI REQUIRED libpci>=3.1.9)
pkg_check_modules(LIBPCIACCESS REQUIRED pciaccess>=0.13.1)
pkg_check_modules(LIBUDEV REQUIRED libudev>=175)
pkg_check_modules(LIBZ REQUIRED zlib>=1.2.11)
if(${USE_DOCTEST})
find_package(doctest 2.3.5)
set_package_properties(doctest PROPERTIES TYPE REQUIRED)
endif()
if(${USE_LIBZFS})
pkg_check_modules(LIBZFS REQUIRED libzfs>=0.8)
endif()
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
include(CMakePackageConfigHelpers)
configure_file(src/version.h.in include/version.h)
set(COMMON_INCLUDE_DIRS
"${LIBATASMART_INCLUDE_DIRS}"
"${LIBBLKID_INCLUDE_DIRS}"
"${LIBCAP_INCLUDE_DIRS}"
"${LIBCRYPTSETUP_INCLUDE_DIRS}"
"${LIBDEVMAPPER_INCLUDE_DIRS}"
"${LIBNETTLE_INCLUDE_DIRS}"
"${LIBPCI_INCLUDE_DIRS}"
"${LIBPCIACCESS_INCLUDE_DIRS}"
"${LIBUDEV_INCLUDE_DIRS}"
"${LIBZ_INCLUDE_DIRS}"
"${LIBZFS_INCLUDE_DIRS}"
"${Notcurses_INCLUDE_DIRS}"
)
set(COMMON_LIBRARY_DIRS
"${LIBATASMART_LIBRARY_DIRS}"
"${LIBBLKID_LIBRARY_DIRS}"
"${LIBCAP_LIBRARY_DIRS}"
"${LIBCRYPTSETUP_LIBRARY_DIRS}"
"${LIBDEVMAPPER_LIBRARY_DIRS}"
"${LIBNETTLE_LIBRARY_DIRS}"
"${LIBPCI_LIBRARY_DIRS}"
"${LIBPCIACCESS_LIBRARY_DIRS}"
"${LIBUDEV_LIBRARY_DIRS}"
"${LIBZ_LIBRARY_DIRS}"
"${LIBZFS_LIBRARY_DIRS}"
"${Notcurses_LIBRARY_DIRS}"
)
set(COMMON_LIBRARIES
"${LIBATASMART_LIBRARIES}"
"${LIBBLKID_LIBRARIES}"
"${LIBCAP_LIBRARIES}"
"${LIBCRYPTSETUP_LIBRARIES}"
"${LIBDEVMAPPER_LIBRARIES}"
"${LIBNETTLE_LIBRARIES}"
"${LIBPCI_LIBRARIES}"
"${LIBPCIACCESS_LIBRARIES}"
"${LIBUDEV_LIBRARIES}"
"${LIBZ_LIBRARIES}"
"${LIBZFS_LIBRARIES}"
"${Notcurses_LIBRARIES}"
Threads::Threads
)
file(GLOB SRCS CONFIGURE_DEPENDS src/*.c)
file(GLOB NCSRCS CONFIGURE_DEPENDS src/notcurses/*.c)
add_executable(growlight ${SRCS} ${NCSRCS})
target_include_directories(growlight
PRIVATE
src
"${PROJECT_BINARY_DIR}/include"
"${COMMON_INCLUDE_DIRS}"
)
target_compile_definitions(growlight
PRIVATE
_GNU_SOURCE _DEFAULT_SOURCE _XOPEN_SOURCE=600
)
target_link_libraries(growlight
PRIVATE
"${COMMON_LIBRARIES}"
)
target_link_directories(growlight
PRIVATE
"${COMMON_LIBRARY_DIRS}"
)
file(GLOB RLSRCS CONFIGURE_DEPENDS src/readline/*.c)
add_executable(growlight-readline ${SRCS} ${RLSRCS})
target_include_directories(growlight-readline
PRIVATE
src
"${PROJECT_BINARY_DIR}/include"
"${COMMON_INCLUDE_DIRS}"
)
target_compile_definitions(growlight-readline
PRIVATE
_GNU_SOURCE _DEFAULT_SOURCE _XOPEN_SOURCE=600
)
target_link_libraries(growlight-readline
PRIVATE
"${COMMON_LIBRARIES}"
)
target_link_directories(growlight-readline
PRIVATE
"${COMMON_LIBRARY_DIRS}"
)
if(${USE_DOCTEST})
file(GLOB TESTSRCS CONFIGURE_DEPENDS tests/*.cpp)
add_executable(growlight-tester ${SRCS} ${TESTSRCS})
target_include_directories(growlight-tester
PRIVATE
src
"${PROJECT_BINARY_DIR}/include"
"${COMMON_INCLUDE_DIRS}"
)
target_compile_definitions(growlight-tester
PRIVATE
_GNU_SOURCE _DEFAULT_SOURCE _XOPEN_SOURCE=600
)
target_link_libraries(growlight-tester
PRIVATE
"${COMMON_LIBRARIES}"
)
target_link_directories(growlight-tester
PRIVATE
"${COMMON_LIBRARY_DIRS}"
)
add_test(
NAME growlight-tester
COMMAND growlight-tester
)
endif()
add_test(
NAME blockdev-verbose
COMMAND sh -c "echo 'blockdev -v' | ./growlight-readline -v --notroot"
)
# Pandoc documentation (man pages)
if(USE_PANDOC)
file(GLOB MANSOURCE8 CONFIGURE_DEPENDS doc/man/man8/*.md)
find_program(PANDOC pandoc)
if(NOT PANDOC)
message(FATAL_ERROR "pandoc not found. USE_PANDOC=OFF to disable.")
else()
foreach(m ${MANSOURCE8})
get_filename_component(me ${m} NAME_WLE)
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${me}
DEPENDS ${m}
COMMAND ${PANDOC}
ARGS --to man --standalone --from markdown-smart ${m} > ${CMAKE_CURRENT_BINARY_DIR}/${me}
COMMENT "Building man page ${me}"
)
add_custom_target(${me}.man
ALL
DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${me}
)
endforeach()
foreach(m ${MANSOURCE8})
get_filename_component(me ${m} NAME_WLE)
LIST(APPEND MANPAGES8 ${CMAKE_CURRENT_BINARY_DIR}/${me})
endforeach()
endif()
endif()
install(FILES doc/growlight.jpg DESTINATION ${CMAKE_INSTALL_FULL_DATADIR}/growlight)
install(TARGETS growlight DESTINATION sbin)
install(TARGETS growlight-readline DESTINATION sbin)
install(FILES ${MANPAGES8} DESTINATION ${CMAKE_INSTALL_PREFIX}/share/man/man8)