This repository has been archived by the owner on Sep 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
CMakeLists.txt
188 lines (156 loc) · 7.29 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
cmake_minimum_required(VERSION 3.1)
cmake_policy(VERSION 3.1)
project(prplmesh
LANGUAGES C CXX
VERSION 1.4.0)
include(cmake/multiap-helpers.cmake)
if(NOT DEFINED TARGET_PLATFORM)
set(TARGET_PLATFORM "linux")
endif()
option (BUILD_AGENT "Build EasyMesh agent" ON)
option (BUILD_CONTROLLER "Build EasyMesh controller" ON)
option(BUILD_SHARED_LIBS "Build shared libraries (.so) instead of static ones (.a)" ON)
## Generic checks and defaults
include(FindPkgConfig)
include(GNUInstallDirs)
# Add global project cmake modules path
list(INSERT CMAKE_MODULE_PATH 0 ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set (CMAKE_INSTALL_PREFIX "${CMAKE_BINARY_DIR}/install" CACHE PATH "default install path" FORCE)
endif()
# Update output directories for easy deployment
set(CMAKE_MULTIAP_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/out)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_MULTIAP_OUTPUT_DIRECTORY}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_MULTIAP_OUTPUT_DIRECTORY}/bin)
message(STATUS "CMAKE_FIND_ROOT_PATH - ${CMAKE_FIND_ROOT_PATH}")
message(STATUS "CMAKE_INSTALL_PREFIX - ${CMAKE_INSTALL_PREFIX}")
message(STATUS "CMAKE_MODULE_PATH - ${CMAKE_MODULE_PATH}")
message(STATUS "CMAKE_PREFIX_PATH - ${CMAKE_PREFIX_PATH}")
message(STATUS "CMAKE_MULTIAP_OUTPUT_DIRECTORY - ${CMAKE_MULTIAP_OUTPUT_DIRECTORY}")
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON) # Do not fall back to C++98
if(CMAKE_BUILD_TYPE STREQUAL "Release")
# When compiling with openWrt, FORTIFY_SOURCE=1 always gets added.
# Since we anyway use FORTIFY_SOURCE=2 and it cannot be set two times
# with a different value, we remove the one set externally, and add our own
string(REGEX REPLACE "-D_FORTIFY_SOURCE=[0-9]" "" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
string(REGEX REPLACE "-D_FORTIFY_SOURCE=[0-9]" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
string(REGEX REPLACE "-D_FORTIFY_SOURCE=[0-9]" "" CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}")
string(REGEX REPLACE "-D_FORTIFY_SOURCE=[0-9]" "" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
add_definitions("-D_FORTIFY_SOURCE=2")
endif()
# Default Compiler flags
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -pthread -Wno-comment -Wno-unused-parameter -Wno-missing-field-initializers")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -s -O2 -Wformat -Wformat-security -Wl,-S -fPIC -fPIE")
# Compiler specific flags
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.9)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-address-of-packed-member")
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fstack-protector-strong")
else()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fstack-protector")
endif()
# Release flags
set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} ${CMAKE_C_FLAGS_RELEASE}")
# Linker Options
# - Setting the "rpath-link" linker variable to help the linker resolve secondery dependecies
# (Libraries that are not directly referenced by the executable, but a linked library)
# - Setting "rpath" linker to add the cmake installed library folder to the linker search path
# (Removes the need to set LD_LIBRARY_PATH manually when installing to a none standard location)
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath=${CMAKE_INSTALL_FULL_LIBDIR},-rpath-link=${PLATFORM_STAGING_DIR}/usr/lib")
if (CMAKE_BUILD_TYPE STREQUAL "Release")
SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -z noexecstack -z relro -z now -pie")
endif()
list (FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" isSystemDir)
if ("${isSystemDir}" STREQUAL "-1")
set (CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}")
endif ("${isSystemDir}" STREQUAL "-1")
set (CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
set(INSTALL_PATH "/opt/prplmesh" CACHE PATH "prplMesh installation directory")
set(TMP_PATH "/tmp/beerocks")
if(TARGET_PLATFORM STREQUAL "linux")
set(INSTALL_PATH "${CMAKE_INSTALL_PREFIX}")
option(USE_USER_TMP_PATH "use /tmp/$USER instead of /tmp path" ON)
if(USE_USER_TMP_PATH)
set(USER "$ENV{USER}")
set(TMP_PATH "/tmp/${USER}/beerocks")
endif()
endif()
# Default values
set(BEEROCKS_WLAN1_IFACE "wlan0" CACHE STRING "1st WLAN iface")
set(BEEROCKS_WLAN2_IFACE "wlan2" CACHE STRING "2nd WLAN iface")
set(BEEROCKS_WLAN3_IFACE "wlan4" CACHE STRING "3rd WLAN iface")
set(BEEROCKS_BRIDGE_IFACE "br-lan" CACHE STRING "LAN bridge")
set(BEEROCKS_BH_WIRE_IFACE "eth1" CACHE STRING "Backhaul wire iface")
set(BEEROCKS_REPEATER_MODE 0)
# Logging configuration
set(BEEROCKS_LOG_FILES_ENABLED "true" CACHE STRING "Write prplMesh logs into files")
set(BEEROCKS_LOG_FILES_PATH "${TMP_PATH}/logs" CACHE PATH "prplMesh logs directory")
set(BEEROCKS_LOG_FILES_SUFFIX ".log" CACHE STRING "prplMesh logs filenames suffix")
set(BEEROCKS_LOG_FILES_AUTO_ROLL "true" CACHE STRING "Auto rollback prplMesh logs")
set(BEEROCKS_LOG_STDOUT_ENABLED "false" CACHE STRING "Print logs to stdout")
set(BEEROCKS_LOG_SYSLOG_ENABLED "false" CACHE STRING "Send logs to syslog")
# Platform specific flags
if (TARGET_PLATFORM STREQUAL "openwrt")
if (TARGET_PLATFORM_TYPE STREQUAL "ugw")
add_definitions(-DBEEROCKS_UGW)
set(BEEROCKS_REPEATER_MODE 1)
else()
set(BEEROCKS_WLAN2_IFACE "wlan1")
set(BEEROCKS_WLAN2_STEERING_VAPS "wlan1.0")
endif()
elseif (TARGET_PLATFORM STREQUAL "rdkb")
add_definitions(-DBEEROCKS_RDKB)
set(BEEROCKS_BRIDGE_IFACE "brlan0")
set(BEEROCKS_BH_WIRE_IFACE "nsgmii0")
# Disable file and enable syslog logging
set(BEEROCKS_LOG_FILES_ENABLED "false")
set(BEEROCKS_LOG_SYSLOG_ENABLED "true")
set(BEEROCKS_LOG_FILES_AUTO_ROLL "false")
set(BEEROCKS_LOG_FILES_PATH "/rdklogs/logs")
set(BEEROCKS_LOG_FILES_SUFFIX ".txt.0")
set(CMAKE_SKIP_RPATH TRUE)
elseif (TARGET_PLATFORM STREQUAL "linux")
add_definitions(-DBEEROCKS_LINUX)
set(BEEROCKS_BH_WIRE_IFACE "eth0")
endif()
# Test support
option(BUILD_TESTS "build multiap unit tests" OFF)
if (BUILD_TESTS)
enable_testing()
message(STATUS "Tests are enabled")
# Compile GoogleTest statically (so we don't have to install libraries)
set(BUILD_SHARED_LIBS_SAVED "${BUILD_SHARED_LIBS}")
set(BUILD_SHARED_LIBS OFF)
# GoogleTest
# https://github.com/google/googletest/blob/master/googletest/README.md#incorporating-into-an-existing-cmake-project
include(cmake/googletest.cmake)
# Revert it
set(BUILD_SHARED_LIBS "${BUILD_SHARED_LIBS_SAVED}")
endif()
# Code coverage analysis support
option(COVERAGE "add run-time instrumentation for test coverage analysis" OFF)
if (COVERAGE)
message(STATUS "Coverage support is enabled")
else()
message(STATUS "Coverage support is not enabled")
endif()
## Components
add_subdirectory(framework)
add_subdirectory(common)
if (BUILD_AGENT)
add_subdirectory(agent)
endif()
if (BUILD_CONTROLLER)
add_subdirectory(controller)
endif()
## Version
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/version.in"
"${CMAKE_CURRENT_BINARY_DIR}/version"
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/version DESTINATION config)
file(COPY ${CMAKE_CURRENT_BINARY_DIR}/version DESTINATION "${CMAKE_MULTIAP_OUTPUT_DIRECTORY}/config")