blob: cd22debb1a904a161b5183cc4dbed4f7ba89c7f7 [file] [log] [blame]
Jan Kundrátd9d26a92018-02-22 12:49:21 +01001project(netconf-cli LANGUAGES CXX)
2cmake_minimum_required(VERSION 3.0)
Jan Kundrát763db1e2018-05-25 15:43:51 +02003set(CMAKE_CXX_STANDARD 17)
Jan Kundrátd9d26a92018-02-22 12:49:21 +01004set(CMAKE_CXX_STANDARD_REQUIRED ON)
Jan Kundrátd47f6552018-03-02 13:40:11 +01005
6include(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.
15if(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")
20endif()
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.
25set(CMAKE_CXX_FLAGS_DEBUG "-Werror ${CMAKE_CXX_FLAGS_DEBUG}")
26
27# I don't want to duplicate the compiler's optimizations
28set(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átfb831902018-05-26 18:58:52 +020032set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Woverloaded-virtual ${CMAKE_CXX_FLAGS}")
33
34if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
35 set(CMAKE_CXX_FLAGS "-Wsuggest-override ${CMAKE_CXX_FLAGS}")
36endif()
Jan Kundrátd47f6552018-03-02 13:40:11 +010037
Jan Kundrátdc2b0722018-03-02 14:13:37 +010038set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
39
40add_custom_target(git-version-cmake-ide
41 cmake/ProjectGitVersion.cmake
42 cmake/ProjectGitVersionRunner.cmake
43 )
44include(cmake/ProjectGitVersion.cmake)
45prepare_git_version(NETCONF_CLI_VERSION "0.0")
46
Jan Kundrát608818b2018-03-02 13:43:53 +010047find_package(Doxygen)
48option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
49
Jan Kundrátd47f6552018-03-02 13:40:11 +010050find_package(docopt REQUIRED)
51find_package(spdlog REQUIRED)
Jan Kundrát03caee82018-03-08 14:16:56 +010052find_package(Boost REQUIRED)
Václav Kubernáta395d332019-02-13 16:49:20 +010053find_library(REPLXX_LIBRARY replxx REQUIRED)
54find_path(REPLXX_PATH replxx.hxx)
55if("${REPLXX_PATH}" STREQUAL REPLXX_PATH-NOTFOUND)
56 message(FATAL_ERROR "Cannot find the \"replxx.hxx\" include file for the replxx library.")
57endif()
Jan Kundrát608818b2018-03-02 13:43:53 +010058
Jan Kundráte05448a2018-06-13 15:54:33 +020059find_package(PkgConfig)
60pkg_check_modules(LIBYANG REQUIRED libyang-cpp>=0.15.111)
Jan Kundrátbd178362019-02-05 19:00:04 +010061# TODO: bump to 0.7.8 once it is tagged
62pkg_check_modules(SYSREPO REQUIRED libSysrepo-cpp>=0.7.7)
Jan Kundráte05448a2018-06-13 15:54:33 +020063
Václav Kubernátb96eef72018-05-04 19:10:22 +020064# we don't need filename tracking, and we prefer to use header-only Boost
65add_definitions(-DBOOST_SPIRIT_X3_NO_FILESYSTEM)
66
Jan Kundrát578347c2018-08-09 15:02:06 +020067add_library(schemas STATIC
Václav Kubernátbddbb172018-06-13 16:27:39 +020068 src/static_schema.cpp
Václav Kubernát48fc3832018-05-28 14:21:22 +020069 src/schema.cpp
Jan Kundrát578347c2018-08-09 15:02:06 +020070 )
71target_link_libraries(schemas PUBLIC Boost::boost)
72
Václav Kubernáte7a9fa32018-08-22 13:56:35 +020073add_library(datastoreaccess STATIC
74 src/datastore_access.cpp
75 )
76target_link_libraries(datastoreaccess PUBLIC Boost::boost)
77
Václav Kubernát80aacc02018-08-22 17:41:54 +020078add_library(sysrepoaccess STATIC
79 src/sysrepo_access.cpp
80 )
81target_link_libraries(sysrepoaccess datastoreaccess ${SYSREPO_LIBRARIES})
82link_directories(${SYSREPO_LIBRARY_DIRS})
83target_include_directories(sysrepoaccess SYSTEM PRIVATE ${SYSREPO_INCLUDE_DIRS})
84
Václav Kubernát0d4db442018-07-18 17:18:43 +020085add_library(yangschema STATIC
86 src/yang_schema.cpp
87 )
88target_link_libraries(yangschema ${LIBYANG_LIBRARIES})
89# Ensure that this doesn't override Boost's -isystem -- see the log for details.
90target_include_directories(yangschema SYSTEM PRIVATE ${LIBYANG_INCLUDEDIR})
91link_directories(${LIBYANG_LIBRARY_DIRS})
92
Jan Kundrát578347c2018-08-09 15:02:06 +020093add_library(parser STATIC
Václav Kubernát48fc3832018-05-28 14:21:22 +020094 src/parser.cpp
Václav Kubernát24df80e2018-06-06 15:18:03 +020095 src/ast_commands.cpp
96 src/ast_path.cpp
Václav Kubernát94938b72018-05-04 15:12:24 +020097 src/utils.cpp
Václav Kubernát195eeea2018-05-18 13:52:36 +020098 src/parser_context.cpp
Václav Kubernát96344a12018-05-28 16:33:39 +020099 src/interpreter.cpp
Václav Kubernát329c6c32019-02-06 16:41:53 +0100100 src/ast_handlers.cpp
Jan Kundrátdc2b0722018-03-02 14:13:37 +0100101 )
Jan Kundrát578347c2018-08-09 15:02:06 +0200102target_link_libraries(parser schemas)
Václav Kubernátd6662962018-03-22 17:41:33 +0100103
Václav Kubernát73109382018-09-14 19:52:03 +0200104
105add_library(sysreposubscription STATIC
106 tests/mock/sysrepo_subscription.cpp
107 )
108
109target_link_libraries(sysreposubscription ${SYSREPO_LIBRARIES})
110link_directories(${SYSREPO_LIBRARY_DIRS})
111target_include_directories(sysreposubscription SYSTEM PRIVATE ${SYSREPO_INCLUDE_DIRS})
112
Jan Kundrátcc4c1f22018-08-09 15:00:03 +0200113add_executable(netconf-cli
Václav Kubernátd6662962018-03-22 17:41:33 +0100114 src/main.cpp
115 )
Václav Kubernáta395d332019-02-13 16:49:20 +0100116target_link_libraries(netconf-cli sysrepoaccess yangschema docopt parser ${REPLXX_LIBRARY})
117target_include_directories(netconf-cli PRIVATE ${REPLXX_PATH})
Václav Kubernát2b684612018-08-09 18:55:24 +0200118if(CMAKE_CXX_FLAGS MATCHES "-stdlib=libc\\+\\+")
119 target_link_libraries(netconf-cli c++experimental)
120else()
121 target_link_libraries(netconf-cli stdc++fs)
122endif()
123
Jan Kundrátdc2b0722018-03-02 14:13:37 +0100124add_dependencies(netconf-cli target-NETCONF_CLI_VERSION)
125target_include_directories(netconf-cli PRIVATE ${PROJECT_BINARY_DIR})
126
Jan Kundrát5c805212018-03-02 13:57:12 +0100127include(CTest)
128if(BUILD_TESTING)
129 enable_testing()
Jan Kundrátc381e632019-03-14 13:39:11 +0100130 find_package(trompeloeil 33 REQUIRED)
Jan Kundráta33cf082019-03-28 11:55:57 +0100131 find_package(doctest 2.3.1 REQUIRED)
Jan Kundrát5c805212018-03-02 13:57:12 +0100132
Jan Kundráta33cf082019-03-28 11:55:57 +0100133 add_library(DoctestIntegration STATIC
134 tests/doctest_integration.cpp
135 tests/trompeloeil_doctest.h
Jan Kundrátc381e632019-03-14 13:39:11 +0100136 tests/wait-a-bit-longer.cpp
Jan Kundrát5c805212018-03-02 13:57:12 +0100137 )
Jan Kundráta33cf082019-03-28 11:55:57 +0100138 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át5c805212018-03-02 13:57:12 +0100141
Václav Kubernát73109382018-09-14 19:52:03 +0200142 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átcc4c1f22018-08-09 15:00:03 +0200152 function(cli_test fname)
153 add_executable(test_${fname}
154 tests/${fname}.cpp
155 )
Jan Kundráta33cf082019-03-28 11:55:57 +0100156 target_link_libraries(test_${fname} DoctestIntegration parser)
Jan Kundrát5c805212018-03-02 13:57:12 +0100157 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áta33cf082019-03-28 11:55:57 +0100161 target_link_libraries(test_${fname} DoctestIntegration)
Jan Kundrátcc4c1f22018-08-09 15:00:03 +0200162 endfunction()
Václav Kubernátd6662962018-03-22 17:41:33 +0100163 cli_test(cd)
Václav Kubernát11afac72018-07-18 14:59:53 +0200164 cli_test(ls)
Václav Kubernátb61336d2018-05-28 17:35:03 +0200165 cli_test(presence_containers)
Václav Kubernát07204242018-06-04 18:12:09 +0200166 cli_test(leaf_editing)
Václav Kubernát0d4db442018-07-18 17:18:43 +0200167 cli_test(yang)
168 target_link_libraries(test_yang yangschema)
Václav Kubernát73109382018-09-14 19:52:03 +0200169 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át4108e0d2018-10-29 13:32:22 +0100172 cli_test(utils)
173 cli_test(path_completion)
Václav Kubernát57272422019-02-08 12:48:24 +0100174 cli_test(command_completion)
Václav Kubernát989b5de2019-02-20 16:28:35 +0100175 cli_test(enum_completion)
Václav Kubernátf5f64f02019-03-19 17:15:47 +0100176 cli_test(list_manipulation)
Jan Kundrát5c805212018-03-02 13:57:12 +0100177endif()
178
Jan Kundrát608818b2018-03-02 13:43:53 +0100179if(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 )
190endif()
Jan Kundrát10f49902018-05-22 17:01:45 +0200191
192install(TARGETS
193 netconf-cli
194 RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/)