-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathCMakeLists.txt
277 lines (232 loc) · 9.75 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
cmake_minimum_required (VERSION 3.16.3)
project (appanvil)
#### Set Source Code #####
set(PROJECT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src)
### Sources that need to be built ###
set(
SOURCES
${PROJECT_SOURCE_DIR}/main_window.cc
${PROJECT_SOURCE_DIR}/console_thread.cc
${PROJECT_SOURCE_DIR}/threads/blocking_queue.cc
${PROJECT_SOURCE_DIR}/threads/command_caller.cc
${PROJECT_SOURCE_DIR}/threads/dispatcher_middleman.cc
${PROJECT_SOURCE_DIR}/threads/log_record.cc
${PROJECT_SOURCE_DIR}/threads/log_reader.cc
${PROJECT_SOURCE_DIR}/tabs/model/database.cc
${PROJECT_SOURCE_DIR}/tabs/model/combobox_store.cc
${PROJECT_SOURCE_DIR}/tabs/model/status_column_record.cc
${PROJECT_SOURCE_DIR}/tabs/model/profile_adapter.cc
${PROJECT_SOURCE_DIR}/tabs/model/process_adapter.cc
${PROJECT_SOURCE_DIR}/tabs/model/log_adapter.cc
${PROJECT_SOURCE_DIR}/tabs/controller/status_controller.cc
${PROJECT_SOURCE_DIR}/tabs/controller/profiles_controller.cc
${PROJECT_SOURCE_DIR}/tabs/controller/profile_modify_controller.cc
${PROJECT_SOURCE_DIR}/tabs/controller/profile_loader_controller.cc
${PROJECT_SOURCE_DIR}/tabs/controller/processes_controller.cc
${PROJECT_SOURCE_DIR}/tabs/controller/logs_controller.cc
${PROJECT_SOURCE_DIR}/tabs/view/apparmor_not_installed.cc
${PROJECT_SOURCE_DIR}/tabs/view/status.cc
${PROJECT_SOURCE_DIR}/tabs/view/profiles.cc
${PROJECT_SOURCE_DIR}/tabs/view/processes.cc
${PROJECT_SOURCE_DIR}/tabs/view/logs.cc
${PROJECT_SOURCE_DIR}/tabs/view/profile_loader.cc
${PROJECT_SOURCE_DIR}/tabs/view/profile_modify.cc
${PROJECT_SOURCE_DIR}/tabs/view/help.cc
${PROJECT_SOURCE_DIR}/tabs/view/info_box.cc
${PROJECT_SOURCE_DIR}/tabs/view/scrolled_view.cc
${PROJECT_SOURCE_DIR}/tabs/view/add_abstraction.cc
${PROJECT_SOURCE_DIR}/tabs/view/add_file_rule.cc
)
### All the code globbed together for easy formatting ###
# We include this so it can be affected by clang-format
file(GLOB_RECURSE FORMAT_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/src/*.cc
${CMAKE_CURRENT_SOURCE_DIR}/src/*.h
${CMAKE_CURRENT_SOURCE_DIR}/src/*.inl
${CMAKE_CURRENT_SOURCE_DIR}/test/src/*.cc
${CMAKE_CURRENT_SOURCE_DIR}/test/src/*.h
${CMAKE_CURRENT_SOURCE_DIR}/test/src/*.inl
${CMAKE_CURRENT_SOURCE_DIR}/aa-caller/src/*.cc
${CMAKE_CURRENT_SOURCE_DIR}/aa-caller/src/*.h
${CMAKE_CURRENT_SOURCE_DIR}/aa-caller/src/*.inl
)
set(PROJECT_RESOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources)
set(PROJECT_UI_DIR ${PROJECT_RESOURCE_DIR}/ui)
set(GENERATED_DIR ${PROJECT_RESOURCE_DIR}/generated)
set(XML_GRESOURCE ${PROJECT_UI_DIR}/resources.gresource.xml)
set(RESOURCE_BUNDLE_OUTPUT ${GENERATED_DIR}/resource.autogen.c)
set(PKEXEC_POLICY_IN ${PROJECT_RESOURCE_DIR}/pkexec.policy.in)
set(PKEXEC_POLICY ${GENERATED_DIR}/com.github.jack-ullery.AppAnvil.pkexec.policy)
configure_file("${PKEXEC_POLICY_IN}" "${PKEXEC_POLICY}" @ONLY)
set(LICENSE_FILE "${CMAKE_CURRENT_SOURCE_DIR}/docs/copyright")
set(ICON_FILE "${PROJECT_UI_DIR}/misc/icon.svg")
#### Add Linters and Static Analysis ####
# If cmake was compiled with DANALYZE=TRUE
if(${ANALYZE})
message(STATUS "Adding static-analysis tools to build:")
set(USE_CLANG_TIDY TRUE)
set(USE_CPPCHECK TRUE)
unset(ANALYZE CACHE)
endif()
# If we want to use cppcheck
find_program(CPPCHECK NAMES cppcheck)
if(${USE_CPPCHECK})
if(${CPPCHECK} STREQUAL "CPPCHECK-NOTFOUND")
message(WARNING "Could not find cppcheck installation. Please install cppcheck if you want to use it for static analysis.")
else()
message(STATUS "Adding cppcheck to build")
set(CMAKE_CXX_CPPCHECK cppcheck
--enable=warning,performance,portability,information
--suppress=missingInclude --suppress=unmatchedSuppression --suppress=internalAstError
--quiet
--inline-suppr
src
)
endif()
unset(USE_CPPCHECK CACHE)
endif()
# If we want to use clang-tidy
find_program(CLANG_TIDY NAMES clang-tidy)
if(${USE_CLANG_TIDY})
if(${CLANG_TIDY} STREQUAL "CLANG_TIDY-NOTFOUND")
message(WARNING "Could not find clang-tidy installation. Please install clang-tidy if you want to use it for static analysis.")
else()
message(STATUS "Adding clang-tidy to build")
set(CMAKE_CXX_CLANG_TIDY clang-tidy; --config-file ${CMAKE_CURRENT_SOURCE_DIR}/.clang-tidy)
endif()
unset(USE_CLANG_TIDY CACHE)
endif()
# If clang-format is downloaded, format all the source code files in ./src and ./test/src
find_program(CLANG_FORMAT NAMES clang-format)
if(${CLANG_FORMAT} STREQUAL "CLANG_FORMAT-NOTFOUND")
message(WARNING "Could not find clang-format installation. Please install clang-format if you want to use it to automaticaly format code.")
else()
message(STATUS "Adding clang-format to build")
add_custom_target(
FORMAT
COMMAND clang-format -style=file -i ${FORMAT_SOURCES}
)
endif()
#### Include GTKmm Libraries ####
find_package(PkgConfig)
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0)
#### Include jsoncpp libraries ####
pkg_check_modules(JSONCPP REQUIRED jsoncpp)
#### libapparmor used for parsing kernel logs ####
pkg_check_modules(LIBAPPARMOR REQUIRED libapparmor)
#### libappanvil custom library for parsing/editing profiles ####
add_subdirectory(libappanvil)
set(LIBAPPANVIL_INCLUDE_DIRS "${CMAKE_CURRENT_SOURCE_DIR}/libappanvil")
#### Package the .gresource.xml resource bundle ####
# This gets the list of dependencies for ${XML_GRESOURCE} when cmake is called.
# If a dependency is added to the ${XML_GRESOURCE} file, you should run cmake again
execute_process(
COMMAND glib-compile-resources ${XML_GRESOURCE} --generate-dependencies
WORKING_DIRECTORY ${PROJECT_UI_DIR}
OUTPUT_VARIABLE GLADE_RESOURCES
RESULT_VARIABLE GLIB_RETURN_VALUE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "Using install prefix: ${CMAKE_INSTALL_PREFIX}")
set(APPANVIL_DESKTOP_IN ${PROJECT_RESOURCE_DIR}/appanvil.desktop.in)
set(APPANVIL_DESKTOP ${GENERATED_DIR}/appanvil.desktop)
configure_file(${APPANVIL_DESKTOP_IN} ${APPANVIL_DESKTOP} @ONLY)
# This ensures that ${GLADE_RESOURCES} uses semicolons instead of newline characters as seperators
string(REGEX REPLACE "\n" ";" GLADE_RESOURCES "${GLADE_RESOURCES}")
list(TRANSFORM GLADE_RESOURCES PREPEND "${PROJECT_UI_DIR}/")
# If glib-compile-resources did not complete succesfully, throw a fatal error
if (NOT GLIB_RETURN_VALUE EQUAL 0)
message(FATAL_ERROR "Failed to get the dependencies from glib-compile-resources")
endif()
add_custom_command(
OUTPUT ${RESOURCE_BUNDLE_OUTPUT}
COMMAND glib-compile-resources
--target=${RESOURCE_BUNDLE_OUTPUT}
--generate-source
${XML_GRESOURCE}
WORKING_DIRECTORY ${PROJECT_UI_DIR}
DEPENDS ${XML_GRESOURCE} ${GLADE_RESOURCES}
COMMENT "Generating Glib Resource Bundle."
VERBATIM
)
include_directories(
SYSTEM # Adds -isystem instead of -I and this tells clang-tidy not to analyze these includes
${GENERATED_DIR}
)
#### Set Compiler Options ####
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIE")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra")
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dist)
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
# set(CMAKE_LINK_WHAT_YOU_USE TRUE)
#### Create the main executable ####
add_executable(${PROJECT_NAME} ${RESOURCE_BUNDLE_OUTPUT} ${SOURCES} ${PROJECT_SOURCE_DIR}/main.cc)
add_dependencies(${PROJECT_NAME} appanvil-dev)
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${GTKMM_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${LIBAPPARMOR_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${JSONCPP_INCLUDE_DIRS})
target_include_directories(${PROJECT_NAME} SYSTEM PUBLIC ${LIBAPPANVIL_INCLUDE_DIRS})
target_link_libraries(${PROJECT_NAME} PUBLIC ${GTKMM_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PUBLIC ${LIBAPPARMOR_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PUBLIC ${JSONCPP_LIBRARIES})
target_link_libraries(${PROJECT_NAME} PUBLIC appanvil-dev)
target_link_libraries(${PROJECT_NAME} PUBLIC pthread)
pkg_check_modules(GTEST gtest)
pkg_check_modules(GMOCK gmock)
enable_testing()
add_subdirectory(aa-caller)
add_subdirectory(test)
#### Create install target to install binaries ####
install(
TARGETS ${PROJECT_NAME}
DESTINATION bin
)
#### Install desktop entry file ####
install(
FILES ${APPANVIL_DESKTOP}
DESTINATION share/applications
)
install(
FILES ${LICENSE_FILE}
DESTINATION "share/doc/appanvil"
RENAME "copyright"
)
#### Install icon ####
install(
FILES ${ICON_FILE}
DESTINATION "share/icons"
RENAME "${PROJECT_NAME}.svg"
)
#### Add CPack target ####
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libgtkmm-3.0-dev,libjsoncpp-dev,libapparmor-dev")
set(CPACK_PACKAGE_CONTACT "Jack Ullery")
set(CPACK_INSTALL_SCRIPT "cmake_install.cmake")
include(CPack)
#### Set install target to also modify pkexec ####
install(
FILES ${PKEXEC_POLICY}
DESTINATION /usr/share/polkit-1/actions/
)
#### Set install target to make snap profiles modifiable ####
# This creates symbolic links in `/var/lib/snapd/apparmor/profiles`, to make it easier to modify these profiles
set(PROFILE_SUBDIRS abi abstractions disable force-complain local tunables)
foreach(SUBDIR ${PROFILE_SUBDIRS})
install(CODE "execute_process(
COMMAND bash -c \"
test -d /var/lib/snapd/apparmor/profiles &&
! (test -d /var/lib/snapd/apparmor/profiles/${SUBDIR}) &&
sudo ln -s /etc/apparmor.d/${SUBDIR} /var/lib/snapd/apparmor/profiles
\")")
endforeach( SUBDIR )
#### Creating uninstall target (copying code from CMake FAQ) ####
if(NOT TARGET uninstall)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake"
IMMEDIATE @ONLY)
add_custom_target(uninstall
COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake)
endif()