forked from sysrepo/sysrepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
235 lines (204 loc) · 9.14 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
cmake_minimum_required(VERSION 2.8)
project(sysrepo)
set(SYSREPO_DESC "YANG-based system repository")
include(GNUInstallDirs)
# setup version
set(SYSREPO_MAJOR_VERSION 0)
set(SYSREPO_MINOR_VERSION 5)
set(SYSREPO_MICRO_VERSION 11)
set(SYSREPO_VERSION ${SYSREPO_MAJOR_VERSION}.${SYSREPO_MINOR_VERSION}.${SYSREPO_MICRO_VERSION})
# setup bindings
set(GEN_LANGUAGE_BINDINGS 1 CACHE BOOL "Enable language bindings generation.")
set(GEN_PYTHON_BINDINGS 1 CACHE BOOL "Enable python bindings.")
set(GEN_LUA_BINDINGS 1 CACHE BOOL "Enable Lua bindings.")
set(GEN_CPP_BINDINGS 1 CACHE BOOL "Enable C++ bindings.")
set(BUILD_CPP_EXAMPLES 1 CACHE BOOL "Build C++ examples.")
set(GEN_JAVA_BINDINGS 0 CACHE BOOL "Enable Java bindings.")
set(GEN_PYTHON_VERSION "2" CACHE STRING "Python version")
set(GEN_LUA_VERSION "5.1" CACHE STRING "Lua version")
set(GEN_PYTHON2_TESTS 1 CACHE BOOL "Enable Python2 tests.")
# 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)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wpedantic -std=gnu11")
if(CMAKE_COMPILER_IS_GNUCC)
# disable strict aliasing in GCC, since it produces false alarams in libev
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-strict-aliasing")
endif()
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2")
set(CMAKE_C_FLAGS_DEBUG "-g -O0")
if(NOT UNIX)
message(FATAL_ERROR "Only Unix-like systems are supported.")
endif()
set(PLUGINS_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/sysrepo/plugins/" CACHE PATH "Sysrepo plugins directory.")
# set build-type specific settings
if(CMAKE_BUILD_TYPE_LOWER MATCHES "debug")
MESSAGE(STATUS "Preparing debug build of sysrepo v. ${SYSREPO_VERSION}")
set(DAEMON_PID_FILE "/tmp/sysrepod.pid" CACHE PATH "Sysrepo daemon PID file.")
set(DAEMON_SOCKET "/tmp/sysrepod.sock" CACHE PATH "Sysrepo deamon server socket path.")
set(PLUGIN_DAEMON_PID_FILE "/tmp/sysrepo-plugind.pid" CACHE PATH "Sysrepo plugin daemon PID file.")
set(SUBSCRIPTIONS_SOCKET_DIR "/tmp/sysrepo-subscriptions" CACHE PATH "Sysrepo subscriptions socket directory.")
else()
MESSAGE(STATUS "Preparing release build of sysrepo v. ${SYSREPO_VERSION}")
set(DAEMON_PID_FILE "/var/run/sysrepod.pid" CACHE PATH "Sysrepo daemon PID file.")
set(DAEMON_SOCKET "/var/run/sysrepod.sock" CACHE PATH "Sysrepo deamon server socket path.")
set(PLUGIN_DAEMON_PID_FILE "/var/run/sysrepo-plugind.pid" CACHE PATH "Sysrepo plugin daemon PID file.")
set(SUBSCRIPTIONS_SOCKET_DIR "/var/run/sysrepo-subscriptions" CACHE PATH "Sysrepo subscriptions socket directory.")
endif()
# location of system repository
if(CMAKE_BUILD_TYPE_LOWER MATCHES "debug")
set(REPOSITORY_LOC "${CMAKE_BINARY_DIR}/repository" CACHE PATH "System repository location, contains configuration schema and data files.")
else()
set(REPOSITORY_LOC "/etc/sysrepo" CACHE PATH "System repository location, contains configuration schema and data files.")
endif()
set(SCHEMA_SEARCH_DIR "${REPOSITORY_LOC}/yang/")
set(DATA_SEARCH_DIR "${REPOSITORY_LOC}/data/")
set(INTERNAL_SCHEMA_SEARCH_DIR "${REPOSITORY_LOC}/yang/internal/")
set(INTERNAL_DATA_SEARCH_DIR "${REPOSITORY_LOC}/data/internal/")
MESSAGE(STATUS "sysrepo repository location: ${REPOSITORY_LOC}")
# include custom Modules
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/inc")
# find required libraries
find_package(EV REQUIRED)
include_directories(${EV_INCLUDE_DIR})
find_package(YANG REQUIRED)
include_directories(${YANG_INCLUDE_DIR})
find_package(Protobuf-c REQUIRED)
include_directories(${PROTOBUF-C_INCLUDE_DIR})
# find libavl and/or libredblack
find_package(AVL)
find_package(RedBlack)
if((NOT AVL_FOUND) AND (NOT REDBLACK_FOUND))
MESSAGE(WARNING "libavl or libredblack must be installed.")
endif()
if(NOT DEFINED USE_AVL_LIB)
# no preference configured, try to find libavl and then libredblack
if(AVL_FOUND)
SET(USE_AVL_LIB 1 CACHE BOOL "Use libavl (1) or libredblack (0) for binary tree manipulations.")
else(AVL_FOUND)
if(REDBLACK_FOUND)
SET(USE_AVL_LIB 0 CACHE BOOL "Use libavl (1) or libredblack (0) for binary tree manipulations.")
endif(REDBLACK_FOUND)
endif(AVL_FOUND)
endif(NOT DEFINED USE_AVL_LIB)
if(USE_AVL_LIB)
if(AVL_FOUND)
MESSAGE(STATUS "libavl will be used for binary tree manipulations.")
include_directories(${AVL_INCLUDE_DIR})
else(AVL_FOUND)
MESSAGE(WARNING "libavl cannot be found.")
endif(AVL_FOUND)
else(USE_AVL_LIB)
if(REDBLACK_FOUND)
MESSAGE(STATUS "libredblack will be used for binary tree manipulations.")
include_directories(${REDBLACK_INCLUDE_DIR})
else(REDBLACK_FOUND)
MESSAGE(WARNING "libredblack cannot be found.")
endif(REDBLACK_FOUND)
endif(USE_AVL_LIB)
# check for non-portable functions and headers
set(CMAKE_REQUIRED_LIBRARIES pthread)
include(CheckFunctionExists)
include(CheckIncludeFiles)
include(CheckStructHasMember)
CHECK_FUNCTION_EXISTS(pthread_rwlockattr_setkind_np HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP)
CHECK_FUNCTION_EXISTS(getpeereid HAVE_GETPEEREID)
CHECK_FUNCTION_EXISTS(getpeerucred HAVE_GETPEERUCRED)
CHECK_FUNCTION_EXISTS(pthread_mutex_timedlock HAVE_TIMED_LOCK)
CHECK_INCLUDE_FILES(ucred.h HAVE_UCRED_H)
CHECK_FUNCTION_EXISTS(setfsuid HAVE_SETFSUID)
CHECK_STRUCT_HAS_MEMBER("struct stat" st_mtim "sys/stat.h" HAVE_STAT_ST_MTIM)
# user options
option (USE_SR_MEM_MGMT
"Use Sysrepo's own memory management (better overall performance but more difficult to track memory bugs)."
ON)
set(COMMIT_TIMEOUT 10 CACHE INTEGER "Commit operation timeout (in seconds).")
option (LOG_THREAD_ID
"If enabled, sysrepo logger will append thread ID (as well as function name) to each printed message."
OFF)
# add subdirectories
add_subdirectory(src)
# Examples
SET(BUILD_EXAMPLES 1 CACHE BOOL "Build examples and install example YANG models.")
if(BUILD_EXAMPLES)
MESSAGE(STATUS "Example code and YANG models will be built and installed.")
add_subdirectory(examples)
endif()
# Testing
SET(ENABLE_TESTS 1 CACHE BOOL "Enable unit tests.")
if(ENABLE_TESTS)
find_package(CMOCKA)
if(CMOCKA_FOUND)
MESSAGE(STATUS "CMocka found, tests are enabled.")
enable_testing()
add_subdirectory(tests)
else(CMOCKA_FOUND)
MESSAGE(WARNING "CMocka not found, tests are disabled.")
endif(CMOCKA_FOUND)
endif(ENABLE_TESTS)
# Documentation
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)
if(NOT MAN_INSTALL_DIR)
set(MAN_INSTALL_DIR share/man)
endif()
# install repository directories
install (DIRECTORY DESTINATION ${REPOSITORY_LOC} DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
install (DIRECTORY DESTINATION ${SCHEMA_SEARCH_DIR} DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
install (DIRECTORY DESTINATION ${DATA_SEARCH_DIR} DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
install (DIRECTORY DESTINATION ${INTERNAL_DATA_SEARCH_DIR} DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_EXECUTE
WORLD_READ WORLD_EXECUTE)
# install subscriptions socket directory
install (DIRECTORY DESTINATION ${SUBSCRIPTIONS_SOCKET_DIR} DIRECTORY_PERMISSIONS
OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_WRITE GROUP_EXECUTE
WORLD_READ WORLD_WRITE WORLD_EXECUTE)
# install plugins directory
install(DIRECTORY DESTINATION ${PLUGINS_DIR})
# install internal YANGs
install (FILES ${PROJECT_SOURCE_DIR}/yang/sysrepo-persistent-data.yang DESTINATION ${INTERNAL_SCHEMA_SEARCH_DIR})
install (FILES ${PROJECT_SOURCE_DIR}/yang/sysrepo-module-dependencies.yang DESTINATION ${INTERNAL_SCHEMA_SEARCH_DIR})
find_package(PkgConfig QUIET)
if(PKG_CONFIG_FOUND)
# generate and install pkg-config file
configure_file("libsysrepo.pc.in" "libsysrepo.pc" @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libsysrepo.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
endif()
# install doc (man)
install(FILES ${PROJECT_SOURCE_DIR}/doc/sysrepoctl.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
install(FILES ${PROJECT_SOURCE_DIR}/doc/sysrepocfg.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
if(WITH_SYSTEMD)
# systemd units
add_custom_target(systemd-units SOURCES
${PROJECT_SOURCE_DIR}/deploy/systemd/sysrepod.service
${PROJECT_SOURCE_DIR}/deploy/systemd/sysrepo-plugind.service
)
install(DIRECTORY ${PROJECT_SOURCE_DIR}/deploy/systemd/ DESTINATION "/lib/systemd/system"
FILES_MATCHING PATTERN "*.service")
endif()
if(GEN_LANGUAGE_BINDINGS)
add_subdirectory(swig)
endif()