Alex Stancu | 29ce368 | 2019-11-02 10:38:59 +0200 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 2.8.12) |
| 2 | project(ntsimulator) |
| 3 | set(PROJECT_DESC "Network Topology Simulator using sysrepo and netopeer2") |
| 4 | include(GNUInstallDirs) |
| 5 | |
| 6 | # setup version |
| 7 | set(NTSIMULATOR_MAJOR_VERSION 1) |
| 8 | set(NTSIMULATOR_MINOR_VERSION 1) |
| 9 | set(NTSIMULATOR_PATCH_VERSION 1) |
| 10 | set(NTSIMULATOR_VERSION ${NTSIMULATOR_MAJOR_VERSION}.${NTSIMULATOR_MINOR_VERSION}.${NTSIMULATOR_PATCH_VERSION}) |
| 11 | set(NTSIMULATOR_SOVERSION ${NTSIMULATOR_MAJOR_VERSION}.${NTSIMULATOR_MINOR_VERSION}) |
| 12 | |
| 13 | # osx specific |
| 14 | set(CMAKE_MACOSX_RPATH TRUE) |
| 15 | |
| 16 | # set default build type if not specified by user |
| 17 | if(NOT CMAKE_BUILD_TYPE) |
| 18 | set(CMAKE_BUILD_TYPE debug) |
| 19 | endif() |
| 20 | string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER) |
| 21 | |
| 22 | set(CMAKE_EXPORT_COMPILE_COMMANDS 1) |
| 23 | |
| 24 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wpedantic -std=gnu11 -Wno-language-extension-token") |
| 25 | if(CMAKE_COMPILER_IS_GNUCC) |
| 26 | # disable strict aliasing in GCC, since it produces false alarams in libev |
| 27 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-strict-aliasing") |
| 28 | endif() |
| 29 | set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2") |
| 30 | set(CMAKE_C_FLAGS_DEBUG "-g -O0") |
| 31 | |
| 32 | if(NOT UNIX) |
| 33 | message(FATAL_ERROR "Only Unix-like systems are supported.") |
| 34 | endif() |
| 35 | |
| 36 | if(NOT DEFINED IS_DEVELOPER_CONFIGURATION) |
| 37 | if(CMAKE_BUILD_TYPE_LOWER MATCHES "debug" AND NOT CMAKE_BUILD_TYPE_LOWER MATCHES "^rel") |
| 38 | set(IS_DEVELOPER_CONFIGURATION true) |
| 39 | else() |
| 40 | set(IS_DEVELOPER_CONFIGURATION false) |
| 41 | endif() |
| 42 | endif() |
| 43 | |
| 44 | # location of system repository |
| 45 | if(${IS_DEVELOPER_CONFIGURATION}) |
| 46 | set(REPOSITORY_LOC "${CMAKE_BINARY_DIR}/repository" CACHE PATH "System repository location, contains configuration schema and data files.") |
| 47 | else() |
| 48 | set(REPOSITORY_LOC "/etc/sysrepo" CACHE PATH "System repository location, contains configuration schema and data files.") |
| 49 | endif() |
| 50 | |
| 51 | # include custom Modules |
| 52 | set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/") |
| 53 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) |
| 54 | include_directories("${CMAKE_CURRENT_SOURCE_DIR}/inc") |
| 55 | |
| 56 | # find required libraries |
| 57 | find_package(SYSREPO REQUIRED) |
| 58 | include_directories(${SYSREPO_INCLUDE_DIR}) |
| 59 | |
| 60 | # add subdirectories |
| 61 | add_subdirectory(src) |
| 62 | |
Alex Stancu | 29ce368 | 2019-11-02 10:38:59 +0200 | [diff] [blame] | 63 | # find sysrepoctl |
| 64 | if (NOT SYSREPOCTL_EXECUTABLE) |
| 65 | find_program(SYSREPOCTL_EXECUTABLE sysrepoctl) |
| 66 | endif() |
| 67 | if (NOT SYSREPOCTL_EXECUTABLE) |
| 68 | message(FATAL_ERROR "Unable to find sysrepoctl, set SYSREPOCTL_EXECUTABLE manually.") |
| 69 | endif() |
| 70 | |
| 71 | # find sysrepocfg |
| 72 | if (NOT SYSREPOCFG_EXECUTABLE) |
| 73 | find_program(SYSREPOCFG_EXECUTABLE sysrepocfg) |
| 74 | endif() |
| 75 | if (NOT SYSREPOCFG_EXECUTABLE) |
| 76 | message(FATAL_ERROR "Unable to find sysrepocfg, set SYSREPOCFG_EXECUTABLE manually.") |
| 77 | endif() |
| 78 | |
| 79 | # Command line options to be passed to `sysrepoctl` when working with modules |
| 80 | # which should only be accessible by an administrator |
| 81 | if (NOT SYSREPOCTL_ROOT_PERMS) |
| 82 | set(SYSREPOCTL_ROOT_PERMS "-o root:root -p 600") |
| 83 | endif() |
| 84 | |
| 85 | install(CODE " |
| 86 | set(ENV{SYSREPOCTL} ${SYSREPOCTL_EXECUTABLE}) |
| 87 | set(ENV{SYSREPOCFG} ${SYSREPOCFG_EXECUTABLE}) |
| 88 | set(ENV{SYSREPOCTL_ROOT_PERMS} SYSREPOCTL_ROOT_PERMS) |
| 89 | execute_process(COMMAND ${PROJECT_BINARY_DIR}/model-install.sh)") |
| 90 | |
| 91 | |
| 92 | |