blob: 3ecbe0bc65a3187d87bb109fa3a3e1c6b58b9910 [file] [log] [blame]
Jan Kundrátd9d26a92018-02-22 12:49:21 +01001project(netconf-cli LANGUAGES CXX)
2cmake_minimum_required(VERSION 3.0)
Jan Kundrát763db1e2018-05-25 15:43:51 +02003set(CMAKE_CXX_STANDARD 17)
Jan Kundrátd9d26a92018-02-22 12:49:21 +01004set(CMAKE_CXX_STANDARD_REQUIRED ON)
Jan Kundrát8569e1b2020-01-16 13:47:19 +01005set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
Jan Kundrátd47f6552018-03-02 13:40:11 +01006
7include(GNUInstallDirs)
8
9# Set a default build type if none was specified. This was shamelessly stolen
10# from VTK's cmake setup because these guys produce both CMake and a project that
11# manipulates this variable, and the web is full of posts where people say that
12# it is apparently evil to just set the build type in a way an earlier version of
13# this patch did. Oh, and the location of this check/update matters, apparently.
14#
15# Yes, this is just plain crazy.
16if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
17 message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
18 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
19 # Set the possible values of build type for cmake-gui
20 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
21endif()
22
23# -Werror is not a default for sanity reasons (one cannot know what warnings a future compiler
24# might bring along), but it's a default in debug mode. The idea is that developers should care
25# about a warning-free build, and that this is easier than messing with yet another configure option.
26set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
27
28# I don't want to duplicate the compiler's optimizations
29set(CMAKE_CXX_FLAGS "-O2 ${CMAKE_CXX_FLAGS}")
30
31# Build warnings are useful tools (and this project should be warning-free anyway), enable them on all
32# configurations. They are warnings, not errors.
Václav Kubernát84834142020-02-07 19:25:55 +010033set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual -Wimplicit-fallthrough ${CMAKE_CXX_FLAGS}")
Jan Kundrátfb831902018-05-26 18:58:52 +020034
35if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
36 set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}")
37endif()
Jan Kundrátd47f6552018-03-02 13:40:11 +010038
Jan Kundrátdc2b0722018-03-02 14:13:37 +010039set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
40
41add_custom_target(git-version-cmake-ide
42 cmake/ProjectGitVersion.cmake
43 cmake/ProjectGitVersionRunner.cmake
44 )
45include(cmake/ProjectGitVersion.cmake)
46prepare_git_version(NETCONF_CLI_VERSION "0.0")
47
Jan Kundrát608818b2018-03-02 13:43:53 +010048find_package(Doxygen)
49option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
50
Jan Kundrátd47f6552018-03-02 13:40:11 +010051find_package(docopt REQUIRED)
Jan Kundrát03caee82018-03-08 14:16:56 +010052find_package(Boost REQUIRED)
Jan Kundrát8d8efe82019-10-18 10:21:36 +020053find_library(REPLXX_LIBRARY NAMES replxx replxx-d REQUIRED)
Václav Kubernáta395d332019-02-13 16:49:20 +010054find_path(REPLXX_PATH replxx.hxx)
55if("${REPLXX_PATH}" STREQUAL REPLXX_PATH-NOTFOUND)
56 message(FATAL_ERROR "Cannot find the \"replxx.hxx\" include file for the replxx library.")
57endif()
Jan Kundrát608818b2018-03-02 13:43:53 +010058
Jan Kundráte05448a2018-06-13 15:54:33 +020059find_package(PkgConfig)
Václav Kubernát654303f2020-07-31 13:16:54 +020060pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.190 IMPORTED_TARGET libyang)
61pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.4.79 IMPORTED_TARGET sysrepo)
62pkg_check_modules(LIBNETCONF2 REQUIRED libnetconf2>=1.1.32 IMPORTED_TARGET libnetconf2)
Jan Kundráte05448a2018-06-13 15:54:33 +020063
Václav Kubernátb96eef72018-05-04 19:10:22 +020064# we don't need filename tracking, and we prefer to use header-only Boost
65add_definitions(-DBOOST_SPIRIT_X3_NO_FILESYSTEM)
66
Jan Kundrátbb525b42020-02-04 11:56:59 +010067include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
68
Václav Kubernát7edb5372019-12-13 12:40:49 +010069add_library(ast_values STATIC
70 src/ast_values.cpp
71 )
Jan Kundrát688041f2020-03-31 10:02:49 +020072target_link_libraries(ast_values PUBLIC Boost::boost)
73
74add_library(path STATIC
75 src/ast_path.cpp
76 )
77target_link_libraries(path PUBLIC ast_values Boost::boost)
Václav Kubernát7edb5372019-12-13 12:40:49 +010078
Václav Kubernát3a99f002020-03-31 02:27:41 +020079add_library(leaf_data_type STATIC
80 src/leaf_data_type.cpp
81 )
82target_link_libraries(leaf_data_type ast_values)
83
Václav Kubernát7edb5372019-12-13 12:40:49 +010084add_library(utils STATIC
85 src/utils.cpp
86 )
Jan Kundrát688041f2020-03-31 10:02:49 +020087target_link_libraries(utils path ast_values)
Václav Kubernát7edb5372019-12-13 12:40:49 +010088
Jan Kundrát578347c2018-08-09 15:02:06 +020089add_library(schemas STATIC
Václav Kubernátbddbb172018-06-13 16:27:39 +020090 src/static_schema.cpp
Václav Kubernát48fc3832018-05-28 14:21:22 +020091 src/schema.cpp
Jan Kundrát578347c2018-08-09 15:02:06 +020092 )
Václav Kubernát3a99f002020-03-31 02:27:41 +020093target_link_libraries(schemas PUBLIC path leaf_data_type Boost::boost)
Jan Kundrát578347c2018-08-09 15:02:06 +020094
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020095add_library(datastoreaccess STATIC
96 src/datastore_access.cpp
Václav Kubernátab612e92019-11-26 19:51:31 +010097 src/data_query.cpp
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020098 )
99target_link_libraries(datastoreaccess PUBLIC Boost::boost)
100
Václav Kubernát80aacc02018-08-22 17:41:54 +0200101add_library(sysrepoaccess STATIC
102 src/sysrepo_access.cpp
103 )
Václav Kubernátc31bd602019-03-07 11:44:48 +0100104
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200105target_link_libraries(sysrepoaccess PUBLIC datastoreaccess ast_values PRIVATE PkgConfig::SYSREPO PkgConfig::LIBYANG)
Václav Kubernát80aacc02018-08-22 17:41:54 +0200106
Václav Kubernátc31bd602019-03-07 11:44:48 +0100107add_library(netconfaccess STATIC
108 src/netconf-client.cpp
109 src/netconf_access.cpp
110 )
111
Václav Kubernát3ea893e2020-10-19 16:33:01 +0200112target_link_libraries(netconfaccess PUBLIC datastoreaccess yangschema ast_values utils PkgConfig::LIBNETCONF2 PRIVATE PkgConfig::LIBYANG)
Václav Kubernátc31bd602019-03-07 11:44:48 +0100113
Václav Kubernát74487df2020-06-04 01:29:28 +0200114add_library(yangaccess STATIC
115 src/yang_access.cpp
116 )
117
Václav Kubernát3ea893e2020-10-19 16:33:01 +0200118target_link_libraries(yangaccess PUBLIC datastoreaccess yangschema PRIVATE PkgConfig::LIBYANG)
Václav Kubernát74487df2020-06-04 01:29:28 +0200119
Václav Kubernát0d4db442018-07-18 17:18:43 +0200120add_library(yangschema STATIC
121 src/yang_schema.cpp
Václav Kubernát02a71152020-01-21 14:52:51 +0100122 src/libyang_utils.cpp
Václav Kubernát0d4db442018-07-18 17:18:43 +0200123 )
Jan Kundrát9f71d772020-04-09 13:29:36 +0200124target_link_libraries(yangschema PUBLIC schemas utils PRIVATE PkgConfig::LIBYANG)
Václav Kubernát0d4db442018-07-18 17:18:43 +0200125
Jan Kundrát578347c2018-08-09 15:02:06 +0200126add_library(parser STATIC
Václav Kubernát48fc3832018-05-28 14:21:22 +0200127 src/parser.cpp
Václav Kubernát24df80e2018-06-06 15:18:03 +0200128 src/ast_commands.cpp
Václav Kubernát195eeea2018-05-18 13:52:36 +0200129 src/parser_context.cpp
Václav Kubernát96344a12018-05-28 16:33:39 +0200130 src/interpreter.cpp
Václav Kubernát329c6c32019-02-06 16:41:53 +0100131 src/ast_handlers.cpp
Václav Kubernátcb3af402020-02-12 16:49:17 +0100132 src/completion.cpp
Jan Kundrátdc2b0722018-03-02 14:13:37 +0100133 )
Václav Kubernát7edb5372019-12-13 12:40:49 +0100134target_link_libraries(parser schemas utils ast_values)
Václav Kubernátd6662962018-03-22 17:41:33 +0100135
Václav Kubernát48e9dfa2020-07-08 10:55:12 +0200136add_library(proxydatastore STATIC
137 src/proxy_datastore.cpp
138 )
Václav Kubernáte7248b22020-06-26 15:38:59 +0200139target_link_libraries(proxydatastore PUBLIC datastoreaccess yangaccess)
Václav Kubernát48e9dfa2020-07-08 10:55:12 +0200140
Václav Kubernát74487df2020-06-04 01:29:28 +0200141# Links libraries, that aren't specific to a datastore type
142function(cli_link_required cli_target)
143 target_include_directories(${cli_target} PRIVATE ${REPLXX_PATH})
Václav Kubernát48e9dfa2020-07-08 10:55:12 +0200144 target_link_libraries(${cli_target} proxydatastore yangschema docopt parser ${REPLXX_LIBRARY})
Václav Kubernát74487df2020-06-04 01:29:28 +0200145 add_dependencies(${cli_target} target-NETCONF_CLI_VERSION)
146 target_include_directories(${cli_target} PRIVATE ${PROJECT_BINARY_DIR})
147endfunction()
148
Václav Kubernátb79f3ca2020-02-04 15:56:01 +0100149add_executable(sysrepo-cli
150 src/cli.cpp
Václav Kubernátd6662962018-03-22 17:41:33 +0100151 )
Václav Kubernátb79f3ca2020-02-04 15:56:01 +0100152target_compile_definitions(sysrepo-cli PRIVATE SYSREPO_CLI)
Václav Kubernát74487df2020-06-04 01:29:28 +0200153target_link_libraries(sysrepo-cli sysrepoaccess)
154cli_link_required(sysrepo-cli)
Václav Kubernát2b684612018-08-09 18:55:24 +0200155
Václav Kubernát74487df2020-06-04 01:29:28 +0200156add_executable(yang-cli
157 src/cli.cpp
158 )
159target_compile_definitions(yang-cli PRIVATE YANG_CLI)
160cli_link_required(yang-cli)
161target_link_libraries(yang-cli yangaccess)
Václav Kubernát619e6542020-06-29 14:13:43 +0200162if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
163 target_link_libraries(yang-cli c++experimental)
164elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1)
165 target_link_libraries(yang-cli stdc++fs)
166endif()
167
Václav Kubernát74487df2020-06-04 01:29:28 +0200168
Jan Kundrátdc2b0722018-03-02 14:13:37 +0100169
Jan Kundrát5c805212018-03-02 13:57:12 +0100170include(CTest)
171if(BUILD_TESTING)
Jan Kundrátc381e632019-03-14 13:39:11 +0100172 find_package(trompeloeil 33 REQUIRED)
Jan Kundráta33cf082019-03-28 11:55:57 +0100173 find_package(doctest 2.3.1 REQUIRED)
Jan Kundrát5c805212018-03-02 13:57:12 +0100174
Jan Kundráta33cf082019-03-28 11:55:57 +0100175 add_library(DoctestIntegration STATIC
176 tests/doctest_integration.cpp
Václav Kubernát26b56082020-02-03 18:28:56 +0100177 tests/trompeloeil_doctest.hpp
Jan Kundrátc381e632019-03-14 13:39:11 +0100178 tests/wait-a-bit-longer.cpp
Jan Kundrát5c805212018-03-02 13:57:12 +0100179 )
Jan Kundráta33cf082019-03-28 11:55:57 +0100180 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/)
Václav Kubernátc31bd602019-03-07 11:44:48 +0100181 target_link_libraries(DoctestIntegration doctest::doctest trompeloeil)
Jan Kundráta33cf082019-03-28 11:55:57 +0100182 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
Jan Kundrát5c805212018-03-02 13:57:12 +0100183
Jan Kundrátbb525b42020-02-04 11:56:59 +0100184 add_library(sysreposubscription STATIC
185 tests/mock/sysrepo_subscription.cpp
186 )
187 target_link_libraries(sysreposubscription PUBLIC datastoreaccess PRIVATE PkgConfig::SYSREPO)
188
Václav Kubernát73109382018-09-14 19:52:03 +0200189 if (NOT SYSREPOCTL_EXECUTABLE)
190 find_program(SYSREPOCTL_EXECUTABLE sysrepoctl)
191 endif()
192 if (NOT SYSREPOCTL_EXECUTABLE)
193 message(FATAL_ERROR "Unable to find sysrepoctl, set SYSREPOCTL_EXECUTABLE manually.")
194 endif()
195
Václav Kubernát88324812019-06-26 17:36:29 +0200196 if (NOT SYSREPOCFG_EXECUTABLE)
197 find_program(SYSREPOCFG_EXECUTABLE sysrepocfg)
198 endif()
199 if (NOT SYSREPOCFG_EXECUTABLE)
200 message(FATAL_ERROR "Unable to find sysrepocfg, set SYSREPOCFG_EXECUTABLE manually.")
201 endif()
Václav Kubernát73109382018-09-14 19:52:03 +0200202
Václav Kubernátc31bd602019-03-07 11:44:48 +0100203 if (NOT NETOPEER2_EXECUTABLE)
204 find_program(NETOPEER2_EXECUTABLE netopeer2-server)
205 endif()
206 if (NOT NETOPEER2_EXECUTABLE)
207 message(FATAL_ERROR "Unable to find netopeer2-server, set NETOPEER2_EXECUTABLE manually.")
208 endif()
209
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200210 pkg_get_variable(SYSREPO_SR_REPO_PATH sysrepo SR_REPO_PATH)
Václav Kubernátc31bd602019-03-07 11:44:48 +0100211
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200212 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_repositories)
213 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_sockets)
214
215 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/yang_access_test_vars.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/yang_access_test_vars.hpp @ONLY)
Václav Kubernát7d478642019-11-22 17:38:11 +0100216
Václav Kubernát88324812019-06-26 17:36:29 +0200217 function(cli_test name)
218 if (${ARGC} GREATER 1) # this is how CMake does optional arguments
219 add_executable(test_${name}
220 tests/${ARGV1}
221 )
222 else()
223 add_executable(test_${name}
224 tests/${name}.cpp
225 )
Jan Kundrát5c805212018-03-02 13:57:12 +0100226 endif()
Václav Kubernát43908fb2020-01-02 19:05:51 +0100227 target_link_libraries(test_${name} DoctestIntegration parser datastoreaccess)
Václav Kubernát88324812019-06-26 17:36:29 +0200228 if(NOT CMAKE_CROSSCOMPILING)
229 add_test(test_${name} test_${name})
230 endif()
231 target_include_directories(test_${name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
Jan Kundrátcc4c1f22018-08-09 15:00:03 +0200232 endfunction()
Václav Kubernát88324812019-06-26 17:36:29 +0200233
Václav Kubernát1acf4f12020-01-31 15:54:34 +0100234 function(datastore_test_impl name model backend)
Václav Kubernát7d478642019-11-22 17:38:11 +0100235 set(TESTNAME test_${name}_${backend})
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200236
Václav Kubernát7d478642019-11-22 17:38:11 +0100237 cli_test(${name}_${backend} ${name}.cpp)
Václav Kubernát7d478642019-11-22 17:38:11 +0100238 target_include_directories(${TESTNAME} PRIVATE ${PROJECT_SOURCE_DIR}/tests/mock)
239 if (${backend} STREQUAL "sysrepo")
240 target_link_libraries(${TESTNAME} sysrepoaccess)
241 elseif (${backend} STREQUAL "netconf")
242 target_link_libraries(${TESTNAME} netconfaccess)
Václav Kubernát74487df2020-06-04 01:29:28 +0200243 elseif (${backend} STREQUAL "yang")
244 target_link_libraries(${TESTNAME} yangaccess)
Václav Kubernát7d478642019-11-22 17:38:11 +0100245 else()
246 message(FATAL_ERROR "Unknown backend ${backend}")
247 endif()
Václav Kubernát3ea893e2020-10-19 16:33:01 +0200248 target_link_libraries(${TESTNAME} yangschema sysreposubscription proxydatastore PkgConfig::SYSREPO)
Václav Kubernát7d478642019-11-22 17:38:11 +0100249
250 target_compile_definitions(${TESTNAME} PRIVATE ${backend}_BACKEND)
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200251 set_tests_properties(${TESTNAME} PROPERTIES FIXTURES_REQUIRED ${TESTNAME}_setup)
252
253 add_test(NAME ${TESTNAME}_init COMMAND ${CMAKE_CURRENT_BINARY_DIR}/init_datastore.bash "${model}" "${backend}")
254 set_tests_properties(${TESTNAME}_init PROPERTIES FIXTURES_SETUP ${TESTNAME}_setup)
255 add_test(NAME ${TESTNAME}_cleanup COMMAND ${CMAKE_CURRENT_BINARY_DIR}/cleanup_datastore.bash "${backend}")
256 set_tests_properties(${TESTNAME}_cleanup PROPERTIES FIXTURES_CLEANUP ${TESTNAME}_setup)
257
258 set_property(TEST ${TESTNAME} ${TESTNAME}_init ${TESTNAME}_cleanup APPEND PROPERTY ENVIRONMENT
259 "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/${TESTNAME}"
260 "SYSREPO_SHM_PREFIX=netconf-cli_${TESTNAME}"
261 "NETOPEER_SOCKET=${CMAKE_CURRENT_BINARY_DIR}/test_sockets/${TESTNAME}.sock"
262 )
263
Václav Kubernát7d478642019-11-22 17:38:11 +0100264 endfunction()
265
Václav Kubernát1acf4f12020-01-31 15:54:34 +0100266 function(datastore_test name model)
267 datastore_test_impl(${name} ${model} sysrepo)
268 datastore_test_impl(${name} ${model} netconf)
Václav Kubernát74487df2020-06-04 01:29:28 +0200269 datastore_test_impl(${name} ${model} yang)
Václav Kubernát88324812019-06-26 17:36:29 +0200270 endfunction()
271
Václav Kubernátd6662962018-03-22 17:41:33 +0100272 cli_test(cd)
Václav Kubernát11afac72018-07-18 14:59:53 +0200273 cli_test(ls)
Václav Kubernátb61336d2018-05-28 17:35:03 +0200274 cli_test(presence_containers)
Václav Kubernát07204242018-06-04 18:12:09 +0200275 cli_test(leaf_editing)
Václav Kubernát3a99f002020-03-31 02:27:41 +0200276 target_link_libraries(test_leaf_editing leaf_data_type)
Václav Kubernát0d4db442018-07-18 17:18:43 +0200277 cli_test(yang)
278 target_link_libraries(test_yang yangschema)
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100279 cli_test(utils)
280 cli_test(path_completion)
Václav Kubernát57272422019-02-08 12:48:24 +0100281 cli_test(command_completion)
Václav Kubernát549b08f2020-05-14 22:19:36 +0200282 cli_test(set_value_completion)
283 target_link_libraries(test_set_value_completion leaf_data_type)
Václav Kubernátf5f64f02019-03-19 17:15:47 +0100284 cli_test(list_manipulation)
Václav Kubernát5452ede2020-06-10 12:05:11 +0200285 cli_test(interpreter)
Václav Kubernát48e9dfa2020-07-08 10:55:12 +0200286 target_link_libraries(test_interpreter proxydatastore)
Václav Kubernát5395e712019-12-03 18:24:33 +0100287 cli_test(path_utils)
Václav Kubernát7edb5372019-12-13 12:40:49 +0100288 target_link_libraries(test_path_utils path)
Václav Kubernát43908fb2020-01-02 19:05:51 +0100289 cli_test(keyvalue_completion)
Václav Kubernátc31bd602019-03-07 11:44:48 +0100290
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200291 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/init_datastore.bash.in
292 ${CMAKE_CURRENT_BINARY_DIR}/init_datastore.bash @ONLY)
293
294 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/cleanup_datastore.bash.in
295 ${CMAKE_CURRENT_BINARY_DIR}/cleanup_datastore.bash @ONLY)
296
297 datastore_test(datastore_access ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang)
298 datastore_test(data_query ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang)
Jan Kundrát5c805212018-03-02 13:57:12 +0100299endif()
300
Jan Kundrátcf5c6362020-01-16 22:54:47 +0100301option(WITH_PYTHON_BINDINGS "Create and install Python3 bindings for accessing datastores" OFF)
302if(WITH_PYTHON_BINDINGS)
303 set(PYBIND11_CPP_STANDARD -std=c++17)
304 find_package(pybind11 REQUIRED)
305 pybind11_add_module(netconf_cli_py src/python_netconf.cpp)
306 target_link_libraries(netconf_cli_py PUBLIC netconfaccess)
307
308 if(BUILD_TESTING)
Václav Kubernát654303f2020-07-31 13:16:54 +0200309 pybind11_add_module(sysrepo_subscription_py tests/mock/sysrepo_subscription_python.cpp)
310 target_link_libraries(sysrepo_subscription_py PUBLIC sysreposubscription utils)
311
Jan Kundrátcf5c6362020-01-16 22:54:47 +0100312 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/python_netconfaccess.py
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200313 ${CMAKE_CURRENT_BINARY_DIR}/tests_python_netconfaccess.py COPYONLY)
314
Jan Kundrátcf5c6362020-01-16 22:54:47 +0100315 add_test(NAME test_netconf_cli_py COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/tests_python_netconfaccess.py)
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200316 set_tests_properties(test_netconf_cli_py PROPERTIES FIXTURES_REQUIRED test_netconf_cli_py_setup)
317
318 add_test(NAME test_netconf_cli_py_init COMMAND ${CMAKE_CURRENT_BINARY_DIR}/init_datastore.bash ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang "netconf")
319 set_tests_properties(test_netconf_cli_py_init PROPERTIES FIXTURES_SETUP test_netconf_cli_py_setup)
320 add_test(NAME test_netconf_cli_py_cleanup COMMAND ${CMAKE_CURRENT_BINARY_DIR}/cleanup_datastore.bash "netconf")
321 set_tests_properties(test_netconf_cli_py_cleanup PROPERTIES FIXTURES_CLEANUP test_netconf_cli_py_setup)
322
323 set_property(TEST test_netconf_cli_py test_netconf_cli_py_init test_netconf_cli_py_cleanup APPEND PROPERTY ENVIRONMENT
324 "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/test_netconf_cli_py"
325 "SYSREPO_SHM_PREFIX=netconf-cli_test_netconf_cli_py"
326 "NETOPEER_SOCKET=${CMAKE_CURRENT_BINARY_DIR}/test_sockets/test_netconf_cli_py.sock"
327 )
Jan Kundrátcf5c6362020-01-16 22:54:47 +0100328
329 set(sanitizer_active OFF)
330 # FIXME: this just sucks. The detection is very unreliable (one could use something like
331 # -fsanitize=address,undefined and we are screwed), and especially clang's query for preload
332 # is obviously unportable because we hardcode host's architecture.
333 # This is super-ugly. Perhaps it would be better just to outright disable everything, but hey,
334 # I need to test this on my laptop where I'm using ASAN by default, and it kinda-almost-works
335 # there with just one patch to libyang :).
336 if (${CMAKE_CXX_FLAGS} MATCHES "-fsanitize=address")
337 set(sanitizer_active ON)
338 set(gcc_sanitizer_preload libasan.so)
339 set(clang_sanitizer_preload libclang_rt.asan-x86_64.so)
340 endif()
341
342 if (sanitizer_active)
343 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
344 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=${clang_sanitizer_preload}
345 OUTPUT_VARIABLE LIBxSAN_FULL_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
346 elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
347 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=${gcc_sanitizer_preload}
348 OUTPUT_VARIABLE LIBxSAN_FULL_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
349 else()
350 message(ERROR "Cannot determine correct sanitizer library for LD_PRELOAD")
351 endif()
352 set_property(TEST test_netconf_cli_py APPEND PROPERTY ENVIRONMENT
353 LD_PRELOAD=${LIBxSAN_FULL_PATH}
354 ASAN_OPTIONS=detect_leaks=0 # they look harmless, but they are annoying
355 )
356 endif()
357 endif()
358endif()
359
Jan Kundrát608818b2018-03-02 13:43:53 +0100360if(WITH_DOCS)
361 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
362 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
363 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
364 add_custom_target(doc
365 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
366 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
367 COMMENT "Generating API documentation with Doxygen"
368 VERBATIM
369 SOURCES ${doxyfile_in}
370 )
371endif()
Jan Kundrát10f49902018-05-22 17:01:45 +0200372
373install(TARGETS
Václav Kubernátb79f3ca2020-02-04 15:56:01 +0100374 sysrepo-cli
Jan Kundrát10f49902018-05-22 17:01:45 +0200375 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)