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) |
Václav Kubernát | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 52 | find_package(Boost REQUIRED COMPONENTS filesystem) |
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) |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 60 | pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=1.0.190 IMPORTED_TARGET libyang) |
| 61 | pkg_check_modules(SYSREPO REQUIRED sysrepo-cpp>=1.4.79 IMPORTED_TARGET sysrepo) |
| 62 | pkg_check_modules(LIBNETCONF2 REQUIRED libnetconf2>=1.1.32 IMPORTED_TARGET libnetconf2) |
Jan Kundrát | e05448a | 2018-06-13 15:54:33 +0200 | [diff] [blame] | 63 | |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 64 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/) |
| 65 | |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 66 | add_library(ast_values STATIC |
| 67 | src/ast_values.cpp |
| 68 | ) |
Jan Kundrát | 688041f | 2020-03-31 10:02:49 +0200 | [diff] [blame] | 69 | target_link_libraries(ast_values PUBLIC Boost::boost) |
| 70 | |
| 71 | add_library(path STATIC |
| 72 | src/ast_path.cpp |
| 73 | ) |
| 74 | target_link_libraries(path PUBLIC ast_values Boost::boost) |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 75 | |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 76 | add_library(leaf_data_type STATIC |
| 77 | src/leaf_data_type.cpp |
| 78 | ) |
| 79 | target_link_libraries(leaf_data_type ast_values) |
| 80 | |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 81 | add_library(utils STATIC |
| 82 | src/utils.cpp |
| 83 | ) |
Jan Kundrát | 688041f | 2020-03-31 10:02:49 +0200 | [diff] [blame] | 84 | target_link_libraries(utils path ast_values) |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 85 | |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 86 | add_library(schemas STATIC |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 87 | src/static_schema.cpp |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 88 | src/schema.cpp |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 89 | ) |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 90 | target_link_libraries(schemas PUBLIC path leaf_data_type Boost::boost) |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 91 | |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 92 | add_library(datastoreaccess STATIC |
| 93 | src/datastore_access.cpp |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 94 | src/data_query.cpp |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 95 | ) |
| 96 | target_link_libraries(datastoreaccess PUBLIC Boost::boost) |
| 97 | |
Václav Kubernát | 80aacc0 | 2018-08-22 17:41:54 +0200 | [diff] [blame] | 98 | add_library(sysrepoaccess STATIC |
| 99 | src/sysrepo_access.cpp |
| 100 | ) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 101 | |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 102 | target_link_libraries(sysrepoaccess PUBLIC datastoreaccess ast_values PRIVATE PkgConfig::SYSREPO PkgConfig::LIBYANG) |
Václav Kubernát | 80aacc0 | 2018-08-22 17:41:54 +0200 | [diff] [blame] | 103 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 104 | add_library(netconfaccess STATIC |
| 105 | src/netconf-client.cpp |
| 106 | src/netconf_access.cpp |
| 107 | ) |
| 108 | |
Václav Kubernát | 3ea893e | 2020-10-19 16:33:01 +0200 | [diff] [blame] | 109 | target_link_libraries(netconfaccess PUBLIC datastoreaccess yangschema ast_values utils PkgConfig::LIBNETCONF2 PRIVATE PkgConfig::LIBYANG) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 110 | |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 111 | add_library(yangaccess STATIC |
| 112 | src/yang_access.cpp |
| 113 | ) |
| 114 | |
Václav Kubernát | 3ea893e | 2020-10-19 16:33:01 +0200 | [diff] [blame] | 115 | target_link_libraries(yangaccess PUBLIC datastoreaccess yangschema PRIVATE PkgConfig::LIBYANG) |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 116 | |
Jan Kundrát | 2b33536 | 2020-11-05 20:40:45 +0100 | [diff] [blame] | 117 | add_library(yangutils STATIC |
Václav Kubernát | 02a7115 | 2020-01-21 14:52:51 +0100 | [diff] [blame] | 118 | src/libyang_utils.cpp |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 119 | ) |
Jan Kundrát | 2b33536 | 2020-11-05 20:40:45 +0100 | [diff] [blame] | 120 | target_link_libraries(yangutils PUBLIC PkgConfig::LIBYANG) |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 121 | |
| 122 | add_library(yangschema STATIC |
| 123 | src/yang_schema.cpp |
| 124 | ) |
Jan Kundrát | 2b33536 | 2020-11-05 20:40:45 +0100 | [diff] [blame] | 125 | target_link_libraries(yangschema PUBLIC schemas utils yangutils PRIVATE PkgConfig::LIBYANG) |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 126 | |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 127 | add_library(parser STATIC |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 128 | src/parser.cpp |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 129 | src/ast_commands.cpp |
Václav Kubernát | 195eeea | 2018-05-18 13:52:36 +0200 | [diff] [blame] | 130 | src/parser_context.cpp |
Václav Kubernát | 96344a1 | 2018-05-28 16:33:39 +0200 | [diff] [blame] | 131 | src/interpreter.cpp |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 132 | src/ast_handlers.cpp |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 133 | src/completion.cpp |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 134 | ) |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 135 | target_link_libraries(parser schemas utils ast_values) |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 136 | |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 137 | add_library(proxydatastore STATIC |
| 138 | src/proxy_datastore.cpp |
| 139 | ) |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 140 | target_link_libraries(proxydatastore PUBLIC datastoreaccess yangaccess) |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 141 | |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 142 | # Links libraries, that aren't specific to a datastore type |
| 143 | function(cli_link_required cli_target) |
| 144 | target_include_directories(${cli_target} PRIVATE ${REPLXX_PATH}) |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 145 | target_link_libraries(${cli_target} proxydatastore yangschema docopt parser ${REPLXX_LIBRARY}) |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 146 | add_dependencies(${cli_target} target-NETCONF_CLI_VERSION) |
| 147 | target_include_directories(${cli_target} PRIVATE ${PROJECT_BINARY_DIR}) |
| 148 | endfunction() |
| 149 | |
Václav Kubernát | b79f3ca | 2020-02-04 15:56:01 +0100 | [diff] [blame] | 150 | add_executable(sysrepo-cli |
| 151 | src/cli.cpp |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 152 | ) |
Václav Kubernát | b79f3ca | 2020-02-04 15:56:01 +0100 | [diff] [blame] | 153 | target_compile_definitions(sysrepo-cli PRIVATE SYSREPO_CLI) |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 154 | target_link_libraries(sysrepo-cli sysrepoaccess) |
| 155 | cli_link_required(sysrepo-cli) |
Václav Kubernát | 2b68461 | 2018-08-09 18:55:24 +0200 | [diff] [blame] | 156 | |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 157 | add_executable(yang-cli |
| 158 | src/cli.cpp |
| 159 | ) |
| 160 | target_compile_definitions(yang-cli PRIVATE YANG_CLI) |
| 161 | cli_link_required(yang-cli) |
| 162 | target_link_libraries(yang-cli yangaccess) |
Václav Kubernát | 619e654 | 2020-06-29 14:13:43 +0200 | [diff] [blame] | 163 | if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) |
| 164 | target_link_libraries(yang-cli c++experimental) |
| 165 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1) |
| 166 | target_link_libraries(yang-cli stdc++fs) |
| 167 | endif() |
| 168 | |
Václav Kubernát | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 169 | add_executable(netconf-cli |
| 170 | src/cli.cpp |
| 171 | src/cli-netconf.cpp |
| 172 | ) |
| 173 | target_compile_definitions(netconf-cli PRIVATE NETCONF_CLI) |
| 174 | |
| 175 | # Boost.Process needs linking with threads, but doesn't have special CMake target which would do that for us. So, we |
| 176 | # need to link manually. This will hopefully change in the future. |
| 177 | # https://discourse.cmake.org/t/boost-process-target-doesnt-exist-for-thread-linking/2113 |
| 178 | set(THREADS_PREFER_PTHREAD_FLAG ON) |
| 179 | find_package(Threads) |
| 180 | target_link_libraries(netconf-cli netconfaccess Threads::Threads Boost::filesystem) |
| 181 | cli_link_required(netconf-cli) |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 182 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 183 | |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 184 | include(CTest) |
| 185 | if(BUILD_TESTING) |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 186 | find_package(trompeloeil 33 REQUIRED) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 187 | find_package(doctest 2.3.1 REQUIRED) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 188 | |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 189 | add_library(DoctestIntegration STATIC |
| 190 | tests/doctest_integration.cpp |
Václav Kubernát | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 191 | tests/trompeloeil_doctest.hpp |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 192 | tests/wait-a-bit-longer.cpp |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 193 | ) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 194 | 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] | 195 | target_link_libraries(DoctestIntegration doctest::doctest trompeloeil) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 196 | target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 197 | |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 198 | add_library(sysreposubscription STATIC |
| 199 | tests/mock/sysrepo_subscription.cpp |
| 200 | ) |
| 201 | target_link_libraries(sysreposubscription PUBLIC datastoreaccess PRIVATE PkgConfig::SYSREPO) |
| 202 | |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 203 | if (NOT SYSREPOCTL_EXECUTABLE) |
| 204 | find_program(SYSREPOCTL_EXECUTABLE sysrepoctl) |
| 205 | endif() |
| 206 | if (NOT SYSREPOCTL_EXECUTABLE) |
| 207 | message(FATAL_ERROR "Unable to find sysrepoctl, set SYSREPOCTL_EXECUTABLE manually.") |
| 208 | endif() |
| 209 | |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 210 | if (NOT SYSREPOCFG_EXECUTABLE) |
| 211 | find_program(SYSREPOCFG_EXECUTABLE sysrepocfg) |
| 212 | endif() |
| 213 | if (NOT SYSREPOCFG_EXECUTABLE) |
| 214 | message(FATAL_ERROR "Unable to find sysrepocfg, set SYSREPOCFG_EXECUTABLE manually.") |
| 215 | endif() |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 216 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 217 | if (NOT NETOPEER2_EXECUTABLE) |
| 218 | find_program(NETOPEER2_EXECUTABLE netopeer2-server) |
| 219 | endif() |
| 220 | if (NOT NETOPEER2_EXECUTABLE) |
| 221 | message(FATAL_ERROR "Unable to find netopeer2-server, set NETOPEER2_EXECUTABLE manually.") |
| 222 | endif() |
| 223 | |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 224 | pkg_get_variable(SYSREPO_SR_REPO_PATH sysrepo SR_REPO_PATH) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 225 | |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 226 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_repositories) |
| 227 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_sockets) |
| 228 | |
| 229 | 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át | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 230 | |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 231 | function(cli_test name) |
| 232 | if (${ARGC} GREATER 1) # this is how CMake does optional arguments |
| 233 | add_executable(test_${name} |
| 234 | tests/${ARGV1} |
| 235 | ) |
| 236 | else() |
| 237 | add_executable(test_${name} |
| 238 | tests/${name}.cpp |
| 239 | ) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 240 | endif() |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 241 | target_link_libraries(test_${name} DoctestIntegration parser datastoreaccess) |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 242 | if(NOT CMAKE_CROSSCOMPILING) |
| 243 | add_test(test_${name} test_${name}) |
| 244 | endif() |
| 245 | target_include_directories(test_${name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
Jan Kundrát | cc4c1f2 | 2018-08-09 15:00:03 +0200 | [diff] [blame] | 246 | endfunction() |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 247 | |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 248 | function(datastore_test_impl name model backend) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 249 | set(TESTNAME test_${name}_${backend}) |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 250 | |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 251 | cli_test(${name}_${backend} ${name}.cpp) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 252 | target_include_directories(${TESTNAME} PRIVATE ${PROJECT_SOURCE_DIR}/tests/mock) |
| 253 | if (${backend} STREQUAL "sysrepo") |
| 254 | target_link_libraries(${TESTNAME} sysrepoaccess) |
| 255 | elseif (${backend} STREQUAL "netconf") |
| 256 | target_link_libraries(${TESTNAME} netconfaccess) |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 257 | elseif (${backend} STREQUAL "yang") |
| 258 | target_link_libraries(${TESTNAME} yangaccess) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 259 | else() |
| 260 | message(FATAL_ERROR "Unknown backend ${backend}") |
| 261 | endif() |
Václav Kubernát | 3ea893e | 2020-10-19 16:33:01 +0200 | [diff] [blame] | 262 | target_link_libraries(${TESTNAME} yangschema sysreposubscription proxydatastore PkgConfig::SYSREPO) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 263 | |
| 264 | target_compile_definitions(${TESTNAME} PRIVATE ${backend}_BACKEND) |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 265 | set_tests_properties(${TESTNAME} PROPERTIES FIXTURES_REQUIRED ${TESTNAME}_setup) |
| 266 | |
| 267 | add_test(NAME ${TESTNAME}_init COMMAND ${CMAKE_CURRENT_BINARY_DIR}/init_datastore.bash "${model}" "${backend}") |
| 268 | set_tests_properties(${TESTNAME}_init PROPERTIES FIXTURES_SETUP ${TESTNAME}_setup) |
| 269 | add_test(NAME ${TESTNAME}_cleanup COMMAND ${CMAKE_CURRENT_BINARY_DIR}/cleanup_datastore.bash "${backend}") |
| 270 | set_tests_properties(${TESTNAME}_cleanup PROPERTIES FIXTURES_CLEANUP ${TESTNAME}_setup) |
| 271 | |
| 272 | set_property(TEST ${TESTNAME} ${TESTNAME}_init ${TESTNAME}_cleanup APPEND PROPERTY ENVIRONMENT |
| 273 | "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/${TESTNAME}" |
| 274 | "SYSREPO_SHM_PREFIX=netconf-cli_${TESTNAME}" |
| 275 | "NETOPEER_SOCKET=${CMAKE_CURRENT_BINARY_DIR}/test_sockets/${TESTNAME}.sock" |
| 276 | ) |
| 277 | |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 278 | endfunction() |
| 279 | |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 280 | function(datastore_test name model) |
| 281 | datastore_test_impl(${name} ${model} sysrepo) |
| 282 | datastore_test_impl(${name} ${model} netconf) |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 283 | datastore_test_impl(${name} ${model} yang) |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 284 | endfunction() |
| 285 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 286 | cli_test(cd) |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 287 | cli_test(ls) |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 288 | cli_test(presence_containers) |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 289 | cli_test(leaf_editing) |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 290 | target_link_libraries(test_leaf_editing leaf_data_type) |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 291 | cli_test(yang) |
| 292 | target_link_libraries(test_yang yangschema) |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 293 | cli_test(utils) |
Jan Kundrát | 2b33536 | 2020-11-05 20:40:45 +0100 | [diff] [blame] | 294 | target_link_libraries(test_utils yangutils) |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 295 | cli_test(path_completion) |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 296 | cli_test(command_completion) |
Václav Kubernát | 549b08f | 2020-05-14 22:19:36 +0200 | [diff] [blame] | 297 | cli_test(set_value_completion) |
| 298 | target_link_libraries(test_set_value_completion leaf_data_type) |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 299 | cli_test(list_manipulation) |
Václav Kubernát | 5452ede | 2020-06-10 12:05:11 +0200 | [diff] [blame] | 300 | cli_test(interpreter) |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 301 | target_link_libraries(test_interpreter proxydatastore) |
Václav Kubernát | 5395e71 | 2019-12-03 18:24:33 +0100 | [diff] [blame] | 302 | cli_test(path_utils) |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 303 | target_link_libraries(test_path_utils path) |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 304 | cli_test(keyvalue_completion) |
Václav Kubernát | 3d787b1 | 2020-10-29 09:11:26 +0100 | [diff] [blame] | 305 | cli_test(prepare) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 306 | |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 307 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/init_datastore.bash.in |
| 308 | ${CMAKE_CURRENT_BINARY_DIR}/init_datastore.bash @ONLY) |
| 309 | |
| 310 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/cleanup_datastore.bash.in |
| 311 | ${CMAKE_CURRENT_BINARY_DIR}/cleanup_datastore.bash @ONLY) |
| 312 | |
| 313 | datastore_test(datastore_access ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang) |
| 314 | datastore_test(data_query ${CMAKE_CURRENT_SOURCE_DIR}/tests/example-schema.yang) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 315 | endif() |
| 316 | |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 317 | option(WITH_PYTHON_BINDINGS "Create and install Python3 bindings for accessing datastores" OFF) |
| 318 | if(WITH_PYTHON_BINDINGS) |
| 319 | set(PYBIND11_CPP_STANDARD -std=c++17) |
| 320 | find_package(pybind11 REQUIRED) |
| 321 | pybind11_add_module(netconf_cli_py src/python_netconf.cpp) |
| 322 | target_link_libraries(netconf_cli_py PUBLIC netconfaccess) |
| 323 | |
| 324 | if(BUILD_TESTING) |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 325 | pybind11_add_module(sysrepo_subscription_py tests/mock/sysrepo_subscription_python.cpp) |
| 326 | target_link_libraries(sysrepo_subscription_py PUBLIC sysreposubscription utils) |
| 327 | |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 328 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/python_netconfaccess.py |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 329 | ${CMAKE_CURRENT_BINARY_DIR}/tests_python_netconfaccess.py COPYONLY) |
| 330 | |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 331 | add_test(NAME test_netconf_cli_py COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/tests_python_netconfaccess.py) |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 332 | set_tests_properties(test_netconf_cli_py PROPERTIES FIXTURES_REQUIRED test_netconf_cli_py_setup) |
| 333 | |
| 334 | 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") |
| 335 | set_tests_properties(test_netconf_cli_py_init PROPERTIES FIXTURES_SETUP test_netconf_cli_py_setup) |
| 336 | add_test(NAME test_netconf_cli_py_cleanup COMMAND ${CMAKE_CURRENT_BINARY_DIR}/cleanup_datastore.bash "netconf") |
| 337 | set_tests_properties(test_netconf_cli_py_cleanup PROPERTIES FIXTURES_CLEANUP test_netconf_cli_py_setup) |
| 338 | |
| 339 | set_property(TEST test_netconf_cli_py test_netconf_cli_py_init test_netconf_cli_py_cleanup APPEND PROPERTY ENVIRONMENT |
| 340 | "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/test_netconf_cli_py" |
| 341 | "SYSREPO_SHM_PREFIX=netconf-cli_test_netconf_cli_py" |
| 342 | "NETOPEER_SOCKET=${CMAKE_CURRENT_BINARY_DIR}/test_sockets/test_netconf_cli_py.sock" |
| 343 | ) |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 344 | |
| 345 | set(sanitizer_active OFF) |
| 346 | # FIXME: this just sucks. The detection is very unreliable (one could use something like |
| 347 | # -fsanitize=address,undefined and we are screwed), and especially clang's query for preload |
| 348 | # is obviously unportable because we hardcode host's architecture. |
| 349 | # This is super-ugly. Perhaps it would be better just to outright disable everything, but hey, |
| 350 | # I need to test this on my laptop where I'm using ASAN by default, and it kinda-almost-works |
| 351 | # there with just one patch to libyang :). |
| 352 | if (${CMAKE_CXX_FLAGS} MATCHES "-fsanitize=address") |
| 353 | set(sanitizer_active ON) |
| 354 | set(gcc_sanitizer_preload libasan.so) |
| 355 | set(clang_sanitizer_preload libclang_rt.asan-x86_64.so) |
| 356 | endif() |
| 357 | |
| 358 | if (sanitizer_active) |
| 359 | if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") |
| 360 | execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=${clang_sanitizer_preload} |
| 361 | OUTPUT_VARIABLE LIBxSAN_FULL_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 362 | elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") |
| 363 | execute_process(COMMAND ${CMAKE_CXX_COMPILER} -print-file-name=${gcc_sanitizer_preload} |
| 364 | OUTPUT_VARIABLE LIBxSAN_FULL_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) |
| 365 | else() |
| 366 | message(ERROR "Cannot determine correct sanitizer library for LD_PRELOAD") |
| 367 | endif() |
| 368 | set_property(TEST test_netconf_cli_py APPEND PROPERTY ENVIRONMENT |
| 369 | LD_PRELOAD=${LIBxSAN_FULL_PATH} |
| 370 | ASAN_OPTIONS=detect_leaks=0 # they look harmless, but they are annoying |
| 371 | ) |
| 372 | endif() |
| 373 | endif() |
| 374 | endif() |
| 375 | |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 376 | if(WITH_DOCS) |
| 377 | set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) |
| 378 | set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) |
| 379 | configure_file(${doxyfile_in} ${doxyfile} @ONLY) |
| 380 | add_custom_target(doc |
| 381 | COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} |
| 382 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 383 | COMMENT "Generating API documentation with Doxygen" |
| 384 | VERBATIM |
| 385 | SOURCES ${doxyfile_in} |
| 386 | ) |
| 387 | endif() |
Jan Kundrát | 10f4990 | 2018-05-22 17:01:45 +0200 | [diff] [blame] | 388 | |
| 389 | install(TARGETS |
Václav Kubernát | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 390 | netconf-cli |
Václav Kubernát | b79f3ca | 2020-02-04 15:56:01 +0100 | [diff] [blame] | 391 | sysrepo-cli |
Jan Kundrát | 43e12e7 | 2020-11-02 20:36:37 +0100 | [diff] [blame] | 392 | yang-cli |
Jan Kundrát | 10f4990 | 2018-05-22 17:01:45 +0200 | [diff] [blame] | 393 | RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/) |