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) |
Václav Kubernát | 385dcdd | 2020-11-25 17:46:54 +0100 | [diff] [blame] | 3 | set(CMAKE_CXX_STANDARD 20) |
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) |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 8 | include(CTest) |
Jan Kundrát | d47f655 | 2018-03-02 13:40:11 +0100 | [diff] [blame] | 9 | |
| 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. |
| 17 | if(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") |
| 22 | endif() |
| 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. |
| 27 | set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}") |
| 28 | |
| 29 | # I don't want to duplicate the compiler's optimizations |
| 30 | set(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át | 8483414 | 2020-02-07 19:25:55 +0100 | [diff] [blame] | 34 | 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] | 35 | |
| 36 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 37 | set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}") |
| 38 | endif() |
Jan Kundrát | d47f655 | 2018-03-02 13:40:11 +0100 | [diff] [blame] | 39 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 40 | add_custom_target(git-version-cmake-ide |
| 41 | cmake/ProjectGitVersion.cmake |
| 42 | cmake/ProjectGitVersionRunner.cmake |
Jan Kundrát | 75c88c5 | 2020-11-12 01:51:26 +0100 | [diff] [blame] | 43 | cmake/DiscoverNetconfExecutables.cmake |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 44 | ) |
| 45 | include(cmake/ProjectGitVersion.cmake) |
| 46 | prepare_git_version(NETCONF_CLI_VERSION "0.0") |
| 47 | |
Jan Kundrát | c28a21b | 2020-11-11 15:45:43 +0100 | [diff] [blame] | 48 | # 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 |
| 51 | set(THREADS_PREFER_PTHREAD_FLAG ON) |
| 52 | find_package(Threads) |
| 53 | |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 54 | find_package(Doxygen) |
| 55 | option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND}) |
| 56 | |
Jan Kundrát | d47f655 | 2018-03-02 13:40:11 +0100 | [diff] [blame] | 57 | find_package(docopt REQUIRED) |
Václav Kubernát | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 58 | find_package(Boost REQUIRED COMPONENTS filesystem) |
Václav Kubernát | 385dcdd | 2020-11-25 17:46:54 +0100 | [diff] [blame] | 59 | # Fixes C++20 build |
| 60 | # https://github.com/boostorg/asio/issues/312 |
| 61 | add_definitions(-DBOOST_ASIO_DISABLE_CONCEPTS) |
Václav Kubernát | f8ca364 | 2020-11-26 04:16:39 +0100 | [diff] [blame] | 62 | find_package(replxx REQUIRED) |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 63 | |
Jan Kundrát | e05448a | 2018-06-13 15:54:33 +0200 | [diff] [blame] | 64 | find_package(PkgConfig) |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 65 | |
| 66 | set(ENABLE_SYSREPO_CLI AUTO CACHE STRING "Enable the `sysrepo-cli`") |
| 67 | set_property(CACHE ENABLE_SYSREPO_CLI PROPERTY STRINGS AUTO ON OFF) |
| 68 | set(ENABLE_FULL_TESTS AUTO CACHE STRING "Enable end-to-end tests via sysrepo and netopeer2") |
| 69 | set_property(CACHE ENABLE_FULL_TESTS PROPERTY STRINGS AUTO ON OFF) |
| 70 | if(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") |
| 72 | endif() |
| 73 | if(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") |
| 75 | endif() |
| 76 | if(NOT BUILD_TESTING AND ENABLE_FULL_TESTS STREQUAL ON) |
| 77 | message(FATAL_ERROR "Cannot combine ENABLE_FULL_TESTS=ON with BUILD_TESTING=OFF") |
| 78 | endif() |
| 79 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 80 | pkg_check_modules(LIBYANG-CPP REQUIRED libyang-cpp>=1.0.0 IMPORTED_TARGET) |
Václav Kubernát | bde37ba | 2022-03-25 15:18:12 +0100 | [diff] [blame] | 81 | pkg_check_modules(LIBNETCONF2-CPP REQUIRED libnetconf2-cpp>=1.0.0 IMPORTED_TARGET) |
Jan Kundrát | e05448a | 2018-06-13 15:54:33 +0200 | [diff] [blame] | 82 | |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 83 | if(ENABLE_FULL_TESTS STREQUAL OFF AND ENABLE_SYSREPO_CLI STREQUAL OFF) |
| 84 | message(STATUS "Skipping sysrepo per configure options") |
| 85 | set(SYSREPO_FOUND 0) |
| 86 | else() |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 87 | pkg_check_modules(SYSREPO sysrepo-cpp>=1.0.0 IMPORTED_TARGET sysrepo) |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 88 | endif() |
| 89 | |
| 90 | if(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() |
| 111 | else() |
| 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() |
| 127 | endif() |
| 128 | |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 129 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src/) |
| 130 | |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 131 | add_library(ast_values STATIC |
| 132 | src/ast_values.cpp |
| 133 | ) |
Jan Kundrát | 688041f | 2020-03-31 10:02:49 +0200 | [diff] [blame] | 134 | target_link_libraries(ast_values PUBLIC Boost::boost) |
| 135 | |
| 136 | add_library(path STATIC |
| 137 | src/ast_path.cpp |
| 138 | ) |
| 139 | target_link_libraries(path PUBLIC ast_values Boost::boost) |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 140 | |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 141 | add_library(leaf_data_type STATIC |
| 142 | src/leaf_data_type.cpp |
| 143 | ) |
| 144 | target_link_libraries(leaf_data_type ast_values) |
| 145 | |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 146 | add_library(utils STATIC |
| 147 | src/utils.cpp |
| 148 | ) |
Jan Kundrát | 688041f | 2020-03-31 10:02:49 +0200 | [diff] [blame] | 149 | target_link_libraries(utils path ast_values) |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 150 | |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 151 | add_library(schemas STATIC |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 152 | src/static_schema.cpp |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 153 | src/schema.cpp |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 154 | ) |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 155 | target_link_libraries(schemas PUBLIC path leaf_data_type Boost::boost) |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 156 | |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 157 | add_library(datastoreaccess STATIC |
| 158 | src/datastore_access.cpp |
Václav Kubernát | ab612e9 | 2019-11-26 19:51:31 +0100 | [diff] [blame] | 159 | src/data_query.cpp |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 160 | ) |
| 161 | target_link_libraries(datastoreaccess PUBLIC Boost::boost) |
| 162 | |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 163 | if(DO_ENABLE_SYSREPO_CLI OR DO_ENABLE_NETCONF_TESTS) |
| 164 | add_library(sysrepoaccess STATIC |
| 165 | src/sysrepo_access.cpp |
| 166 | ) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 167 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 168 | target_link_libraries(sysrepoaccess PUBLIC datastoreaccess ast_values PkgConfig::SYSREPO PRIVATE PkgConfig::LIBYANG-CPP) |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 169 | endif() |
Václav Kubernát | 80aacc0 | 2018-08-22 17:41:54 +0200 | [diff] [blame] | 170 | |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 171 | add_library(netconfaccess STATIC |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 172 | src/netconf_access.cpp |
| 173 | ) |
| 174 | |
Václav Kubernát | bde37ba | 2022-03-25 15:18:12 +0100 | [diff] [blame] | 175 | target_link_libraries(netconfaccess PUBLIC datastoreaccess yangschema ast_values utils PkgConfig::LIBNETCONF2-CPP PkgConfig::LIBYANG-CPP) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 176 | |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 177 | add_library(yangaccess STATIC |
| 178 | src/yang_access.cpp |
| 179 | ) |
| 180 | |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 181 | target_link_libraries(yangaccess PUBLIC datastoreaccess yangschema PRIVATE PkgConfig::LIBYANG-CPP) |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 182 | |
Jan Kundrát | 2b33536 | 2020-11-05 20:40:45 +0100 | [diff] [blame] | 183 | add_library(yangutils STATIC |
Václav Kubernát | 02a7115 | 2020-01-21 14:52:51 +0100 | [diff] [blame] | 184 | src/libyang_utils.cpp |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 185 | ) |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 186 | target_link_libraries(yangutils PUBLIC PkgConfig::LIBYANG-CPP) |
Václav Kubernát | 2e4cafe | 2020-11-05 01:53:21 +0100 | [diff] [blame] | 187 | |
| 188 | add_library(yangschema STATIC |
| 189 | src/yang_schema.cpp |
| 190 | ) |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 191 | target_link_libraries(yangschema PUBLIC schemas utils yangutils PRIVATE PkgConfig::LIBYANG-CPP) |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 192 | |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 193 | add_library(parser STATIC |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 194 | src/parser.cpp |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 195 | src/ast_commands.cpp |
Václav Kubernát | 195eeea | 2018-05-18 13:52:36 +0200 | [diff] [blame] | 196 | src/parser_context.cpp |
Václav Kubernát | 96344a1 | 2018-05-28 16:33:39 +0200 | [diff] [blame] | 197 | src/interpreter.cpp |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 198 | src/ast_handlers.cpp |
Václav Kubernát | cb3af40 | 2020-02-12 16:49:17 +0100 | [diff] [blame] | 199 | src/completion.cpp |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 200 | ) |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 201 | target_link_libraries(parser schemas utils ast_values yangutils) |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 202 | |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 203 | add_library(proxydatastore STATIC |
| 204 | src/proxy_datastore.cpp |
| 205 | ) |
Václav Kubernát | e7248b2 | 2020-06-26 15:38:59 +0200 | [diff] [blame] | 206 | target_link_libraries(proxydatastore PUBLIC datastoreaccess yangaccess) |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 207 | |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 208 | # Links libraries, that aren't specific to a datastore type |
| 209 | function(cli_link_required cli_target) |
Václav Kubernát | f8ca364 | 2020-11-26 04:16:39 +0100 | [diff] [blame] | 210 | target_link_libraries(${cli_target} proxydatastore yangschema docopt parser replxx::replxx) |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 211 | add_dependencies(${cli_target} target-NETCONF_CLI_VERSION) |
| 212 | target_include_directories(${cli_target} PRIVATE ${PROJECT_BINARY_DIR}) |
| 213 | endfunction() |
| 214 | |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 215 | if(DO_ENABLE_SYSREPO_CLI) |
| 216 | add_executable(sysrepo-cli |
| 217 | src/cli.cpp |
| 218 | ) |
| 219 | target_compile_definitions(sysrepo-cli PRIVATE SYSREPO_CLI) |
| 220 | target_link_libraries(sysrepo-cli sysrepoaccess) |
| 221 | cli_link_required(sysrepo-cli) |
| 222 | list(APPEND cli_targets sysrepo-cli) |
| 223 | endif() |
Václav Kubernát | 2b68461 | 2018-08-09 18:55:24 +0200 | [diff] [blame] | 224 | |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 225 | add_executable(yang-cli |
| 226 | src/cli.cpp |
| 227 | ) |
| 228 | target_compile_definitions(yang-cli PRIVATE YANG_CLI) |
| 229 | cli_link_required(yang-cli) |
| 230 | target_link_libraries(yang-cli yangaccess) |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 231 | list(APPEND cli_targets yang-cli) |
Václav Kubernát | 619e654 | 2020-06-29 14:13:43 +0200 | [diff] [blame] | 232 | if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+" AND CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.0) |
| 233 | target_link_libraries(yang-cli c++experimental) |
| 234 | elseif(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 9.1) |
| 235 | target_link_libraries(yang-cli stdc++fs) |
| 236 | endif() |
| 237 | |
Václav Kubernát | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 238 | add_executable(netconf-cli |
| 239 | src/cli.cpp |
| 240 | src/cli-netconf.cpp |
| 241 | ) |
| 242 | target_compile_definitions(netconf-cli PRIVATE NETCONF_CLI) |
| 243 | |
Václav Kubernát | e2e15ee | 2020-02-05 17:38:13 +0100 | [diff] [blame] | 244 | target_link_libraries(netconf-cli netconfaccess Threads::Threads Boost::filesystem) |
| 245 | cli_link_required(netconf-cli) |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 246 | list(APPEND cli_targets netconf-cli) |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 247 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 248 | |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 249 | if(BUILD_TESTING) |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 250 | find_package(trompeloeil 33 REQUIRED) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 251 | find_package(doctest 2.3.1 REQUIRED) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 252 | |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 253 | add_library(DoctestIntegration STATIC |
| 254 | tests/doctest_integration.cpp |
Václav Kubernát | 26b5608 | 2020-02-03 18:28:56 +0100 | [diff] [blame] | 255 | tests/trompeloeil_doctest.hpp |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 256 | tests/wait-a-bit-longer.cpp |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 257 | ) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 258 | target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/) |
Václav Kubernát | cfdb922 | 2021-07-07 22:36:24 +0200 | [diff] [blame] | 259 | target_link_libraries(DoctestIntegration doctest::doctest trompeloeil::trompeloeil) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 260 | target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 261 | |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 262 | if(DO_ENABLE_NETCONF_TESTS) |
| 263 | add_library(sysreposubscription STATIC |
| 264 | tests/mock/sysrepo_subscription.cpp |
| 265 | ) |
Václav Kubernát | eaf5668 | 2021-02-22 17:15:41 +0100 | [diff] [blame] | 266 | target_link_libraries(sysreposubscription PUBLIC datastoreaccess PkgConfig::SYSREPO) |
Jan Kundrát | bb525b4 | 2020-02-04 11:56:59 +0100 | [diff] [blame] | 267 | |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 268 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_repositories) |
Jan Kundrát | 805d02c | 2020-11-13 20:20:44 +0100 | [diff] [blame] | 269 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_netopeer_files) |
Václav Kubernát | 634e24a | 2020-11-19 01:20:27 +0100 | [diff] [blame] | 270 | file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/test_netopeer_outputs) |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 271 | endif() |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 272 | |
| 273 | 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] | 274 | |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 275 | function(cli_test name) |
| 276 | if (${ARGC} GREATER 1) # this is how CMake does optional arguments |
| 277 | add_executable(test_${name} |
| 278 | tests/${ARGV1} |
| 279 | ) |
| 280 | else() |
| 281 | add_executable(test_${name} |
| 282 | tests/${name}.cpp |
| 283 | ) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 284 | endif() |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 285 | target_link_libraries(test_${name} DoctestIntegration parser datastoreaccess) |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 286 | if(NOT CMAKE_CROSSCOMPILING) |
| 287 | add_test(test_${name} test_${name}) |
| 288 | endif() |
| 289 | target_include_directories(test_${name} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
Jan Kundrát | cc4c1f2 | 2018-08-09 15:00:03 +0200 | [diff] [blame] | 290 | endfunction() |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 291 | |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 292 | function(datastore_test_impl name model backend) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 293 | set(TESTNAME test_${name}_${backend}) |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 294 | |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 295 | cli_test(${name}_${backend} ${name}.cpp) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 296 | target_include_directories(${TESTNAME} PRIVATE ${PROJECT_SOURCE_DIR}/tests/mock) |
| 297 | if (${backend} STREQUAL "sysrepo") |
| 298 | target_link_libraries(${TESTNAME} sysrepoaccess) |
| 299 | elseif (${backend} STREQUAL "netconf") |
| 300 | target_link_libraries(${TESTNAME} netconfaccess) |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 301 | elseif (${backend} STREQUAL "yang") |
| 302 | target_link_libraries(${TESTNAME} yangaccess) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 303 | else() |
| 304 | message(FATAL_ERROR "Unknown backend ${backend}") |
| 305 | endif() |
Václav Kubernát | 3ea893e | 2020-10-19 16:33:01 +0200 | [diff] [blame] | 306 | target_link_libraries(${TESTNAME} yangschema sysreposubscription proxydatastore PkgConfig::SYSREPO) |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 307 | |
| 308 | target_compile_definitions(${TESTNAME} PRIVATE ${backend}_BACKEND) |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 309 | set_tests_properties(${TESTNAME} PROPERTIES FIXTURES_REQUIRED ${TESTNAME}_setup) |
| 310 | |
| 311 | add_test(NAME ${TESTNAME}_init COMMAND ${CMAKE_CURRENT_BINARY_DIR}/init_datastore.bash "${model}" "${backend}") |
| 312 | set_tests_properties(${TESTNAME}_init PROPERTIES FIXTURES_SETUP ${TESTNAME}_setup) |
| 313 | add_test(NAME ${TESTNAME}_cleanup COMMAND ${CMAKE_CURRENT_BINARY_DIR}/cleanup_datastore.bash "${backend}") |
| 314 | set_tests_properties(${TESTNAME}_cleanup PROPERTIES FIXTURES_CLEANUP ${TESTNAME}_setup) |
| 315 | |
| 316 | set_property(TEST ${TESTNAME} ${TESTNAME}_init ${TESTNAME}_cleanup APPEND PROPERTY ENVIRONMENT |
| 317 | "SYSREPO_REPOSITORY_PATH=${CMAKE_CURRENT_BINARY_DIR}/test_repositories/${TESTNAME}" |
| 318 | "SYSREPO_SHM_PREFIX=netconf-cli_${TESTNAME}" |
Jan Kundrát | 9a7f742 | 2021-01-04 17:01:53 +0100 | [diff] [blame] | 319 | "NETOPEER_SOCKET=test_netopeer_files/${TESTNAME}.sock" |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 320 | ) |
| 321 | |
Václav Kubernát | 7d47864 | 2019-11-22 17:38:11 +0100 | [diff] [blame] | 322 | endfunction() |
| 323 | |
Václav Kubernát | 1acf4f1 | 2020-01-31 15:54:34 +0100 | [diff] [blame] | 324 | function(datastore_test name model) |
| 325 | datastore_test_impl(${name} ${model} sysrepo) |
| 326 | datastore_test_impl(${name} ${model} netconf) |
Václav Kubernát | 74487df | 2020-06-04 01:29:28 +0200 | [diff] [blame] | 327 | datastore_test_impl(${name} ${model} yang) |
Václav Kubernát | 8832481 | 2019-06-26 17:36:29 +0200 | [diff] [blame] | 328 | endfunction() |
| 329 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 330 | cli_test(cd) |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 331 | cli_test(ls) |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 332 | cli_test(presence_containers) |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 333 | cli_test(leaf_editing) |
Václav Kubernát | 3a99f00 | 2020-03-31 02:27:41 +0200 | [diff] [blame] | 334 | target_link_libraries(test_leaf_editing leaf_data_type) |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 335 | cli_test(yang) |
| 336 | target_link_libraries(test_yang yangschema) |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 337 | cli_test(utils) |
Jan Kundrát | 2b33536 | 2020-11-05 20:40:45 +0100 | [diff] [blame] | 338 | target_link_libraries(test_utils yangutils) |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 339 | cli_test(path_completion) |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 340 | cli_test(command_completion) |
Václav Kubernát | 549b08f | 2020-05-14 22:19:36 +0200 | [diff] [blame] | 341 | cli_test(set_value_completion) |
| 342 | target_link_libraries(test_set_value_completion leaf_data_type) |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 343 | cli_test(list_manipulation) |
Václav Kubernát | 5452ede | 2020-06-10 12:05:11 +0200 | [diff] [blame] | 344 | cli_test(interpreter) |
Václav Kubernát | 48e9dfa | 2020-07-08 10:55:12 +0200 | [diff] [blame] | 345 | target_link_libraries(test_interpreter proxydatastore) |
Václav Kubernát | 5395e71 | 2019-12-03 18:24:33 +0100 | [diff] [blame] | 346 | cli_test(path_utils) |
Václav Kubernát | 7edb537 | 2019-12-13 12:40:49 +0100 | [diff] [blame] | 347 | target_link_libraries(test_path_utils path) |
Václav Kubernát | 43908fb | 2020-01-02 19:05:51 +0100 | [diff] [blame] | 348 | cli_test(keyvalue_completion) |
Václav Kubernát | d8408e0 | 2020-12-02 05:13:27 +0100 | [diff] [blame] | 349 | cli_test(parser_rpc) |
Václav Kubernát | 1d59390 | 2021-03-08 08:55:16 +0100 | [diff] [blame] | 350 | cli_test(misc_commands) |
Václav Kubernát | c31bd60 | 2019-03-07 11:44:48 +0100 | [diff] [blame] | 351 | |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 352 | 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át | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 358 | 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át | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 362 | endif() |
| 363 | |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 364 | option(WITH_PYTHON_BINDINGS "Create and install Python3 bindings for accessing datastores" OFF) |
| 365 | if(WITH_PYTHON_BINDINGS) |
Václav Kubernát | 385dcdd | 2020-11-25 17:46:54 +0100 | [diff] [blame] | 366 | set(PYBIND11_CPP_STANDARD -std=c++20) |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 367 | 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át | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 372 | 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át | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 375 | configure_file(${CMAKE_CURRENT_SOURCE_DIR}/tests/python_netconfaccess.py |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 376 | ${CMAKE_CURRENT_BINARY_DIR}/tests_python_netconfaccess.py COPYONLY) |
| 377 | |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 378 | 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] | 379 | 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át | 9a7f742 | 2021-01-04 17:01:53 +0100 | [diff] [blame] | 389 | "NETOPEER_SOCKET=test_netopeer_files/test_netconf_cli_py.sock" |
Václav Kubernát | d1beedc | 2020-09-07 12:09:05 +0200 | [diff] [blame] | 390 | ) |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 391 | |
| 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() |
| 421 | endif() |
| 422 | |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 423 | if(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 | ) |
| 434 | endif() |
Jan Kundrát | 10f4990 | 2018-05-22 17:01:45 +0200 | [diff] [blame] | 435 | |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 436 | install(TARGETS ${cli_targets} |
Jan Kundrát | 10f4990 | 2018-05-22 17:01:45 +0200 | [diff] [blame] | 437 | RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/) |