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 | d47f655 | 2018-03-02 13:40:11 +0100 | [diff] [blame] | 5 | |
| 6 | include(GNUInstallDirs) |
| 7 | |
| 8 | # Set a default build type if none was specified. This was shamelessly stolen |
| 9 | # from VTK's cmake setup because these guys produce both CMake and a project that |
| 10 | # manipulates this variable, and the web is full of posts where people say that |
| 11 | # it is apparently evil to just set the build type in a way an earlier version of |
| 12 | # this patch did. Oh, and the location of this check/update matters, apparently. |
| 13 | # |
| 14 | # Yes, this is just plain crazy. |
| 15 | if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) |
| 16 | message(STATUS "Setting build type to 'RelWithDebInfo' as none was specified.") |
| 17 | set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING "Choose the type of build." FORCE) |
| 18 | # Set the possible values of build type for cmake-gui |
| 19 | set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") |
| 20 | endif() |
| 21 | |
| 22 | # -Werror is not a default for sanity reasons (one cannot know what warnings a future compiler |
| 23 | # might bring along), but it's a default in debug mode. The idea is that developers should care |
| 24 | # about a warning-free build, and that this is easier than messing with yet another configure option. |
| 25 | set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}") |
| 26 | |
| 27 | # I don't want to duplicate the compiler's optimizations |
| 28 | set(CMAKE_CXX_FLAGS "-O2 ${CMAKE_CXX_FLAGS}") |
| 29 | |
| 30 | # Build warnings are useful tools (and this project should be warning-free anyway), enable them on all |
| 31 | # configurations. They are warnings, not errors. |
Jan Kundrát | fb83190 | 2018-05-26 18:58:52 +0200 | [diff] [blame] | 32 | set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual ${CMAKE_CXX_FLAGS}") |
| 33 | |
| 34 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") |
| 35 | set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}") |
| 36 | endif() |
Jan Kundrát | d47f655 | 2018-03-02 13:40:11 +0100 | [diff] [blame] | 37 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 38 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") |
| 39 | |
| 40 | add_custom_target(git-version-cmake-ide |
| 41 | cmake/ProjectGitVersion.cmake |
| 42 | cmake/ProjectGitVersionRunner.cmake |
| 43 | ) |
| 44 | include(cmake/ProjectGitVersion.cmake) |
| 45 | prepare_git_version(NETCONF_CLI_VERSION "0.0") |
| 46 | |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 47 | find_package(Doxygen) |
| 48 | option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND}) |
| 49 | |
Jan Kundrát | d47f655 | 2018-03-02 13:40:11 +0100 | [diff] [blame] | 50 | find_package(docopt REQUIRED) |
| 51 | find_package(spdlog REQUIRED) |
Jan Kundrát | 03caee8 | 2018-03-08 14:16:56 +0100 | [diff] [blame] | 52 | find_package(Boost REQUIRED) |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 53 | find_library(REPLXX_LIBRARY replxx REQUIRED) |
| 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) |
| 60 | pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=0.15.111) |
Jan Kundrát | bd17836 | 2019-02-05 19:00:04 +0100 | [diff] [blame] | 61 | # TODO: bump to 0.7.8 once it is tagged |
| 62 | pkg_check_modules(SYSREPO REQUIRED libSysrepo-cpp>=0.7.7) |
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 | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 67 | add_library(schemas STATIC |
Václav Kubernát | bddbb17 | 2018-06-13 16:27:39 +0200 | [diff] [blame] | 68 | src/static_schema.cpp |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 69 | src/schema.cpp |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 70 | ) |
| 71 | target_link_libraries(schemas PUBLIC Boost::boost) |
| 72 | |
Václav Kubernát | e7a9fa3 | 2018-08-22 13:56:35 +0200 | [diff] [blame] | 73 | add_library(datastoreaccess STATIC |
| 74 | src/datastore_access.cpp |
| 75 | ) |
| 76 | target_link_libraries(datastoreaccess PUBLIC Boost::boost) |
| 77 | |
Václav Kubernát | 80aacc0 | 2018-08-22 17:41:54 +0200 | [diff] [blame] | 78 | add_library(sysrepoaccess STATIC |
| 79 | src/sysrepo_access.cpp |
| 80 | ) |
| 81 | target_link_libraries(sysrepoaccess datastoreaccess ${SYSREPO_LIBRARIES}) |
| 82 | link_directories(${SYSREPO_LIBRARY_DIRS}) |
| 83 | target_include_directories(sysrepoaccess SYSTEM PRIVATE ${SYSREPO_INCLUDE_DIRS}) |
| 84 | |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 85 | add_library(yangschema STATIC |
| 86 | src/yang_schema.cpp |
| 87 | ) |
| 88 | target_link_libraries(yangschema ${LIBYANG_LIBRARIES}) |
| 89 | # Ensure that this doesn't override Boost's -isystem -- see the log for details. |
| 90 | target_include_directories(yangschema SYSTEM PRIVATE ${LIBYANG_INCLUDEDIR}) |
| 91 | link_directories(${LIBYANG_LIBRARY_DIRS}) |
| 92 | |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 93 | add_library(parser STATIC |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 94 | src/parser.cpp |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 95 | src/ast_commands.cpp |
| 96 | src/ast_path.cpp |
Václav Kubernát | 94938b7 | 2018-05-04 15:12:24 +0200 | [diff] [blame] | 97 | src/utils.cpp |
Václav Kubernát | 195eeea | 2018-05-18 13:52:36 +0200 | [diff] [blame] | 98 | src/parser_context.cpp |
Václav Kubernát | 96344a1 | 2018-05-28 16:33:39 +0200 | [diff] [blame] | 99 | src/interpreter.cpp |
Václav Kubernát | 329c6c3 | 2019-02-06 16:41:53 +0100 | [diff] [blame] | 100 | src/ast_handlers.cpp |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 101 | ) |
Jan Kundrát | 578347c | 2018-08-09 15:02:06 +0200 | [diff] [blame] | 102 | target_link_libraries(parser schemas) |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 103 | |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 104 | |
| 105 | add_library(sysreposubscription STATIC |
| 106 | tests/mock/sysrepo_subscription.cpp |
| 107 | ) |
| 108 | |
| 109 | target_link_libraries(sysreposubscription ${SYSREPO_LIBRARIES}) |
| 110 | link_directories(${SYSREPO_LIBRARY_DIRS}) |
| 111 | target_include_directories(sysreposubscription SYSTEM PRIVATE ${SYSREPO_INCLUDE_DIRS}) |
| 112 | |
Jan Kundrát | cc4c1f2 | 2018-08-09 15:00:03 +0200 | [diff] [blame] | 113 | add_executable(netconf-cli |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 114 | src/main.cpp |
| 115 | ) |
Václav Kubernát | a395d33 | 2019-02-13 16:49:20 +0100 | [diff] [blame] | 116 | target_link_libraries(netconf-cli sysrepoaccess yangschema docopt parser ${REPLXX_LIBRARY}) |
| 117 | target_include_directories(netconf-cli PRIVATE ${REPLXX_PATH}) |
Václav Kubernát | 2b68461 | 2018-08-09 18:55:24 +0200 | [diff] [blame] | 118 | if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+") |
| 119 | target_link_libraries(netconf-cli c++experimental) |
| 120 | else() |
| 121 | target_link_libraries(netconf-cli stdc++fs) |
| 122 | endif() |
| 123 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 124 | add_dependencies(netconf-cli target-NETCONF_CLI_VERSION) |
| 125 | target_include_directories(netconf-cli PRIVATE ${PROJECT_BINARY_DIR}) |
| 126 | |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 127 | include(CTest) |
| 128 | if(BUILD_TESTING) |
| 129 | enable_testing() |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 130 | find_package(trompeloeil 33 REQUIRED) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 131 | find_package(doctest 2.3.1 REQUIRED) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 132 | |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 133 | add_library(DoctestIntegration STATIC |
| 134 | tests/doctest_integration.cpp |
| 135 | tests/trompeloeil_doctest.h |
Jan Kundrát | c381e63 | 2019-03-14 13:39:11 +0100 | [diff] [blame] | 136 | tests/wait-a-bit-longer.cpp |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 137 | ) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 138 | target_include_directories(DoctestIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/) |
| 139 | target_link_libraries(DoctestIntegration doctest::doctest trompeloeil spdlog::spdlog) |
| 140 | target_compile_definitions(DoctestIntegration PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 141 | |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 142 | if (NOT SYSREPOCTL_EXECUTABLE) |
| 143 | find_program(SYSREPOCTL_EXECUTABLE sysrepoctl) |
| 144 | endif() |
| 145 | if (NOT SYSREPOCTL_EXECUTABLE) |
| 146 | message(FATAL_ERROR "Unable to find sysrepoctl, set SYSREPOCTL_EXECUTABLE manually.") |
| 147 | endif() |
| 148 | |
| 149 | configure_file("${PROJECT_SOURCE_DIR}/sysrepo_vars.hpp.in" "${PROJECT_BINARY_DIR}/sysrepo_vars.hpp" @ONLY) |
| 150 | configure_file("${PROJECT_SOURCE_DIR}/example-schema.yang" "${PROJECT_BINARY_DIR}/example-schema.yang" COPYONLY) |
| 151 | |
Jan Kundrát | cc4c1f2 | 2018-08-09 15:00:03 +0200 | [diff] [blame] | 152 | function(cli_test fname) |
| 153 | add_executable(test_${fname} |
| 154 | tests/${fname}.cpp |
| 155 | ) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 156 | target_link_libraries(test_${fname} DoctestIntegration parser) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 157 | if(NOT CMAKE_CROSSCOMPILING) |
| 158 | add_test(test_${fname} test_${fname}) |
| 159 | endif() |
| 160 | target_include_directories(test_${fname} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
Jan Kundrát | a33cf08 | 2019-03-28 11:55:57 +0100 | [diff] [blame] | 161 | target_link_libraries(test_${fname} DoctestIntegration) |
Jan Kundrát | cc4c1f2 | 2018-08-09 15:00:03 +0200 | [diff] [blame] | 162 | endfunction() |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 163 | cli_test(cd) |
Václav Kubernát | 11afac7 | 2018-07-18 14:59:53 +0200 | [diff] [blame] | 164 | cli_test(ls) |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 165 | cli_test(presence_containers) |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 166 | cli_test(leaf_editing) |
Václav Kubernát | 0d4db44 | 2018-07-18 17:18:43 +0200 | [diff] [blame] | 167 | cli_test(yang) |
| 168 | target_link_libraries(test_yang yangschema) |
Václav Kubernát | 7310938 | 2018-09-14 19:52:03 +0200 | [diff] [blame] | 169 | cli_test(sysrepo) |
| 170 | target_link_libraries(test_sysrepo sysreposubscription sysrepoaccess yangschema parser) |
| 171 | target_include_directories(test_sysrepo PRIVATE ${PROJECT_SOURCE_DIR}/tests/mock) |
Václav Kubernát | 4108e0d | 2018-10-29 13:32:22 +0100 | [diff] [blame] | 172 | cli_test(utils) |
| 173 | cli_test(path_completion) |
Václav Kubernát | 5727242 | 2019-02-08 12:48:24 +0100 | [diff] [blame] | 174 | cli_test(command_completion) |
Václav Kubernát | 989b5de | 2019-02-20 16:28:35 +0100 | [diff] [blame] | 175 | cli_test(enum_completion) |
Václav Kubernát | f5f64f0 | 2019-03-19 17:15:47 +0100 | [diff] [blame] | 176 | cli_test(list_manipulation) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 177 | endif() |
| 178 | |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 179 | if(WITH_DOCS) |
| 180 | set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) |
| 181 | set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) |
| 182 | configure_file(${doxyfile_in} ${doxyfile} @ONLY) |
| 183 | add_custom_target(doc |
| 184 | COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} |
| 185 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 186 | COMMENT "Generating API documentation with Doxygen" |
| 187 | VERBATIM |
| 188 | SOURCES ${doxyfile_in} |
| 189 | ) |
| 190 | endif() |
Jan Kundrát | 10f4990 | 2018-05-22 17:01:45 +0200 | [diff] [blame] | 191 | |
| 192 | install(TARGETS |
| 193 | netconf-cli |
| 194 | RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/) |