Jan Kundrát | d9d26a9 | 2018-02-22 12:49:21 +0100 | [diff] [blame] | 1 | project(netconf-cli LANGUAGES CXX) |
| 2 | cmake_minimum_required(VERSION 3.0) |
Jan Kundrát | 763db1e | 2018-05-25 15:43:51 +0200 | [diff] [blame] | 3 | set(CMAKE_CXX_STANDARD 17) |
Jan Kundrát | d9d26a9 | 2018-02-22 12:49:21 +0100 | [diff] [blame] | 4 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
Jan Kundrát | 8569e1b | 2020-01-16 13:47:19 +0100 | [diff] [blame] | 5 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
Jan Kundrát | d47f655 | 2018-03-02 13:40:11 +0100 | [diff] [blame] | 6 | |
| 7 | include(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. |
| 16 | if(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") |
| 21 | endif() |
| 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. |
| 26 | set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}") |
| 27 | |
| 28 | # I don't want to duplicate the compiler's optimizations |
| 29 | set(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át | 8483414 | 2020-02-07 19:25:55 +0100 | [diff] [blame] | 33 | set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual -Wimplicit-fallthrough ${CMAKE_CXX_FLAGS}") |
Jan Kundrát | fb83190 | 2018-05-26 18:58:52 +0200 | [diff] [blame] | 34 | |
| 35 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 36 | set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}") |
| 37 | endif() |
Jan Kundrát | d47f655 | 2018-03-02 13:40:11 +0100 | [diff] [blame] | 38 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 39 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") |
| 40 | |
| 41 | add_custom_target(git-version-cmake-ide |
| 42 | cmake/ProjectGitVersion.cmake |
| 43 | cmake/ProjectGitVersionRunner.cmake |
| 44 | ) |
| 45 | include(cmake/ProjectGitVersion.cmake) |
| 46 | prepare_git_version(NETCONF_CLI_VERSION "0.0") |
| 47 | |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 48 | find_package(Doxygen) |
| 49 | option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND}) |
| 50 | |
Jan Kundrát | d47f655 | 2018-03-02 13:40:11 +0100 | [diff] [blame] | 51 | find_package(docopt REQUIRED) |
Jan Kundrát | 03caee8 | 2018-03-08 14:16:56 +0100 | [diff] [blame] | 52 | find_package(Boost REQUIRED) |
Jan Kundrát | 8d8efe8 | 2019-10-18 10:21:36 +0200 | [diff] [blame] | 53 | find_library(REPLXX_LIBRARY NAMES replxx replxx-d REQUIRED) |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 54 | find_path(REPLXX_PATH replxx.hxx) |
| 55 | if("${REPLXX_PATH}" STREQUAL REPLXX_PATH-NOTFOUND) |
| 56 | message(FATAL_ERROR "Cannot find the \"replxx.hxx\" include file for the replxx library.") |
| 57 | endif() |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 58 | |
Jan Kundrát | e05448a | 2018-06-13 15:54:33 +0200 | [diff] [blame] | 59 | find_package(PkgConfig) |
Jan Kundrát | 9f71d77 | 2020-04-09 13:29:36 +0200 | [diff] [blame] | 60 | pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.130 IMPORTED_TARGET libyang) |
| 61 | pkg_check_modules(SYSREPO REQUIRED libSysrepo-cpp>=0.7.9 IMPORTED_TARGET libsysrepo) |
| 62 | pkg_check_modules(LIBNETCONF2 REQUIRED libnetconf2>=0.12.64 IMPORTED_TARGET libnetconf2) |
Jan Kundrát | e05448a | 2018-06-13 15:54:33 +0200 | [diff] [blame] | 63 | |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 64 | # we don't need filename tracking, and we prefer to use header-only Boost |
| 65 | add_definitions(-DBOOST_SPIRIT_X3_NO_FILESYSTEM) |
| 66 | |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 67 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/) |
| 68 | |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 69 | add_library(ast_values STATIC |
| 70 | src/ast_values.cpp |
| 71 | ) |
Jan Kundrát | 688041f | 2020-03-31 10:02:49 +0200 | [diff] [blame] | 72 | target_link_libraries(ast_values PUBLIC Boost::boost) |
| 73 | |
| 74 | add_library(path STATIC |
| 75 | src/ast_path.cpp |
| 76 | ) |
| 77 | target_link_libraries(path PUBLIC ast_values Boost::boost) |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 78 | |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 79 | add_library(leaf_data_type STATIC |
| 80 | src/leaf_data_type.cpp |
| 81 | ) |
| 82 | target_link_libraries(leaf_data_type ast_values) |
| 83 | |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 84 | add_library(utils STATIC |
| 85 | src/utils.cpp |
| 86 | ) |
Jan Kundrát | 688041f | 2020-03-31 10:02:49 +0200 | [diff] [blame] | 87 | target_link_libraries(utils path ast_values) |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 88 | |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 89 | add_library(schemas STATIC |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 90 | src/static_schema.cpp |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 91 | src/schema.cpp |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 92 | ) |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 93 | target_link_libraries(schemas PUBLIC path leaf_data_type Boost::boost) |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 94 | |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 95 | add_library(datastoreaccess STATIC |
| 96 | src/datastore_access.cpp |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 97 | src/data_query.cpp |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 98 | ) |
| 99 | target_link_libraries(datastoreaccess PUBLIC Boost::boost) |
| 100 | |
Václav Kubernát | 80aacc0 | 2018-08-22 17:41:54 +0200 | [diff] [blame] | 101 | add_library(sysrepoaccess STATIC |
| 102 | src/sysrepo_access.cpp |
| 103 | ) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 104 | |
Jan Kundrát | 9f71d77 | 2020-04-09 13:29:36 +0200 | [diff] [blame] | 105 | target_link_libraries(sysrepoaccess PUBLIC datastoreaccess ast_values PRIVATE PkgConfig::SYSREPO) |
Václav Kubernát | 80aacc0 | 2018-08-22 17:41:54 +0200 | [diff] [blame] | 106 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 107 | add_library(netconfaccess STATIC |
| 108 | src/netconf-client.cpp |
| 109 | src/netconf_access.cpp |
| 110 | ) |
| 111 | |
Jan Kundrát | 9f71d77 | 2020-04-09 13:29:36 +0200 | [diff] [blame] | 112 | target_link_libraries(netconfaccess PUBLIC datastoreaccess yangschema ast_values utils PRIVATE PkgConfig::LIBNETCONF2) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 113 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 114 | add_library(yangschema STATIC |
| 115 | src/yang_schema.cpp |
Václav Kubernát | 02a7115 | 2020-01-21 14:52:51 +0100 | [diff] [blame] | 116 | src/libyang_utils.cpp |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 117 | ) |
Jan Kundrát | 9f71d77 | 2020-04-09 13:29:36 +0200 | [diff] [blame] | 118 | target_link_libraries(yangschema PUBLIC schemas utils PRIVATE PkgConfig::LIBYANG) |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 119 | |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 120 | add_library(parser STATIC |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 121 | src/parser.cpp |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 122 | src/ast_commands.cpp |
Václav Kubernát | 195eeea | 2018-05-18 13:52:36 +0200 | [diff] [blame] | 123 | src/parser_context.cpp |
Václav Kubernát | 96344a1 | 2018-05-28 16:33:39 +0200 | [diff] [blame] | 124 | src/interpreter.cpp |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 125 | src/ast_handlers.cpp |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 126 | src/completion.cpp |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 127 | ) |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 128 | target_link_libraries(parser schemas utils ast_values) |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 129 | |
Václav Kubernát | b79f3ca | 2020-02-04 15:56:01 +0100 | [diff] [blame] | 130 | add_executable(sysrepo-cli |
| 131 | src/cli.cpp |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 132 | ) |
Václav Kubernát | b79f3ca | 2020-02-04 15:56:01 +0100 | [diff] [blame] | 133 | target_compile_definitions(sysrepo-cli PRIVATE SYSREPO_CLI) |
| 134 | target_include_directories(sysrepo-cli PRIVATE ${REPLXX_PATH}) |
| 135 | target_link_libraries(sysrepo-cli sysrepoaccess yangschema docopt parser ${REPLXX_LIBRARY}) |
Jan Kundrát | 1f30b62 | 2020-04-21 10:43:31 +0200 | [diff] [blame] | 136 | if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) |
Václav Kubernát | b79f3ca | 2020-02-04 15:56:01 +0100 | [diff] [blame] | 137 | target_link_libraries(sysrepo-cli c++experimental) |
Jan Kundrát | 1f30b62 | 2020-04-21 10:43:31 +0200 | [diff] [blame] | 138 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1) |
Václav Kubernát | b79f3ca | 2020-02-04 15:56:01 +0100 | [diff] [blame] | 139 | target_link_libraries(sysrepo-cli stdc++fs) |
Václav Kubernát | 2b68461 | 2018-08-09 18:55:24 +0200 | [diff] [blame] | 140 | endif() |
| 141 | |
Václav Kubernát | b79f3ca | 2020-02-04 15:56:01 +0100 | [diff] [blame] | 142 | add_dependencies(sysrepo-cli target-NETCONF_CLI_VERSION) |
| 143 | target_include_directories(sysrepo-cli PRIVATE ${PROJECT_BINARY_DIR}) |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 144 | |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 145 | include(CTest) |
| 146 | if(BUILD_TESTING) |
| 147 | enable_testing() |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 148 | find_package(trompeloeil 33 REQUIRED) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 149 | find_package(doctest 2.3.1 REQUIRED) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 150 | |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 151 | add_library(DoctestIntegration STATIC |
| 152 | tests/doctest_integration.cpp |
Václav Kubernát | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 153 | tests/trompeloeil_doctest.hpp |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 154 | tests/wait-a-bit-longer.cpp |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 155 | ) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 156 | target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 157 | target_link_libraries(DoctestIntegration doctest::doctest trompeloeil) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 158 | target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 159 | |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 160 | add_library(sysreposubscription STATIC |
| 161 | tests/mock/sysrepo_subscription.cpp |
| 162 | ) |
| 163 | target_link_libraries(sysreposubscription PUBLIC datastoreaccess PRIVATE PkgConfig::SYSREPO) |
| 164 | |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 165 | if (NOT SYSREPOCTL_EXECUTABLE) |
| 166 | find_program(SYSREPOCTL_EXECUTABLE sysrepoctl) |
| 167 | endif() |
| 168 | if (NOT SYSREPOCTL_EXECUTABLE) |
| 169 | message(FATAL_ERROR "Unable to find sysrepoctl, set SYSREPOCTL_EXECUTABLE manually.") |
| 170 | endif() |
| 171 | |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 172 | if (NOT SYSREPOCFG_EXECUTABLE) |
| 173 | find_program(SYSREPOCFG_EXECUTABLE sysrepocfg) |
| 174 | endif() |
| 175 | if (NOT SYSREPOCFG_EXECUTABLE) |
| 176 | message(FATAL_ERROR "Unable to find sysrepocfg, set SYSREPOCFG_EXECUTABLE manually.") |
| 177 | endif() |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 178 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 179 | if (NOT SYSREPOD_EXECUTABLE) |
| 180 | find_program(SYSREPOD_EXECUTABLE sysrepod) |
| 181 | endif() |
| 182 | if (NOT SYSREPOD_EXECUTABLE) |
| 183 | message(FATAL_ERROR "Unable to find sysrepod, set SYSREPOD_EXECUTABLE manually.") |
| 184 | endif() |
| 185 | |
| 186 | if (NOT SYSREPO_PLUGIND_EXECUTABLE) |
| 187 | find_program(SYSREPO_PLUGIND_EXECUTABLE sysrepo-plugind) |
| 188 | endif() |
| 189 | if (NOT SYSREPO_PLUGIND_EXECUTABLE) |
| 190 | message(FATAL_ERROR "Unable to find sysrepo-plugind, set SYSREPO_EXECUTABLE manually.") |
| 191 | endif() |
| 192 | |
| 193 | if (NOT NETOPEER2_EXECUTABLE) |
| 194 | find_program(NETOPEER2_EXECUTABLE netopeer2-server) |
| 195 | endif() |
| 196 | if (NOT NETOPEER2_EXECUTABLE) |
| 197 | message(FATAL_ERROR "Unable to find netopeer2-server, set NETOPEER2_EXECUTABLE manually.") |
| 198 | endif() |
| 199 | |
Jan Kundrát | e323627 | 2019-09-27 09:45:26 +0200 | [diff] [blame] | 200 | if (NOT FAKEROOT_EXECUTABLE) |
| 201 | find_program(FAKEROOT_EXECUTABLE fakeroot) |
| 202 | endif() |
| 203 | if (NOT FAKEROOT_EXECUTABLE) |
| 204 | message(FATAL_ERROR "Unable to find fakeroot, set FAKEROOT_EXECUTABLE manually.") |
| 205 | endif() |
| 206 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 207 | set(NETOPEER_SOCKET_PATH "${CMAKE_CURRENT_BINARY_DIR}/netopeer2-server.sock") |
Jan Kundrát | e103449 | 2020-01-16 23:09:09 +0100 | [diff] [blame] | 208 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/start_daemons.sh.in ${CMAKE_CURRENT_BINARY_DIR}/start_daemons.sh @ONLY) |
| 209 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/netopeer_vars.hpp.in ${CMAKE_CURRENT_BINARY_DIR}/netopeer_vars.hpp @ONLY) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 210 | |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 211 | function(setup_datastore_tests) |
Jan Kundrát | e103449 | 2020-01-16 23:09:09 +0100 | [diff] [blame] | 212 | add_test(NAME setup_netopeer COMMAND ${SYSREPOCFG_EXECUTABLE} ietf-netconf-server -i ${CMAKE_CURRENT_SOURCE_DIR}/tests/netopeer-test-config.xml --datastore=startup --format=xml) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 213 | add_test(NAME start_daemons COMMAND ${FAKEROOT_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/start_daemons.sh) |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 214 | add_test(NAME example-schema_init |
| 215 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL_EXECUTABLE} ${SYSREPOCFG_EXECUTABLE} install ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang ) |
| 216 | add_test(NAME example-schema_cleanup |
| 217 | COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/sysrepoctl-manage-module.sh ${SYSREPOCTL_EXECUTABLE} ${SYSREPOCFG_EXECUTABLE} uninstall ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang ) |
Jan Kundrát | e103449 | 2020-01-16 23:09:09 +0100 | [diff] [blame] | 218 | add_test(NAME kill_daemons COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/tests/kill_daemons.sh) |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 219 | set_tests_properties(example-schema_init PROPERTIES FIXTURES_REQUIRED netopeer_running FIXTURES_SETUP example-schema_setup) |
| 220 | set_tests_properties(example-schema_cleanup PROPERTIES FIXTURES_CLEANUP example-schema_setup) |
| 221 | set_tests_properties(setup_netopeer start_daemons kill_daemons example-schema_init example-schema_cleanup PROPERTIES RESOURCE_LOCK sysrepo) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 222 | set_tests_properties(setup_netopeer PROPERTIES FIXTURES_SETUP netopeer_configured) |
| 223 | set_tests_properties(start_daemons PROPERTIES FIXTURES_REQUIRED netopeer_configured FIXTURES_SETUP netopeer_running) |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 224 | set_property(TEST kill_daemons APPEND PROPERTY DEPENDS example-schema_cleanup) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 225 | endfunction() |
| 226 | |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 227 | function(cli_test name) |
| 228 | if (${ARGC} GREATER 1) # this is how CMake does optional arguments |
| 229 | add_executable(test_${name} |
| 230 | tests/${ARGV1} |
| 231 | ) |
| 232 | else() |
| 233 | add_executable(test_${name} |
| 234 | tests/${name}.cpp |
| 235 | ) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 236 | endif() |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 237 | target_link_libraries(test_${name} DoctestIntegration parser datastoreaccess) |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 238 | if(NOT CMAKE_CROSSCOMPILING) |
| 239 | add_test(test_${name} test_${name}) |
| 240 | endif() |
| 241 | target_include_directories(test_${name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
Jan Kundrát | cc4c1f2 | 2018-08-09 15:00:03 +0200 | [diff] [blame] | 242 | endfunction() |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 243 | |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 244 | function(datastore_test_impl name model backend) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 245 | set(TESTNAME test_${name}_${backend}) |
| 246 | cli_test(${name}_${backend} ${name}.cpp) |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 247 | set_tests_properties(${TESTNAME} PROPERTIES FIXTURES_REQUIRED ${model}_setup RESOURCE_LOCK sysrepo) |
| 248 | set_property(TEST ${TESTNAME} APPEND PROPERTY FIXTURES_REQUIRED netopeer_running) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 249 | target_include_directories(${TESTNAME} PRIVATE ${PROJECT_SOURCE_DIR}/tests/mock) |
| 250 | if (${backend} STREQUAL "sysrepo") |
| 251 | target_link_libraries(${TESTNAME} sysrepoaccess) |
| 252 | elseif (${backend} STREQUAL "netconf") |
| 253 | target_link_libraries(${TESTNAME} netconfaccess) |
| 254 | else() |
| 255 | message(FATAL_ERROR "Unknown backend ${backend}") |
| 256 | endif() |
| 257 | target_link_libraries(${TESTNAME} yangschema sysreposubscription) |
| 258 | |
| 259 | target_compile_definitions(${TESTNAME} PRIVATE ${backend}_BACKEND) |
| 260 | endfunction() |
| 261 | |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 262 | function(datastore_test name model) |
| 263 | datastore_test_impl(${name} ${model} sysrepo) |
| 264 | datastore_test_impl(${name} ${model} netconf) |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 265 | endfunction() |
| 266 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 267 | cli_test(cd) |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 268 | cli_test(ls) |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 269 | cli_test(presence_containers) |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 270 | cli_test(leaf_editing) |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 271 | target_link_libraries(test_leaf_editing leaf_data_type) |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 272 | cli_test(yang) |
| 273 | target_link_libraries(test_yang yangschema) |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 274 | cli_test(utils) |
| 275 | cli_test(path_completion) |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 276 | cli_test(command_completion) |
Václav Kubernát | 549b08f | 2020-05-14 22:19:36 +0200 | [diff] [blame] | 277 | cli_test(set_value_completion) |
| 278 | target_link_libraries(test_set_value_completion leaf_data_type) |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 279 | cli_test(list_manipulation) |
Václav Kubernát | 8208687 | 2020-04-29 01:09:50 +0200 | [diff] [blame] | 280 | cli_test(ls_interpreter) |
Václav Kubernát | 5395e71 | 2019-12-03 18:24:33 +0100 | [diff] [blame] | 281 | cli_test(path_utils) |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 282 | target_link_libraries(test_path_utils path) |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 283 | cli_test(keyvalue_completion) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 284 | |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 285 | setup_datastore_tests() |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 286 | datastore_test(datastore_access example-schema) |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 287 | datastore_test(data_query example-schema) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 288 | endif() |
| 289 | |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 290 | option(WITH_PYTHON_BINDINGS "Create and install Python3 bindings for accessing datastores" OFF) |
| 291 | if(WITH_PYTHON_BINDINGS) |
| 292 | set(PYBIND11_CPP_STANDARD -std=c++17) |
| 293 | find_package(pybind11 REQUIRED) |
| 294 | pybind11_add_module(netconf_cli_py src/python_netconf.cpp) |
| 295 | target_link_libraries(netconf_cli_py PUBLIC netconfaccess) |
| 296 | |
| 297 | if(BUILD_TESTING) |
| 298 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/python_netconfaccess.py |
| 299 | ${CMAKE_CURRENT_BINARY_DIR}/tests_python_netconfaccess.py @ONLY) |
| 300 | add_test(NAME test_netconf_cli_py COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/tests_python_netconfaccess.py) |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 301 | set_tests_properties(test_netconf_cli_py PROPERTIES FIXTURES_REQUIRED netopeer_running RESOURCE_LOCK sysrepo DEPENDS example-schema_cleanup) |
Václav Kubernát | 0177a93 | 2020-01-22 11:17:55 +0100 | [diff] [blame] | 302 | set_property(TEST kill_daemons APPEND PROPERTY DEPENDS test_netconf_cli_py) |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 303 | |
| 304 | set(sanitizer_active OFF) |
| 305 | # FIXME: this just sucks. The detection is very unreliable (one could use something like |
| 306 | # -fsanitize=address,undefined and we are screwed), and especially clang's query for preload |
| 307 | # is obviously unportable because we hardcode host's architecture. |
| 308 | # This is super-ugly. Perhaps it would be better just to outright disable everything, but hey, |
| 309 | # I need to test this on my laptop where I'm using ASAN by default, and it kinda-almost-works |
| 310 | # there with just one patch to libyang :). |
| 311 | if (${CMAKE_CXX_FLAGS} MATCHES "-fsanitize=address") |
| 312 | set(sanitizer_active ON) |
| 313 | set(gcc_sanitizer_preload libasan.so) |
| 314 | set(clang_sanitizer_preload libclang_rt.asan-x86_64.so) |
| 315 | endif() |
| 316 | |
| 317 | if (sanitizer_active) |
| 318 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 319 | execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=${clang_sanitizer_preload} |
| 320 | OUTPUT_VARIABLE LIBxSAN_FULL_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 321 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 322 | execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=${gcc_sanitizer_preload} |
| 323 | OUTPUT_VARIABLE LIBxSAN_FULL_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 324 | else() |
| 325 | message(ERROR "Cannot determine correct sanitizer library for LD_PRELOAD") |
| 326 | endif() |
| 327 | set_property(TEST test_netconf_cli_py APPEND PROPERTY ENVIRONMENT |
| 328 | LD_PRELOAD=${LIBxSAN_FULL_PATH} |
| 329 | ASAN_OPTIONS=detect_leaks=0 # they look harmless, but they are annoying |
| 330 | ) |
| 331 | endif() |
| 332 | endif() |
| 333 | endif() |
| 334 | |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 335 | if(WITH_DOCS) |
| 336 | set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) |
| 337 | set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) |
| 338 | configure_file(${doxyfile_in} ${doxyfile} @ONLY) |
| 339 | add_custom_target(doc |
| 340 | COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} |
| 341 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 342 | COMMENT "Generating API documentation with Doxygen" |
| 343 | VERBATIM |
| 344 | SOURCES ${doxyfile_in} |
| 345 | ) |
| 346 | endif() |
Jan Kundrát | 10f4990 | 2018-05-22 17:01:45 +0200 | [diff] [blame] | 347 | |
| 348 | install(TARGETS |
Václav Kubernát | b79f3ca | 2020-02-04 15:56:01 +0100 | [diff] [blame] | 349 | sysrepo-cli |
Jan Kundrát | 10f4990 | 2018-05-22 17:01:45 +0200 | [diff] [blame] | 350 | RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/) |