blob: 3ac927897c540fd3ad9715df7847e32c904a7810 [file] [log] [blame]
Jan Kundrátd9d26a92018-02-22 12:49:21 +01001project(netconf-cli LANGUAGES CXX)
2cmake_minimum_required(VERSION 3.0)
3set(CMAKE_CXX_STANDARD 14)
4set(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.
Miroslav Mareš90485112018-03-16 09:55:14 +010032set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Wsuggest-override -Woverloaded-virtual ${CMAKE_CXX_FLAGS}")
Jan Kundrátd47f6552018-03-02 13:40:11 +010033
Jan Kundrátdc2b0722018-03-02 14:13:37 +010034set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
35
36add_custom_target(git-version-cmake-ide
37 cmake/ProjectGitVersion.cmake
38 cmake/ProjectGitVersionRunner.cmake
39 )
40include(cmake/ProjectGitVersion.cmake)
41prepare_git_version(NETCONF_CLI_VERSION "0.0")
42
Jan Kundrát608818b2018-03-02 13:43:53 +010043find_package(Doxygen)
44option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND})
45
Jan Kundrátd47f6552018-03-02 13:40:11 +010046find_package(docopt REQUIRED)
47find_package(spdlog REQUIRED)
Jan Kundrát03caee82018-03-08 14:16:56 +010048find_package(Boost REQUIRED)
Jan Kundrát608818b2018-03-02 13:43:53 +010049
Václav Kubernátd6662962018-03-22 17:41:33 +010050set(parser_SRCS
Václav Kubernát624a8872018-03-02 17:28:47 +010051 src/CTree.cpp
52 src/CParser.cpp
Václav Kubernát8cd63422018-03-19 17:10:13 +010053 src/ast.cpp
Jan Kundrátdc2b0722018-03-02 14:13:37 +010054 )
55
Václav Kubernátd6662962018-03-22 17:41:33 +010056add_library(parser STATIC ${parser_SRCS})
57target_link_libraries(parser Boost::boost)
58
59set(netconf-cli_SRCS
60 src/main.cpp
61 )
62
Jan Kundrátdc2b0722018-03-02 14:13:37 +010063add_executable(netconf-cli ${netconf-cli_SRCS})
Václav Kubernátd6662962018-03-22 17:41:33 +010064target_link_libraries(netconf-cli docopt parser)
Jan Kundrátdc2b0722018-03-02 14:13:37 +010065add_dependencies(netconf-cli target-NETCONF_CLI_VERSION)
66target_include_directories(netconf-cli PRIVATE ${PROJECT_BINARY_DIR})
67
Jan Kundrát5c805212018-03-02 13:57:12 +010068include(CTest)
69if(BUILD_TESTING)
70 enable_testing()
71 find_path(TROMPELOEIL_PATH trompeloeil.hpp PATH_SUFFIXES trompeloeil/)
72 if("${TROMPELOEIL_PATH}" STREQUAL "TROMPELOEIL_PATH-NOTFOUND")
73 message(FATAL_ERROR "Cannot find the \"trompeloeil.hpp\" file provided by <https://github.com/rollbear/trompeloeil>. "
74 "Please set TROMPELOEIL_PATH to where it is available.")
75 endif()
76
77 find_path(CATCH_PATH catch.hpp PATH_SUFFIXES catch/)
78 if("${CATCH_PATH}" STREQUAL "CATCH_PATH-NOTFOUND")
79 message(FATAL_ERROR "Cannot find the \"catch.hpp\" file provided by <http://catch-lib.net/>. "
80 "Please set CATCH_PATH to where it is available.")
81 endif()
82
83 add_library(TestCatchIntegration STATIC
84 tests/catch_integration.cpp
85 tests/trompeloeil_catch.h
86 )
87 target_include_directories(TestCatchIntegration SYSTEM PUBLIC ${TROMPELOEIL_PATH} ${CATCH_PATH})
88 target_include_directories(TestCatchIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/)
89 target_link_libraries(TestCatchIntegration spdlog::spdlog)
90
91 macro(cli_test fname)
92 set(test_${fname}_SOURCES tests/${fname}.cpp)
93 add_executable(test_${fname} ${test_${fname}_SOURCES})
Václav Kubernátd6662962018-03-22 17:41:33 +010094 target_link_libraries(test_${fname} TestCatchIntegration parser)
Jan Kundrát5c805212018-03-02 13:57:12 +010095 if(NOT CMAKE_CROSSCOMPILING)
96 add_test(test_${fname} test_${fname})
97 endif()
98 target_include_directories(test_${fname} PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
99 target_link_libraries(test_${fname} TestCatchIntegration)
100 endmacro()
Jan Kundrát34c790d2018-03-02 13:57:47 +0100101 cli_test(dummy)
Václav Kubernátd6662962018-03-22 17:41:33 +0100102 cli_test(cd)
103
Jan Kundrát5c805212018-03-02 13:57:12 +0100104endif()
105
Jan Kundrát608818b2018-03-02 13:43:53 +0100106if(WITH_DOCS)
107 set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in)
108 set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
109 configure_file(${doxyfile_in} ${doxyfile} @ONLY)
110 add_custom_target(doc
111 COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
112 WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
113 COMMENT "Generating API documentation with Doxygen"
114 VERBATIM
115 SOURCES ${doxyfile_in}
116 )
117endif()