-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
161 lines (135 loc) · 4.6 KB
/
Copy pathCMakeLists.txt
File metadata and controls
161 lines (135 loc) · 4.6 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
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
cmake_minimum_required(VERSION 3.12)
project(hostman VERSION 1.2.7 LANGUAGES C)
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/hostman/core/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/include/hostman/core/version.h
@ONLY
)
if(CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Werror=return-type)
endif()
option(HOSTMAN_USE_TUI "Build with TUI support (requires ncurses)" ON)
option(HOSTMAN_USE_NOTIFY "Build with desktop notifications via libnotify (if available)" ON)
find_package(CURL REQUIRED)
find_package(SQLite3 REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(Threads REQUIRED)
add_library(cJSON STATIC third_party/cjson/cJSON.c)
target_include_directories(cJSON PUBLIC third_party/cjson)
set(JSON_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/cjson)
if(HOSTMAN_USE_TUI)
if(WIN32)
message(STATUS "TUI not supported on Windows, building without TUI")
else()
find_package(Curses REQUIRED)
add_definitions(-DUSE_TUI)
endif()
endif()
if(HOSTMAN_USE_NOTIFY AND NOT WIN32)
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
pkg_check_modules(LIBNOTIFY QUIET libnotify)
if(LIBNOTIFY_FOUND)
add_definitions(-DHAVE_LIBNOTIFY)
message(STATUS "libnotify found, desktop notifications enabled")
else()
message(STATUS "libnotify not found, desktop notifications disabled")
endif()
else()
message(STATUS "pkg-config not found, desktop notifications disabled")
endif()
else()
message(STATUS "Desktop notifications disabled")
endif()
set(HOSTMAN_CORE_SOURCES
src/core/config.c
src/core/logging.c
src/core/notification.c
src/core/utils.c)
set(HOSTMAN_UI_SOURCES
src/ui/ui.c)
set(HOSTMAN_CLI_SOURCES
src/cli/cli.c
src/cli/tui.c)
set(HOSTMAN_NETWORK_SOURCES
src/network/network.c
src/network/hosts.c)
set(HOSTMAN_CRYPTO_SOURCES
src/crypto/encryption.c)
set(HOSTMAN_STORAGE_SOURCES
src/storage/database.c)
set(HOSTMAN_SOURCES
src/main.c
${HOSTMAN_CORE_SOURCES}
${HOSTMAN_UI_SOURCES}
${HOSTMAN_CLI_SOURCES}
${HOSTMAN_NETWORK_SOURCES}
${HOSTMAN_CRYPTO_SOURCES}
${HOSTMAN_STORAGE_SOURCES})
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include
${CURL_INCLUDE_DIRS}
${SQLite3_INCLUDE_DIRS}
${JSON_INCLUDE_DIR}
${OPENSSL_INCLUDE_DIR}
${LIBNOTIFY_INCLUDE_DIRS}
)
add_executable(hostman ${HOSTMAN_SOURCES})
target_link_libraries(hostman
${CURL_LIBRARIES}
${SQLite3_LIBRARY}
cJSON
${OPENSSL_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
m)
if(HOSTMAN_USE_NOTIFY AND LIBNOTIFY_FOUND)
target_link_libraries(hostman ${LIBNOTIFY_LIBRARIES})
endif()
if(HOSTMAN_USE_TUI)
target_link_libraries(hostman ${CURSES_LIBRARIES})
endif()
install(TARGETS hostman DESTINATION bin)
install(DIRECTORY include/hostman DESTINATION include)
install(DIRECTORY include/hostman/ui DESTINATION include/hostman)
install(FILES man/hostman.1 DESTINATION share/man/man1)
install(FILES man/hostman-config.5 DESTINATION share/man/man5)
option(BUILD_DOCS "Build documentation" OFF)
if(BUILD_DOCS)
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DOXYGEN_IN ${CMAKE_CURRENT_SOURCE_DIR}/docs/Doxyfile.in)
set(DOXYGEN_OUT ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
configure_file(${DOXYGEN_IN} ${DOXYGEN_OUT} @ONLY)
add_custom_target(docs
COMMAND ${DOXYGEN_EXECUTABLE} ${DOXYGEN_OUT}
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen"
VERBATIM)
endif()
endif()
find_program(CLANG_FORMAT "clang-format")
if(CLANG_FORMAT)
message(STATUS "Found clang-format: ${CLANG_FORMAT}")
file(GLOB_RECURSE ALL_SOURCE_FILES
"${CMAKE_SOURCE_DIR}/src/*.c"
"${CMAKE_SOURCE_DIR}/src/*.h"
"${CMAKE_SOURCE_DIR}/include/hostman/*.h"
)
add_custom_target(format
COMMAND ${CLANG_FORMAT} -i -style=file ${ALL_SOURCE_FILES}
COMMENT "Formatting source code with clang-format"
VERBATIM)
add_custom_target(check-format
COMMAND ${CLANG_FORMAT} --dry-run --Werror -style=file ${ALL_SOURCE_FILES}
COMMENT "Checking code formatting with clang-format"
VERBATIM)
else()
message(STATUS "clang-format not found, format target will not be available")
add_custom_target(format
COMMAND echo "clang-format not found, please install it to enable automatic formatting"
VERBATIM)
endif()