forked from sysrepo/sysrepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
317 lines (264 loc) · 10.6 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
cmake_minimum_required(VERSION 2.8.12)
project(sysrepo)
set(SYSREPO_DESC "YANG-based system repository for all-around configuration management.")
# include custom Modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
include(GNUInstallDirs)
include(CheckSymbolExists)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckIncludeFile)
include(UseCompat)
if(POLICY CMP0075)
cmake_policy(SET CMP0075 NEW)
endif()
# osx specific
set(CMAKE_MACOSX_RPATH TRUE)
# set default build type if not specified by user
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Debug)
endif()
string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
if(NOT UNIX)
message(FATAL_ERROR "Only Unix-like systems are supported.")
endif()
# Version of the project
# Generic version of not only the library. Major version is reserved for really big changes of the project,
# minor version changes with added functionality (new tool, functionality of the tool or library, ...) and
# micro version is changed with a set of small changes or bugfixes anywhere in the project.
set(SYSREPO_MAJOR_VERSION 1)
set(SYSREPO_MINOR_VERSION 4)
set(SYSREPO_MICRO_VERSION 70)
set(SYSREPO_VERSION ${SYSREPO_MAJOR_VERSION}.${SYSREPO_MINOR_VERSION}.${SYSREPO_MICRO_VERSION})
# Version of the library
# Major version is changed with every backward non-compatible API/ABI change, minor version changes
# with backward compatible change and micro version is connected with any internal change of the library.
set(SYSREPO_MAJOR_SOVERSION 5)
set(SYSREPO_MINOR_SOVERSION 5)
set(SYSREPO_MICRO_SOVERSION 12)
set(SYSREPO_SOVERSION_FULL ${SYSREPO_MAJOR_SOVERSION}.${SYSREPO_MINOR_SOVERSION}.${SYSREPO_MICRO_SOVERSION})
set(SYSREPO_SOVERSION ${SYSREPO_MAJOR_SOVERSION})
# Version of libyang library that this sysrepo depends on
set(LIBYANG_DEP_VERSION 1.0.182)
set(LIBYANG_DEP_SOVERSION 1.9.0)
set(LIBYANG_DEP_SOVERSION_MAJOR 1)
# options
if((CMAKE_BUILD_TYPE_LOWER STREQUAL debug) OR (CMAKE_BUILD_TYPE_LOWER STREQUAL package))
option(ENABLE_TESTS "Build tests" ON)
option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" ON)
else()
option(ENABLE_TESTS "Build tests" OFF)
option(ENABLE_VALGRIND_TESTS "Build tests with valgrind" OFF)
endif()
option(BUILD_EXAMPLES "Build examples." ON)
option(ENABLE_COVERAGE "Build code coverage report from tests" OFF)
if(ENABLE_COVERAGE)
find_program(PATH_GCOV NAMES gcov)
if(NOT PATH_GCOV)
message(WARNING "'gcov' executable not found! Disabling building code coverage report.")
set(ENABLE_COVERAGE OFF)
endif()
find_program(PATH_LCOV NAMES lcov)
if(NOT PATH_GCOV)
message(WARNING "'lcov' executable not found! Disabling building code coverage report.")
set(ENABLE_COVERAGE OFF)
endif()
find_program(PATH_GENHTML NAMES genhtml)
if(NOT PATH_GCOV)
message(WARNING "'genhtml' executable not found! Disabling building code coverage report.")
set(ENABLE_COVERAGE OFF)
endif()
if(NOT CMAKE_COMPILER_IS_GNUCC)
message(WARNING "Compiler is not gcc! Coverage may break the tests!")
endif()
if(ENABLE_COVERAGE)
set(CMAKE_C_FLAGS_COVERAGE "${CMAKE_C_FLAGS} --coverage -fprofile-arcs -ftest-coverage")
endif()
endif()
# binding options
option(GEN_LANGUAGE_BINDINGS "Enable library bindings for different languages." OFF)
option(GEN_CPP_BINDINGS "Enable C++ bindings." ON)
option(BUILD_CPP_EXAMPLES "Enable C++ example application compilation." ON)
option(GEN_PYTHON_BINDINGS "Enable Python bindings." ON)
option(ENABLE_PYTHON_TESTS "Enable Python tests." ON)
# compilation flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_C_FLAGS_COVERAGE} -Wall -Wextra -Wpedantic -std=c99")
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2")
set(CMAKE_C_FLAGS_PACKAGE "-g -O2 -DNDEBUG")
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
# ietf-yang-library revision
set(YANGLIB_REVISION "2019-01-04" CACHE STRING
"YANG module ietf-yang-library revision to implement. Only 2019-01-04 and 2016-06-21 are supported.")
if(NOT ${YANGLIB_REVISION} STREQUAL "2019-01-04" AND NOT ${YANGLIB_REVISION} STREQUAL "2016-06-21")
message(FATAL_ERROR "Unsupported ietf-yang-library revision ${YANGLIB_REVISION} specified!")
endif()
message(STATUS "ietf-yang-library revision: ${YANGLIB_REVISION}")
# paths
if(NOT REPO_PATH)
if(CMAKE_BUILD_TYPE_LOWER STREQUAL debug)
set(REPO_PATH "${CMAKE_BINARY_DIR}/repository")
else()
set(REPO_PATH "/etc/sysrepo")
endif()
endif()
set(REPO_PATH "${REPO_PATH}" CACHE PATH "Repository path, contains configuration schema and data files.")
message(STATUS "Sysrepo repository: ${REPO_PATH}")
set(STARTUP_DATA_PATH "${STARTUP_DATA_PATH}" CACHE PATH "Startup data path, contains startup datastore module files.")
if(STARTUP_DATA_PATH)
message(STATUS "Startup data path: ${STARTUP_DATA_PATH}")
else()
message(STATUS "Startup data path: ${REPO_PATH}/data")
endif()
set(NOTIFICATION_PATH "${NOTIFICATION_PATH}" CACHE PATH "Notification path, contains stored notifications.")
if(NOTIFICATION_PATH)
message(STATUS "Notification path: ${NOTIFICATION_PATH}")
else()
message(STATUS "Notification path: ${REPO_PATH}/data/notif")
endif()
set(YANG_MODULE_PATH "${YANG_MODULE_PATH}" CACHE PATH "YANG module path, contains all used YANG module files.")
if(YANG_MODULE_PATH)
message(STATUS "YANG module path: ${YANG_MODULE_PATH}")
else()
message(STATUS "YANG module path: ${REPO_PATH}/yang")
endif()
if(NOT PLUGINS_PATH)
set(PLUGINS_PATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/sysrepo/plugins/" CACHE PATH
"Sysrepo plugin daemon plugins path.")
endif()
message(STATUS "SRPD plugins path: ${PLUGINS_PATH}")
# objects
set(LIB_SRC
src/sysrepo.c
src/common.c
src/log.c
src/replay.c
src/modinfo.c
src/edit_diff.c
src/lyd_mods.c
src/shm_main.c
src/shm_mod.c
src/shm_sub.c
src/utils/values.c
src/utils/xpath.c)
set (SYSREPOCTL_SRC
src/executables/sysrepoctl.c)
set (SYSREPOCFG_SRC
src/executables/sysrepocfg.c)
set (SYSREPOPLUGIND_SRC
src/executables/sysrepo-plugind.c)
# use compat
use_compat()
# sysrepo
set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
add_library(srobj OBJECT ${LIB_SRC})
set_target_properties(srobj PROPERTIES COMPILE_FLAGS "-fvisibility=hidden")
add_library(sysrepo SHARED $<TARGET_OBJECTS:srobj> $<TARGET_OBJECTS:compat>)
set_target_properties(sysrepo PROPERTIES VERSION ${SYSREPO_SOVERSION_FULL} SOVERSION ${SYSREPO_SOVERSION})
# sysrepoctl tool
add_executable(sysrepoctl ${SYSREPOCTL_SRC} $<TARGET_OBJECTS:compat>)
target_link_libraries(sysrepoctl sysrepo)
# sysrepocfg tool
add_executable(sysrepocfg ${SYSREPOCFG_SRC} $<TARGET_OBJECTS:compat>)
target_link_libraries(sysrepocfg sysrepo)
# sysrepo-plugind daemon
add_executable(sysrepo-plugind ${SYSREPOPLUGIND_SRC} $<TARGET_OBJECTS:compat>)
target_link_libraries(sysrepo-plugind sysrepo ${CMAKE_DL_LIBS})
# include repository files with highest priority
include_directories("${PROJECT_SOURCE_DIR}/src")
include_directories(${PROJECT_BINARY_DIR})
# dependencies
# librt (shm_open, shm_unlink, not required on OSX or QNX)
find_library(LIBRT rt)
if(LIBRT)
target_link_libraries(sysrepo ${LIBRT})
endif()
# atomic
check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_ATOMIC)
if(HAVE_ATOMIC)
target_link_libraries(sysrepo atomic)
endif()
# libyang, check version
find_package(LibYANG ${LIBYANG_DEP_SOVERSION} REQUIRED)
target_link_libraries(sysrepo ${LIBYANG_LIBRARIES})
include_directories(${LIBYANG_INCLUDE_DIRS})
# pthread
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
find_package(Threads REQUIRED)
target_link_libraries(sysrepo ${CMAKE_THREAD_LIBS_INIT})
set(CMAKE_REQUIRED_LIBRARIES pthread)
# required functions
set(CMAKE_REQUIRED_DEFINITIONS "-D_GNU_SOURCE;-D_DEFAULT_SOURCE")
check_function_exists(pthread_mutex_timedlock SR_HAVE_PTHREAD_MUTEX_TIMEDLOCK)
check_symbol_exists(eaccess "unistd.h" SR_HAVE_EACCESS)
if(NOT SR_HAVE_EACCESS)
message(WARNING "Function eaccess() is not supported, using access() instead which may "
"change results of access control checks!")
endif()
check_include_file("stdatomic.h" SR_HAVE_STDATOMIC)
check_symbol_exists(mkstemps "stdlib.h" SR_HAVE_MKSTEMPS)
unset(CMAKE_REQUIRED_DEFINITIONS)
# generate files
configure_file("${PROJECT_SOURCE_DIR}/src/common.h.in" "${PROJECT_BINARY_DIR}/common.h" ESCAPE_QUOTES @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/src/executables/bin_common.h.in" "${PROJECT_BINARY_DIR}/bin_common.h" ESCAPE_QUOTES @ONLY)
configure_file("${PROJECT_SOURCE_DIR}/sysrepo.pc.in" "${PROJECT_BINARY_DIR}/sysrepo.pc" @ONLY)
# installation
install(TARGETS sysrepo DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${PROJECT_SOURCE_DIR}/src/sysrepo.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
install(FILES ${PROJECT_SOURCE_DIR}/src/utils/values.h ${PROJECT_SOURCE_DIR}/src/utils/xpath.h
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/sysrepo)
install(TARGETS sysrepoctl sysrepocfg sysrepo-plugind DESTINATION ${CMAKE_INSTALL_BINDIR})
install(FILES "${PROJECT_BINARY_DIR}/sysrepo.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
# examples
if(BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# tests
if(ENABLE_TESTS)
find_package(CMocka 1.0.0)
if(CMOCKA_FOUND)
enable_testing()
add_subdirectory(tests)
else()
message(STATUS "Disabling tests because of missing CMocka.")
set(ENABLE_BUILD_TESTS NO)
endif()
endif()
# bindings
if(GEN_LANGUAGE_BINDINGS)
add_subdirectory(bindings)
endif()
# packages
add_subdirectory(packages)
# doxygen documentation
find_package(Doxygen)
if(DOXYGEN_FOUND)
find_program(DOT_PATH dot PATH_SUFFIXES graphviz2.38/bin graphviz/bin)
if(DOT_PATH)
set(HAVE_DOT "YES")
else()
set(HAVE_DOT "NO")
message(AUTHOR_WARNING "Doxygen: to generate UML diagrams please install graphviz")
endif()
if(GEN_LANGUAGE_BINDINGS AND GEN_CPP_BINDINGS)
set(CPP_HEADERS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/bindings/cpp/src)
endif()
add_custom_target(doc
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
configure_file(Doxyfile.in Doxyfile)
endif()
# phony target for clearing sysrepo SHM
add_custom_target(shm_clean
COMMAND rm -rf /dev/shm/sr_*
COMMAND rm -rf /dev/shm/srsub_*
)
# phony target for clearing all sysrepo data
add_custom_target(sr_clean
COMMAND rm -rf ${REPO_PATH}
DEPENDS shm_clean
)
# uninstall
add_custom_target(uninstall "${CMAKE_COMMAND}" -P "${CMAKE_MODULE_PATH}/uninstall.cmake")
add_custom_target(uninstall_with_repo "${CMAKE_COMMAND}" -P "${CMAKE_MODULE_PATH}/uninstall.cmake"
COMMAND rm -rf ${REPO_PATH})