blob: 533a77d605dc4252547157595c8a1a7cb2a3fc1f [file] [log] [blame]
Jan Kundrátd9d26a92018-02-22 12:49:21 +01001project(netconf-cli LANGUAGES CXX)
2cmake_minimum_required(VERSION 3.0)
Václav Kubernát385dcdd2020-11-25 17:46:54 +01003set(CMAKE_CXX_STANDARD 20)
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)
Jan Kundrátbba52522020-11-11 17:40:31 +01008include(CTest)
Jan Kundrátd47f6552018-03-02 13:40:11 +01009
10# Set a default build type if none was specified. This was shamelessly stolen
11# from VTK's cmake setup because these guys produce both CMake and a project that
12# manipulates this variable, and the web is full of posts where people say that
13# it is apparently evil to just set the build type in a way an earlier version of
14# this patch did. Oh, and the location of this check/update matters, apparently.
15#
16# Yes, this is just plain crazy.
17if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
18 message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.")
19 set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE)
20 # Set the possible values of build type for cmake-gui
21 set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
22endif()
23
24# -Werror is not a default for sanity reasons (one cannot know what warnings a future compiler
25# might bring along), but it's a default in debug mode. The idea is that developers should care
26# about a warning-free build, and that this is easier than messing with yet another configure option.
27set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
28
29# I don't want to duplicate the compiler's optimizations
30set(CMAKE_CXX_FLAGS "-O2 ${CMAKE_CXX_FLAGS}")
31
32# Build warnings are useful tools (and this project should be warning-free anyway), enable them on all
33# configurations. They are warnings, not errors.
Václav Kubernát84834142020-02-07 19:25:55 +010034set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual -Wimplicit-fallthrough ${CMAKE_CXX_FLAGS}")
Jan Kundrátfb831902018-05-26 18:58:52 +020035
36if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
37 set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}")
38endif()
Jan Kundrátd47f6552018-03-02 13:40:11 +010039
Jan Kundrátdc2b0722018-03-02 14:13:37 +010040add_custom_target(git-version-cmake-ide
41 cmake/ProjectGitVersion.cmake
42 cmake/ProjectGitVersionRunner.cmake
Jan Kundrát75c88c52020-11-12 01:51:26 +010043 cmake/DiscoverNetconfExecutables.cmake
Jan Kundrátdc2b0722018-03-02 14:13:37 +010044 )
45include(cmake/ProjectGitVersion.cmake)
46prepare_git_version(NETCONF_CLI_VERSION "0.0")
47
Jan Kundrátc28a21b2020-11-11 15:45:43 +010048# Boost.Process needs linking with threads, but doesn't have special CMake target which would do that for us. So, we
49# need to link manually. This will hopefully change in the future.
50# https://discourse.cmake.org/t/boost-process-target-doesnt-exist-for-thread-linking/2113
51set(THREADS_PREFER_PTHREAD_FLAG ON)
52find_package(Threads)
53
Jan Kundrát608818b2018-03-02 13:43:53 +010054find_package(Doxygen)
55option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
56
Jan Kundrátd47f6552018-03-02 13:40:11 +010057find_package(docopt REQUIRED)
Václav Kubernáte2e15ee2020-02-05 17:38:13 +010058find_package(Boost REQUIRED COMPONENTS filesystem)
Václav Kubernát385dcdd2020-11-25 17:46:54 +010059# Fixes C++20 build
60# https://github.com/boostorg/asio/issues/312
61add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS)
Václav Kubernátf8ca3642020-11-26 04:16:39 +010062find_package(replxx REQUIRED)
Jan Kundrát608818b2018-03-02 13:43:53 +010063
Jan Kundráte05448a2018-06-13 15:54:33 +020064find_package(PkgConfig)
Jan Kundrátbba52522020-11-11 17:40:31 +010065
66set(ENABLE_SYSREPO_CLI AUTO CACHE STRING "Enable the `sysrepo-cli`")
67set_property(CACHE ENABLE_SYSREPO_CLI PROPERTY STRINGS AUTO ON OFF)
68set(ENABLE_FULL_TESTS AUTO CACHE STRING "Enable end-to-end tests via sysrepo and netopeer2")
69set_property(CACHE ENABLE_FULL_TESTS PROPERTY STRINGS AUTO ON OFF)
70if(NOT (ENABLE_SYSREPO_CLI STREQUAL ON OR ENABLE_SYSREPO_CLI STREQUAL OFF OR ENABLE_SYSREPO_CLI STREQUAL AUTO))
71 message(FATAL_ERROR "ENABLE_SYSREPO_CLI must be one of ON, OFF, AUTO")
72endif()
73if(NOT (ENABLE_FULL_TESTS STREQUAL ON OR ENABLE_FULL_TESTS STREQUAL OFF OR ENABLE_FULL_TESTS STREQUAL AUTO))
74 message(FATAL_ERROR "ENABLE_FULL_TESTS must be one of ON, OFF, AUTO")
75endif()
76if(NOT BUILD_TESTING AND ENABLE_FULL_TESTS STREQUAL ON)
77 message(FATAL_ERROR "Cannot combine ENABLE_FULL_TESTS=ON with BUILD_TESTING=OFF")
78endif()
79
Jan Kundrát86840ec2021-01-27 15:38:08 +010080pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.215 IMPORTED_TARGET libyang)
Jan Kundrát603dc162021-01-19 09:29:52 +010081pkg_check_modules(LIBNETCONF2 REQUIRED libnetconf2>=1.1.36 IMPORTED_TARGET libnetconf2)
Jan Kundráte05448a2018-06-13 15:54:33 +020082
Jan Kundrátbba52522020-11-11 17:40:31 +010083if(ENABLE_FULL_TESTS STREQUAL OFF AND ENABLE_SYSREPO_CLI STREQUAL OFF)
84 message(STATUS "Skipping sysrepo per configure options")
85 set(SYSREPO_FOUND 0)
86else()
Jan Kundrát86840ec2021-01-27 15:38:08 +010087 pkg_check_modules(SYSREPO sysrepo-cpp>=1.4.103 IMPORTED_TARGET sysrepo)
Jan Kundrátbba52522020-11-11 17:40:31 +010088endif()
89
90if(SYSREPO_FOUND)
91 if(ENABLE_SYSREPO_CLI STREQUAL OFF)
92 message(STATUS "Skipping the `sysrepo-cli` per config option")
93 set(DO_ENABLE_SYSREPO_CLI OFF)
94 else()
95 message(STATUS "The `sysrepo-cli` will be available")
96 set(DO_ENABLE_SYSREPO_CLI ON)
97 endif()
98
99 if(BUILD_TESTING)
100 include(cmake/DiscoverNetconfExecutables.cmake)
101 discover_netconf_executables()
102
103 if(ENABLE_FULL_TESTS STREQUAL OFF)
104 message(STATUS "End-to-end NETCONF test suite disabled per config option")
105 set(DO_ENABLE_NETCONF_TESTS OFF)
106 else()
107 message(STATUS "End-to-end NETCONF test suite enabled")
108 set(DO_ENABLE_NETCONF_TESTS ON)
109 endif()
110 endif()
111else()
112 if(ENABLE_SYSREPO_CLI STREQUAL ON)
113 message(FATAL_ERROR "Cannot find sysrepo-cpp which is required for the `sysrepo-cli`")
114 elseif(ENABLE_SYSREPO_CLI STREQUAL AUTO)
115 message(STATUS "Cannot find sysrepo-cpp, skipping the `sysrepo-cli`")
116 endif()
117 set(DO_ENABLE_SYSREPO_CLI OFF)
118
119 if(BUILD_TESTING)
120 if(ENABLE_FULL_TESTS STREQUAL ON)
121 message(FATAL_ERROR "Cannot find sysrepo-cpp which is required for the end-to-end NETCONF test suite")
122 elseif(ENABLE_FULL_TESTS STREQUAL AUTO)
123 message(STATUS "Cannot find sysrepo-cpp, skipping the end-to-end NETCONF test suite")
124 endif()
125 set(DO_ENABLE_NETCONF_TESTS OFF)
126 endif()
127endif()
128
Jan Kundrátbb525b42020-02-04 11:56:59 +0100129include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/)
130
Václav Kubernát7edb5372019-12-13 12:40:49 +0100131add_library(ast_values STATIC
132 src/ast_values.cpp
133 )
Jan Kundrát688041f2020-03-31 10:02:49 +0200134target_link_libraries(ast_values PUBLIC Boost::boost)
135
136add_library(path STATIC
137 src/ast_path.cpp
138 )
139target_link_libraries(path PUBLIC ast_values Boost::boost)
Václav Kubernát7edb5372019-12-13 12:40:49 +0100140
Václav Kubernát3a99f002020-03-31 02:27:41 +0200141add_library(leaf_data_type STATIC
142 src/leaf_data_type.cpp
143 )
144target_link_libraries(leaf_data_type ast_values)
145
Václav Kubernát7edb5372019-12-13 12:40:49 +0100146add_library(utils STATIC
147 src/utils.cpp
148 )
Jan Kundrát688041f2020-03-31 10:02:49 +0200149target_link_libraries(utils path ast_values)
Václav Kubernát7edb5372019-12-13 12:40:49 +0100150
Jan Kundrát578347c2018-08-09 15:02:06 +0200151add_library(schemas STATIC
Václav Kubernátbddbb172018-06-13 16:27:39 +0200152 src/static_schema.cpp
Václav Kubernát48fc3832018-05-28 14:21:22 +0200153 src/schema.cpp
Jan Kundrát578347c2018-08-09 15:02:06 +0200154 )
Václav Kubernát3a99f002020-03-31 02:27:41 +0200155target_link_libraries(schemas PUBLIC path leaf_data_type Boost::boost)
Jan Kundrát578347c2018-08-09 15:02:06 +0200156
Václav Kubernáte7a9fa32018-08-22 13:56:35 +0200157add_library(datastoreaccess STATIC
158 src/datastore_access.cpp
Václav Kubernátab612e92019-11-26 19:51:31 +0100159 src/data_query.cpp
Václav Kubernáte7a9fa32018-08-22 13:56:35 +0200160 )
161target_link_libraries(datastoreaccess PUBLIC Boost::boost)
162
Jan Kundrátbba52522020-11-11 17:40:31 +0100163if(DO_ENABLE_SYSREPO_CLI OR DO_ENABLE_NETCONF_TESTS)
164 add_library(sysrepoaccess STATIC
165 src/sysrepo_access.cpp
166 )
Václav Kubernátc31bd602019-03-07 11:44:48 +0100167
Jan Kundrátbba52522020-11-11 17:40:31 +0100168 target_link_libraries(sysrepoaccess PUBLIC datastoreaccess ast_values PRIVATE PkgConfig::SYSREPO PkgConfig::LIBYANG)
169endif()
Václav Kubernát80aacc02018-08-22 17:41:54 +0200170
Václav Kubernátc31bd602019-03-07 11:44:48 +0100171add_library(netconfaccess STATIC
172 src/netconf-client.cpp
173 src/netconf_access.cpp
174 )
175
Václav Kubernát3ea893e2020-10-19 16:33:01 +0200176target_link_libraries(netconfaccess PUBLIC datastoreaccess yangschema ast_values utils PkgConfig::LIBNETCONF2 PRIVATE PkgConfig::LIBYANG)
Václav Kubernátc31bd602019-03-07 11:44:48 +0100177
Václav Kubernát74487df2020-06-04 01:29:28 +0200178add_library(yangaccess STATIC
179 src/yang_access.cpp
180 )
181
Václav Kubernát3ea893e2020-10-19 16:33:01 +0200182target_link_libraries(yangaccess PUBLIC datastoreaccess yangschema PRIVATE PkgConfig::LIBYANG)
Václav Kubernát74487df2020-06-04 01:29:28 +0200183
Jan Kundrát2b335362020-11-05 20:40:45 +0100184add_library(yangutils STATIC
Václav Kubernát02a71152020-01-21 14:52:51 +0100185 src/libyang_utils.cpp
Václav Kubernát0d4db442018-07-18 17:18:43 +0200186 )
Jan Kundrát2b335362020-11-05 20:40:45 +0100187target_link_libraries(yangutils PUBLIC PkgConfig::LIBYANG)
Václav Kubernát2e4cafe2020-11-05 01:53:21 +0100188
189add_library(yangschema STATIC
190 src/yang_schema.cpp
191 )
Jan Kundrát2b335362020-11-05 20:40:45 +0100192target_link_libraries(yangschema PUBLIC schemas utils yangutils PRIVATE PkgConfig::LIBYANG)
Václav Kubernát0d4db442018-07-18 17:18:43 +0200193
Jan Kundrát578347c2018-08-09 15:02:06 +0200194add_library(parser STATIC
Václav Kubernát48fc3832018-05-28 14:21:22 +0200195 src/parser.cpp
Václav Kubernát24df80e2018-06-06 15:18:03 +0200196 src/ast_commands.cpp
Václav Kubernát195eeea2018-05-18 13:52:36 +0200197 src/parser_context.cpp
Václav Kubernát96344a12018-05-28 16:33:39 +0200198 src/interpreter.cpp
Václav Kubernát329c6c32019-02-06 16:41:53 +0100199 src/ast_handlers.cpp
Václav Kubernátcb3af402020-02-12 16:49:17 +0100200 src/completion.cpp
Jan Kundrátdc2b0722018-03-02 14:13:37 +0100201 )
Václav Kubernát7edb5372019-12-13 12:40:49 +0100202target_link_libraries(parser schemas utils ast_values)
Václav Kubernátd6662962018-03-22 17:41:33 +0100203
Václav Kubernát48e9dfa2020-07-08 10:55:12 +0200204add_library(proxydatastore STATIC
205 src/proxy_datastore.cpp
206 )
Václav Kubernáte7248b22020-06-26 15:38:59 +0200207target_link_libraries(proxydatastore PUBLIC datastoreaccess yangaccess)
Václav Kubernát48e9dfa2020-07-08 10:55:12 +0200208
Václav Kubernát74487df2020-06-04 01:29:28 +0200209# Links libraries, that aren't specific to a datastore type
210function(cli_link_required cli_target)
Václav Kubernátf8ca3642020-11-26 04:16:39 +0100211 target_link_libraries(${cli_target} proxydatastore yangschema docopt parser replxx::replxx)
Václav Kubernát74487df2020-06-04 01:29:28 +0200212 add_dependencies(${cli_target} target-NETCONF_CLI_VERSION)
213 target_include_directories(${cli_target} PRIVATE ${PROJECT_BINARY_DIR})
214endfunction()
215
Jan Kundrátbba52522020-11-11 17:40:31 +0100216if(DO_ENABLE_SYSREPO_CLI)
217 add_executable(sysrepo-cli
218 src/cli.cpp
219 )
220 target_compile_definitions(sysrepo-cli PRIVATE SYSREPO_CLI)
221 target_link_libraries(sysrepo-cli sysrepoaccess)
222 cli_link_required(sysrepo-cli)
223 list(APPEND cli_targets sysrepo-cli)
224endif()
Václav Kubernát2b684612018-08-09 18:55:24 +0200225
Václav Kubernát74487df2020-06-04 01:29:28 +0200226add_executable(yang-cli
227 src/cli.cpp
228 )
229target_compile_definitions(yang-cli PRIVATE YANG_CLI)
230cli_link_required(yang-cli)
231target_link_libraries(yang-cli yangaccess)
Jan Kundrátbba52522020-11-11 17:40:31 +0100232list(APPEND cli_targets yang-cli)
Václav Kubernát619e6542020-06-29 14:13:43 +0200233if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0)
234 target_link_libraries(yang-cli c++experimental)
235elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1)
236 target_link_libraries(yang-cli stdc++fs)
237endif()
238
Václav Kubernáte2e15ee2020-02-05 17:38:13 +0100239add_executable(netconf-cli
240 src/cli.cpp
241 src/cli-netconf.cpp
242 )
243target_compile_definitions(netconf-cli PRIVATE NETCONF_CLI)
244
Václav Kubernáte2e15ee2020-02-05 17:38:13 +0100245target_link_libraries(netconf-cli netconfaccess Threads::Threads Boost::filesystem)
246cli_link_required(netconf-cli)
Jan Kundrátbba52522020-11-11 17:40:31 +0100247list(APPEND cli_targets netconf-cli)
Václav Kubernát74487df2020-06-04 01:29:28 +0200248
Jan Kundrátdc2b0722018-03-02 14:13:37 +0100249
Jan Kundrát5c805212018-03-02 13:57:12 +0100250if(BUILD_TESTING)
Jan Kundrátc381e632019-03-14 13:39:11 +0100251 find_package(trompeloeil 33 REQUIRED)
Jan Kundráta33cf082019-03-28 11:55:57 +0100252 find_package(doctest 2.3.1 REQUIRED)
Jan Kundrát5c805212018-03-02 13:57:12 +0100253
Jan Kundráta33cf082019-03-28 11:55:57 +0100254 add_library(DoctestIntegration STATIC
255 tests/doctest_integration.cpp
Václav Kubernát26b56082020-02-03 18:28:56 +0100256 tests/trompeloeil_doctest.hpp
Jan Kundrátc381e632019-03-14 13:39:11 +0100257 tests/wait-a-bit-longer.cpp
Jan Kundrát5c805212018-03-02 13:57:12 +0100258 )
Jan Kundráta33cf082019-03-28 11:55:57 +0100259 target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/)
Václav Kubernátc31bd602019-03-07 11:44:48 +0100260 target_link_libraries(DoctestIntegration doctest::doctest trompeloeil)
Jan Kundráta33cf082019-03-28 11:55:57 +0100261 target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS)
Jan Kundrát5c805212018-03-02 13:57:12 +0100262
Jan Kundrátbba52522020-11-11 17:40:31 +0100263 if(DO_ENABLE_NETCONF_TESTS)
264 add_library(sysreposubscription STATIC
265 tests/mock/sysrepo_subscription.cpp
266 )
267 target_link_libraries(sysreposubscription PUBLIC datastoreaccess PRIVATE PkgConfig::SYSREPO)
Jan Kundrátbb525b42020-02-04 11:56:59 +0100268
Jan Kundrátbba52522020-11-11 17:40:31 +0100269 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_repositories)
Jan Kundrát805d02c2020-11-13 20:20:44 +0100270 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_netopeer_files)
Václav Kubernát634e24a2020-11-19 01:20:27 +0100271 file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_netopeer_outputs)
Jan Kundrátbba52522020-11-11 17:40:31 +0100272 endif()
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200273
274 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 +0100275
Václav Kubernát88324812019-06-26 17:36:29 +0200276 function(cli_test name)
277 if (${ARGC} GREATER 1) # this is how CMake does optional arguments
278 add_executable(test_${name}
279 tests/${ARGV1}
280 )
281 else()
282 add_executable(test_${name}
283 tests/${name}.cpp
284 )
Jan Kundrát5c805212018-03-02 13:57:12 +0100285 endif()
Václav Kubernát43908fb2020-01-02 19:05:51 +0100286 target_link_libraries(test_${name} DoctestIntegration parser datastoreaccess)
Václav Kubernát88324812019-06-26 17:36:29 +0200287 if(NOT CMAKE_CROSSCOMPILING)
288 add_test(test_${name} test_${name})
289 endif()
290 target_include_directories(test_${name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
Jan Kundrátcc4c1f22018-08-09 15:00:03 +0200291 endfunction()
Václav Kubernát88324812019-06-26 17:36:29 +0200292
Václav Kubernát1acf4f12020-01-31 15:54:34 +0100293 function(datastore_test_impl name model backend)
Václav Kubernát7d478642019-11-22 17:38:11 +0100294 set(TESTNAME test_${name}_${backend})
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200295
Václav Kubernát7d478642019-11-22 17:38:11 +0100296 cli_test(${name}_${backend} ${name}.cpp)
Václav Kubernát7d478642019-11-22 17:38:11 +0100297 target_include_directories(${TESTNAME} PRIVATE ${PROJECT_SOURCE_DIR}/tests/mock)
298 if (${backend} STREQUAL "sysrepo")
299 target_link_libraries(${TESTNAME} sysrepoaccess)
300 elseif (${backend} STREQUAL "netconf")
301 target_link_libraries(${TESTNAME} netconfaccess)
Václav Kubernát74487df2020-06-04 01:29:28 +0200302 elseif (${backend} STREQUAL "yang")
303 target_link_libraries(${TESTNAME} yangaccess)
Václav Kubernát7d478642019-11-22 17:38:11 +0100304 else()
305 message(FATAL_ERROR "Unknown backend ${backend}")
306 endif()
Václav Kubernát3ea893e2020-10-19 16:33:01 +0200307 target_link_libraries(${TESTNAME} yangschema sysreposubscription proxydatastore PkgConfig::SYSREPO)
Václav Kubernát7d478642019-11-22 17:38:11 +0100308
309 target_compile_definitions(${TESTNAME} PRIVATE ${backend}_BACKEND)
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200310 set_tests_properties(${TESTNAME} PROPERTIES FIXTURES_REQUIRED ${TESTNAME}_setup)
311
312 add_test(NAME ${TESTNAME}_init COMMAND ${CMAKE_CURRENT_BINARY_DIR}/init_datastore.bash "${model}" "${backend}")
313 set_tests_properties(${TESTNAME}_init PROPERTIES FIXTURES_SETUP ${TESTNAME}_setup)
314 add_test(NAME ${TESTNAME}_cleanup COMMAND ${CMAKE_CURRENT_BINARY_DIR}/cleanup_datastore.bash "${backend}")
315 set_tests_properties(${TESTNAME}_cleanup PROPERTIES FIXTURES_CLEANUP ${TESTNAME}_setup)
316
317 set_property(TEST ${TESTNAME} ${TESTNAME}_init ${TESTNAME}_cleanup APPEND PROPERTY ENVIRONMENT
318 "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/${TESTNAME}"
319 "SYSREPO_SHM_PREFIX=netconf-cli_${TESTNAME}"
Jan Kundrát9a7f7422021-01-04 17:01:53 +0100320 "NETOPEER_SOCKET=test_netopeer_files/${TESTNAME}.sock"
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200321 )
322
Václav Kubernát7d478642019-11-22 17:38:11 +0100323 endfunction()
324
Václav Kubernát1acf4f12020-01-31 15:54:34 +0100325 function(datastore_test name model)
326 datastore_test_impl(${name} ${model} sysrepo)
327 datastore_test_impl(${name} ${model} netconf)
Václav Kubernát74487df2020-06-04 01:29:28 +0200328 datastore_test_impl(${name} ${model} yang)
Václav Kubernát88324812019-06-26 17:36:29 +0200329 endfunction()
330
Václav Kubernátd6662962018-03-22 17:41:33 +0100331 cli_test(cd)
Václav Kubernát11afac72018-07-18 14:59:53 +0200332 cli_test(ls)
Václav Kubernátb61336d2018-05-28 17:35:03 +0200333 cli_test(presence_containers)
Václav Kubernát07204242018-06-04 18:12:09 +0200334 cli_test(leaf_editing)
Václav Kubernát3a99f002020-03-31 02:27:41 +0200335 target_link_libraries(test_leaf_editing leaf_data_type)
Václav Kubernát0d4db442018-07-18 17:18:43 +0200336 cli_test(yang)
337 target_link_libraries(test_yang yangschema)
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100338 cli_test(utils)
Jan Kundrát2b335362020-11-05 20:40:45 +0100339 target_link_libraries(test_utils yangutils)
Václav Kubernát4108e0d2018-10-29 13:32:22 +0100340 cli_test(path_completion)
Václav Kubernát57272422019-02-08 12:48:24 +0100341 cli_test(command_completion)
Václav Kubernát549b08f2020-05-14 22:19:36 +0200342 cli_test(set_value_completion)
343 target_link_libraries(test_set_value_completion leaf_data_type)
Václav Kubernátf5f64f02019-03-19 17:15:47 +0100344 cli_test(list_manipulation)
Václav Kubernát5452ede2020-06-10 12:05:11 +0200345 cli_test(interpreter)
Václav Kubernát48e9dfa2020-07-08 10:55:12 +0200346 target_link_libraries(test_interpreter proxydatastore)
Václav Kubernát5395e712019-12-03 18:24:33 +0100347 cli_test(path_utils)
Václav Kubernát7edb5372019-12-13 12:40:49 +0100348 target_link_libraries(test_path_utils path)
Václav Kubernát43908fb2020-01-02 19:05:51 +0100349 cli_test(keyvalue_completion)
Václav Kubernátd8408e02020-12-02 05:13:27 +0100350 cli_test(parser_rpc)
Václav Kubernátc31bd602019-03-07 11:44:48 +0100351
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200352 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/init_datastore.bash.in
353 ${CMAKE_CURRENT_BINARY_DIR}/init_datastore.bash @ONLY)
354
355 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/cleanup_datastore.bash.in
356 ${CMAKE_CURRENT_BINARY_DIR}/cleanup_datastore.bash @ONLY)
357
Jan Kundrátbba52522020-11-11 17:40:31 +0100358 if(DO_ENABLE_NETCONF_TESTS)
359 datastore_test(datastore_access ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang)
360 datastore_test(data_query ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang)
361 endif()
Jan Kundrát5c805212018-03-02 13:57:12 +0100362endif()
363
Jan Kundrátcf5c6362020-01-16 22:54:47 +0100364option(WITH_PYTHON_BINDINGS "Create and install Python3 bindings for accessing datastores" OFF)
365if(WITH_PYTHON_BINDINGS)
Václav Kubernát385dcdd2020-11-25 17:46:54 +0100366 set(PYBIND11_CPP_STANDARD -std=c++20)
Jan Kundrátcf5c6362020-01-16 22:54:47 +0100367 find_package(pybind11 REQUIRED)
368 pybind11_add_module(netconf_cli_py src/python_netconf.cpp)
369 target_link_libraries(netconf_cli_py PUBLIC netconfaccess)
370
371 if(BUILD_TESTING)
Václav Kubernát654303f2020-07-31 13:16:54 +0200372 pybind11_add_module(sysrepo_subscription_py tests/mock/sysrepo_subscription_python.cpp)
373 target_link_libraries(sysrepo_subscription_py PUBLIC sysreposubscription utils)
374
Jan Kundrátcf5c6362020-01-16 22:54:47 +0100375 configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/python_netconfaccess.py
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200376 ${CMAKE_CURRENT_BINARY_DIR}/tests_python_netconfaccess.py COPYONLY)
377
Jan Kundrátcf5c6362020-01-16 22:54:47 +0100378 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 +0200379 set_tests_properties(test_netconf_cli_py PROPERTIES FIXTURES_REQUIRED test_netconf_cli_py_setup)
380
381 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")
382 set_tests_properties(test_netconf_cli_py_init PROPERTIES FIXTURES_SETUP test_netconf_cli_py_setup)
383 add_test(NAME test_netconf_cli_py_cleanup COMMAND ${CMAKE_CURRENT_BINARY_DIR}/cleanup_datastore.bash "netconf")
384 set_tests_properties(test_netconf_cli_py_cleanup PROPERTIES FIXTURES_CLEANUP test_netconf_cli_py_setup)
385
386 set_property(TEST test_netconf_cli_py test_netconf_cli_py_init test_netconf_cli_py_cleanup APPEND PROPERTY ENVIRONMENT
387 "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/test_netconf_cli_py"
388 "SYSREPO_SHM_PREFIX=netconf-cli_test_netconf_cli_py"
Jan Kundrát9a7f7422021-01-04 17:01:53 +0100389 "NETOPEER_SOCKET=test_netopeer_files/test_netconf_cli_py.sock"
Václav Kubernátd1beedc2020-09-07 12:09:05 +0200390 )
Jan Kundrátcf5c6362020-01-16 22:54:47 +0100391
392 set(sanitizer_active OFF)
393 # FIXME: this just sucks. The detection is very unreliable (one could use something like
394 # -fsanitize=address,undefined and we are screwed), and especially clang's query for preload
395 # is obviously unportable because we hardcode host's architecture.
396 # This is super-ugly. Perhaps it would be better just to outright disable everything, but hey,
397 # I need to test this on my laptop where I'm using ASAN by default, and it kinda-almost-works
398 # there with just one patch to libyang :).
399 if (${CMAKE_CXX_FLAGS} MATCHES "-fsanitize=address")
400 set(sanitizer_active ON)
401 set(gcc_sanitizer_preload libasan.so)
402 set(clang_sanitizer_preload libclang_rt.asan-x86_64.so)
403 endif()
404
405 if (sanitizer_active)
406 if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
407 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=${clang_sanitizer_preload}
408 OUTPUT_VARIABLE LIBxSAN_FULL_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
409 elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
410 execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=${gcc_sanitizer_preload}
411 OUTPUT_VARIABLE LIBxSAN_FULL_PATH OUTPUT_STRIP_TRAILING_WHITESPACE)
412 else()
413 message(ERROR "Cannot determine correct sanitizer library for LD_PRELOAD")
414 endif()
415 set_property(TEST test_netconf_cli_py APPEND PROPERTY ENVIRONMENT
416 LD_PRELOAD=${LIBxSAN_FULL_PATH}
417 ASAN_OPTIONS=detect_leaks=0 # they look harmless, but they are annoying
418 )
419 endif()
420 endif()
421endif()
422
Jan Kundrát608818b2018-03-02 13:43:53 +0100423if(WITH_DOCS)
424 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
425 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
426 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
427 add_custom_target(doc
428 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
429 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
430 COMMENT "Generating API documentation with Doxygen"
431 VERBATIM
432 SOURCES ${doxyfile_in}
433 )
434endif()
Jan Kundrát10f49902018-05-22 17:01:45 +0200435
Jan Kundrátbba52522020-11-11 17:40:31 +0100436install(TARGETS ${cli_targets}
Jan Kundrát10f49902018-05-22 17:01:45 +0200437 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)