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) |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 53 | |
Václav Kubernát | b96eef7 | 2018-05-04 19:10:22 +0200 | [diff] [blame] | 54 | # we don't need filename tracking, and we prefer to use header-only Boost |
| 55 | add_definitions(-DBOOST_SPIRIT_X3_NO_FILESYSTEM) |
| 56 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 57 | set(parser_SRCS |
Václav Kubernát | 48fc383 | 2018-05-28 14:21:22 +0200 | [diff] [blame] | 58 | src/schema.cpp |
| 59 | src/parser.cpp |
Václav Kubernát | 24df80e | 2018-06-06 15:18:03 +0200 | [diff] [blame] | 60 | src/ast_commands.cpp |
| 61 | src/ast_path.cpp |
Václav Kubernát | 94938b7 | 2018-05-04 15:12:24 +0200 | [diff] [blame] | 62 | src/utils.cpp |
Václav Kubernát | 195eeea | 2018-05-18 13:52:36 +0200 | [diff] [blame] | 63 | src/parser_context.cpp |
Václav Kubernát | 96344a1 | 2018-05-28 16:33:39 +0200 | [diff] [blame] | 64 | src/interpreter.cpp |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 65 | ) |
| 66 | |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 67 | add_library(parser STATIC ${parser_SRCS}) |
| 68 | target_link_libraries(parser Boost::boost) |
| 69 | |
| 70 | set(netconf-cli_SRCS |
| 71 | src/main.cpp |
| 72 | ) |
| 73 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 74 | add_executable(netconf-cli ${netconf-cli_SRCS}) |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 75 | target_link_libraries(netconf-cli docopt parser) |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 76 | add_dependencies(netconf-cli target-NETCONF_CLI_VERSION) |
| 77 | target_include_directories(netconf-cli PRIVATE ${PROJECT_BINARY_DIR}) |
| 78 | |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 79 | include(CTest) |
| 80 | if(BUILD_TESTING) |
| 81 | enable_testing() |
| 82 | find_path(TROMPELOEIL_PATH trompeloeil.hpp PATH_SUFFIXES trompeloeil/) |
| 83 | if("${TROMPELOEIL_PATH}" STREQUAL "TROMPELOEIL_PATH-NOTFOUND") |
| 84 | message(FATAL_ERROR "Cannot find the \"trompeloeil.hpp\" file provided by <https://github.com/rollbear/trompeloeil>. " |
| 85 | "Please set TROMPELOEIL_PATH to where it is available.") |
| 86 | endif() |
| 87 | |
| 88 | find_path(CATCH_PATH catch.hpp PATH_SUFFIXES catch/) |
| 89 | if("${CATCH_PATH}" STREQUAL "CATCH_PATH-NOTFOUND") |
| 90 | message(FATAL_ERROR "Cannot find the \"catch.hpp\" file provided by <http://catch-lib.net/>. " |
| 91 | "Please set CATCH_PATH to where it is available.") |
| 92 | endif() |
| 93 | |
| 94 | add_library(TestCatchIntegration STATIC |
| 95 | tests/catch_integration.cpp |
| 96 | tests/trompeloeil_catch.h |
| 97 | ) |
| 98 | target_include_directories(TestCatchIntegration SYSTEM PUBLIC ${TROMPELOEIL_PATH} ${CATCH_PATH}) |
| 99 | target_include_directories(TestCatchIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/) |
| 100 | target_link_libraries(TestCatchIntegration spdlog::spdlog) |
| 101 | |
| 102 | macro(cli_test fname) |
| 103 | set(test_${fname}_SOURCES tests/${fname}.cpp) |
| 104 | add_executable(test_${fname} ${test_${fname}_SOURCES}) |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 105 | target_link_libraries(test_${fname} TestCatchIntegration parser) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 106 | if(NOT CMAKE_CROSSCOMPILING) |
| 107 | add_test(test_${fname} test_${fname}) |
| 108 | endif() |
| 109 | target_include_directories(test_${fname} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 110 | target_link_libraries(test_${fname} TestCatchIntegration) |
| 111 | endmacro() |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 112 | cli_test(cd) |
Václav Kubernát | b61336d | 2018-05-28 17:35:03 +0200 | [diff] [blame] | 113 | cli_test(presence_containers) |
Václav Kubernát | 0720424 | 2018-06-04 18:12:09 +0200 | [diff] [blame] | 114 | cli_test(leaf_editing) |
Václav Kubernát | d666296 | 2018-03-22 17:41:33 +0100 | [diff] [blame] | 115 | |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 116 | endif() |
| 117 | |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 118 | if(WITH_DOCS) |
| 119 | set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) |
| 120 | set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) |
| 121 | configure_file(${doxyfile_in} ${doxyfile} @ONLY) |
| 122 | add_custom_target(doc |
| 123 | COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} |
| 124 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 125 | COMMENT "Generating API documentation with Doxygen" |
| 126 | VERBATIM |
| 127 | SOURCES ${doxyfile_in} |
| 128 | ) |
| 129 | endif() |
Jan Kundrát | 10f4990 | 2018-05-22 17:01:45 +0200 | [diff] [blame] | 130 | |
| 131 | install(TARGETS |
| 132 | netconf-cli |
| 133 | RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/) |