blob: 804f80bb70141f18b78bfe52e05cc08d4d769a1e [file] [log] [blame]
Alex Stancu29ce3682019-11-02 10:38:59 +02001cmake_minimum_required(VERSION 2.8.12)
2project(ntsimulator)
3set(PROJECT_DESC "Network Topology Simulator using sysrepo and netopeer2")
4include(GNUInstallDirs)
5
6# setup version
7set(NTSIMULATOR_MAJOR_VERSION 1)
8set(NTSIMULATOR_MINOR_VERSION 1)
9set(NTSIMULATOR_PATCH_VERSION 1)
10set(NTSIMULATOR_VERSION ${NTSIMULATOR_MAJOR_VERSION}.${NTSIMULATOR_MINOR_VERSION}.${NTSIMULATOR_PATCH_VERSION})
11set(NTSIMULATOR_SOVERSION ${NTSIMULATOR_MAJOR_VERSION}.${NTSIMULATOR_MINOR_VERSION})
12
13# osx specific
14set(CMAKE_MACOSX_RPATH TRUE)
15
16# set default build type if not specified by user
17if(NOT CMAKE_BUILD_TYPE)
18 set(CMAKE_BUILD_TYPE debug)
19endif()
20string(TOLOWER "${CMAKE_BUILD_TYPE}" CMAKE_BUILD_TYPE_LOWER)
21
22set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
23
24set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wpedantic -std=gnu11 -Wno-language-extension-token")
25if(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")
28endif()
29set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG -O2")
30set(CMAKE_C_FLAGS_DEBUG "-g -O0")
31
32if(NOT UNIX)
33 message(FATAL_ERROR "Only Unix-like systems are supported.")
34endif()
35
36if(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()
42endif()
43
44# location of system repository
45if(${IS_DEVELOPER_CONFIGURATION})
46 set(REPOSITORY_LOC "${CMAKE_BINARY_DIR}/repository" CACHE PATH "System repository location, contains configuration schema and data files.")
47else()
48 set(REPOSITORY_LOC "/etc/sysrepo" CACHE PATH "System repository location, contains configuration schema and data files.")
49endif()
50
51# include custom Modules
52set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/CMakeModules/")
53include_directories(${CMAKE_CURRENT_BINARY_DIR})
54include_directories("${CMAKE_CURRENT_SOURCE_DIR}/inc")
55
56# find required libraries
57find_package(SYSREPO REQUIRED)
58include_directories(${SYSREPO_INCLUDE_DIR})
59
60# add subdirectories
61add_subdirectory(src)
62
Alex Stancu29ce3682019-11-02 10:38:59 +020063# find sysrepoctl
64if (NOT SYSREPOCTL_EXECUTABLE)
65 find_program(SYSREPOCTL_EXECUTABLE sysrepoctl)
66endif()
67if (NOT SYSREPOCTL_EXECUTABLE)
68 message(FATAL_ERROR "Unable to find sysrepoctl, set SYSREPOCTL_EXECUTABLE manually.")
69endif()
70
71# find sysrepocfg
72if (NOT SYSREPOCFG_EXECUTABLE)
73 find_program(SYSREPOCFG_EXECUTABLE sysrepocfg)
74endif()
75if (NOT SYSREPOCFG_EXECUTABLE)
76 message(FATAL_ERROR "Unable to find sysrepocfg, set SYSREPOCFG_EXECUTABLE manually.")
77endif()
78
79# Command line options to be passed to `sysrepoctl` when working with modules
80# which should only be accessible by an administrator
81if (NOT SYSREPOCTL_ROOT_PERMS)
82 set(SYSREPOCTL_ROOT_PERMS "-o root:root -p 600")
83endif()
84
85install(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