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) |
| 3 | set(CMAKE_CXX_STANDARD 14) |
| 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. |
Miroslav Mareš | 9048511 | 2018-03-16 09:55:14 +0100 | [diff] [blame] | 32 | set(CMAKE_CXX_FLAGS "-Wall -Wextra -pedantic -Wsuggest-override -Woverloaded-virtual ${CMAKE_CXX_FLAGS}") |
Jan Kundrát | d47f655 | 2018-03-02 13:40:11 +0100 | [diff] [blame] | 33 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 34 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/") |
| 35 | |
| 36 | add_custom_target(git-version-cmake-ide |
| 37 | cmake/ProjectGitVersion.cmake |
| 38 | cmake/ProjectGitVersionRunner.cmake |
| 39 | ) |
| 40 | include(cmake/ProjectGitVersion.cmake) |
| 41 | prepare_git_version(NETCONF_CLI_VERSION "0.0") |
| 42 | |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 43 | find_package(Doxygen) |
| 44 | option(WITH_DOCS "Create and install internal documentation (needs Doxygen)" ${DOXYGEN_FOUND}) |
| 45 | |
Jan Kundrát | d47f655 | 2018-03-02 13:40:11 +0100 | [diff] [blame] | 46 | find_package(docopt REQUIRED) |
| 47 | find_package(spdlog REQUIRED) |
Jan Kundrát | 03caee8 | 2018-03-08 14:16:56 +0100 | [diff] [blame] | 48 | find_package(Boost REQUIRED) |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 49 | |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 50 | set(netconf-cli_SRCS |
| 51 | src/main.cpp |
| 52 | ) |
| 53 | |
| 54 | add_executable(netconf-cli ${netconf-cli_SRCS}) |
Jan Kundrát | 03caee8 | 2018-03-08 14:16:56 +0100 | [diff] [blame] | 55 | target_link_libraries(netconf-cli docopt Boost::boost) |
Jan Kundrát | dc2b072 | 2018-03-02 14:13:37 +0100 | [diff] [blame] | 56 | add_dependencies(netconf-cli target-NETCONF_CLI_VERSION) |
| 57 | target_include_directories(netconf-cli PRIVATE ${PROJECT_BINARY_DIR}) |
| 58 | |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 59 | include(CTest) |
| 60 | if(BUILD_TESTING) |
| 61 | enable_testing() |
| 62 | find_path(TROMPELOEIL_PATH trompeloeil.hpp PATH_SUFFIXES trompeloeil/) |
| 63 | if("${TROMPELOEIL_PATH}" STREQUAL "TROMPELOEIL_PATH-NOTFOUND") |
| 64 | message(FATAL_ERROR "Cannot find the \"trompeloeil.hpp\" file provided by <https://github.com/rollbear/trompeloeil>. " |
| 65 | "Please set TROMPELOEIL_PATH to where it is available.") |
| 66 | endif() |
| 67 | |
| 68 | find_path(CATCH_PATH catch.hpp PATH_SUFFIXES catch/) |
| 69 | if("${CATCH_PATH}" STREQUAL "CATCH_PATH-NOTFOUND") |
| 70 | message(FATAL_ERROR "Cannot find the \"catch.hpp\" file provided by <http://catch-lib.net/>. " |
| 71 | "Please set CATCH_PATH to where it is available.") |
| 72 | endif() |
| 73 | |
| 74 | add_library(TestCatchIntegration STATIC |
| 75 | tests/catch_integration.cpp |
| 76 | tests/trompeloeil_catch.h |
| 77 | ) |
| 78 | target_include_directories(TestCatchIntegration SYSTEM PUBLIC ${TROMPELOEIL_PATH} ${CATCH_PATH}) |
| 79 | target_include_directories(TestCatchIntegration PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/ ${CMAKE_CURRENT_SOURCE_DIR}/src/) |
| 80 | target_link_libraries(TestCatchIntegration spdlog::spdlog) |
| 81 | |
| 82 | macro(cli_test fname) |
| 83 | set(test_${fname}_SOURCES tests/${fname}.cpp) |
| 84 | add_executable(test_${fname} ${test_${fname}_SOURCES}) |
| 85 | target_link_libraries(test_${fname} TestCatchIntegration) |
| 86 | if(NOT CMAKE_CROSSCOMPILING) |
| 87 | add_test(test_${fname} test_${fname}) |
| 88 | endif() |
| 89 | target_include_directories(test_${fname} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) |
| 90 | target_link_libraries(test_${fname} TestCatchIntegration) |
| 91 | endmacro() |
Jan Kundrát | 34c790d | 2018-03-02 13:57:47 +0100 | [diff] [blame] | 92 | cli_test(dummy) |
Jan Kundrát | 5c80521 | 2018-03-02 13:57:12 +0100 | [diff] [blame] | 93 | endif() |
| 94 | |
Jan Kundrát | 608818b | 2018-03-02 13:43:53 +0100 | [diff] [blame] | 95 | if(WITH_DOCS) |
| 96 | set(doxyfile_in ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile.in) |
| 97 | set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile) |
| 98 | configure_file(${doxyfile_in} ${doxyfile} @ONLY) |
| 99 | add_custom_target(doc |
| 100 | COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile} |
| 101 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} |
| 102 | COMMENT "Generating API documentation with Doxygen" |
| 103 | VERBATIM |
| 104 | SOURCES ${doxyfile_in} |
| 105 | ) |
| 106 | endif() |