-
Notifications
You must be signed in to change notification settings - Fork 43
/
CMakeLists.txt
245 lines (216 loc) · 10.2 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
##################################################################################################
# FILE: CMakelists.txt
# DESCRIPTION: The main CMake file for building Commotion Router images.
#
# Copyright (c) 2014, Josh King
#
# This file is part of Commotion-Router.
#
# Commotion-Router is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Commotion-Router is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Commotion-Router. If not, see <http://www.gnu.org/licenses/>.
##################################################################################################
##################################################################################################
# PROJECT
##################################################################################################
cmake_minimum_required(VERSION 3.0.2)
include(ImageBuilder.cmake)
include(PackageBuilder.cmake)
#Hide unnecessary cache variables for cmake-gui
mark_as_advanced(CMAKE_C_COMPILER)
mark_as_advanced(CMAKE_CXX_COMPILER)
mark_as_advanced(CMAKE_INSTALL_PREFIX)
#Set up project
project(commotion-router VERSION 1.1.0 LANGUAGES NONE)
##################################################################################################
# GLOBALS
##################################################################################################
#Set up variables for cache configuration
set(DEBUG OFF CACHE BOOL "Create verbose Makefile output")
set(COMMOTION_VERSION "master" CACHE STRING "Branch of Commotion to build")
set(COMMOTION_RELEASE "grumpy_cat" CACHE STRING "Commotion release nickname")
set(SKIP_MD5 OFF CACHE BOOL "Skip MD5 checking of downloaded ImageBuilder & PackageBuilder files")
set(COMMOTION_PACKAGES "commotion;commotion-gui;nodewatcher-agent;nodeupgrade;identity-pubkey" CACHE INTERNAL "Commotion default packages")
set(PACKAGEBUILD_TARGETS "commotion;nodewatcher-agent;nodeupgrade;identity-pubkey" CACHE INTERNAL "Make targets for PackageBuilder")
set(OPENWRT_VERSION "15.05.1" CACHE INTERNAL "OpenWRT version number")
set(OPENWRT_RELEASE "chaos_calmer" CACHE INTERNAL "OpenWRT release nickname")
set(BUILD_IMAGES ON CACHE BOOL "Toggle building of images")
set(BUILD_PACKAGES OFF CACHE BOOL "Toggle building of packages")
set(USE_LOCAL OFF CACHE BOOL "Use the locally built packages when building images")
set(JOBS "2" CACHE STRING "Number of parallel compile jobs")
set(DL_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE FILEPATH "Custom download directory")
#Verbose Makefile
if(DEBUG)
set(CMAKE_VERBOSE_MAKEFILE ON)
endif()
#Router default files
set(CONFIGS_DIR "${PROJECT_SOURCE_DIR}/configs")
set(FILES_DIR "${PROJECT_SOURCE_DIR}/files")
set(UPGRADES_DIR "${PROJECT_SOURCE_DIR}/upgrades")
##################################################################################################
# MACROS
##################################################################################################
#Macro for listing config subdirectories.
macro(config_list CONFIG_LIST CONFIGS_DIR)
file(GLOB CHILDREN RELATIVE ${CONFIGS_DIR} ${CONFIGS_DIR}/*)
set(DIR_LIST "")
foreach(CHILD ${CHILDREN})
if(IS_DIRECTORY ${CONFIGS_DIR}/${CHILD})
list(APPEND DIR_LIST ${CHILD})
endif()
endforeach()
set(${CONFIG_LIST} ${DIR_LIST})
endmacro()
#Assert macro
macro(defined VARIABLE ERR_MESSAGE)
if(NOT DEFINED ${VARIABLE})
message(FATAL_ERROR ${ERR_MESSAGE})
endif()
endmacro()
#Macro for choosing which router configuration to use
macro(choose_config CONFIG_PATH)
if(NOT IS_DIRECTORY ${CONFIG_PATH})
message(FATAL_ERROR "Error: Configuration doesn't exist!")
endif()
add_subdirectory(${CONFIG_PATH})
defined(TARGET "Error: Target not defined in configuration!")
defined(SUBTARGET "Error: Subtarget not defined in configuration!")
defined(PROFILE "Error: Profile not defined in configuration!")
endmacro()
##################################################################################################
# SETUP
##################################################################################################
#Get list of available router configs and select one in cache
config_list(CONFIG_LIST ${CONFIGS_DIR})
set(CONFIG "ubnt" CACHE STRING "Commotion Router configuration")
set_property(CACHE CONFIG PROPERTY STRINGS "${CONFIG_LIST}")
choose_config("${CONFIGS_DIR}/${CONFIG}")
#Create list of all packages to include in images
if(DEFINED PACKAGES)
list(APPEND ALL_PACKAGES ${COMMOTION_PACKAGES} ${PACKAGES})
else()
set(ALL_PACKAGES ${COMMOTION_PACKAGES})
endif()
##################################################################################################
# BUILD
##################################################################################################
if(NOT BUILD_PACKAGES AND NOT BUILD_IMAGES)
message(FATAL_ERROR "Not building images or packages, nothing to do!")
endif()
#Call Packagebuilder
if(BUILD_PACKAGES)
#Add Commotion package feed to feeds.conf
set(FEEDS_CONF "${CMAKE_CURRENT_BINARY_DIR}/feeds.conf")
configure_file("${PROJECT_SOURCE_DIR}/feeds.conf.in" "${FEEDS_CONF}")
packagebuild(RELEASE "${OPENWRT_RELEASE}" VERSION "${OPENWRT_VERSION}" TARGET "${TARGET}"
SUBTARGET "${SUBTARGET}" FEEDS_CONF "${FEEDS_CONF}" PACKAGES "${ALL_PACKAGES}" BUILD_TARGETS
${PACKAGEBUILD_TARGETS} JOBS ${JOBS} DEBUG ${DEBUG} DL_DIR ${DL_DIR} SKIP_MD5 ${SKIP_MD5})
endif()
#Call Imagebuilder
if(BUILD_IMAGES)
#Remove existing files directory
if(IS_DIRECTORY ${FILES_DIR})
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/files)
endif()
#Copy default configuration files
if(IS_DIRECTORY ${FILES_DIR})
file(COPY ${FILES_DIR}/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/files)
endif()
#Copy config-specific configuration files
if(IS_DIRECTORY ${CONFIGS_DIR}/${CONFIG}/files)
file(COPY ${CONFIGS_DIR}/${CONFIG}/files/ DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/files)
endif()
#Write version identification files
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/files/etc/openwrt_version "${COMMOTION_VERSION}")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/files/etc/openwrt_release "${COMMOTION_RELEASE}")
#Write banner
configure_file("${PROJECT_SOURCE_DIR}/banner.in"
${CMAKE_CURRENT_BINARY_DIR}/files/etc/banner)
#Write opkg.conf
configure_file("${PROJECT_SOURCE_DIR}/opkg.conf.in"
${CMAKE_CURRENT_BINARY_DIR}/files/etc/opkg.conf)
#Set repository configuration location
set(REPO_CONF "${CMAKE_CURRENT_BINARY_DIR}/repositories.conf")
#Add Commotion package repository to repositories.conf
set(LOCAL OFF)
if(USE_LOCAL)
if(BUILD_PACKAGES)
set(LOCAL ON)
configure_file("${PROJECT_SOURCE_DIR}/repositories.conf.local.in" "${REPO_CONF}")
else()
message(WARNING "BUILD_PACKAGES not set, using remote repository.")
configure_file("${PROJECT_SOURCE_DIR}/repositories.conf.remote.in" "${REPO_CONF}")
endif()
else()
configure_file("${PROJECT_SOURCE_DIR}/repositories.conf.remote.in" "${REPO_CONF}")
endif()
imagebuild(RELEASE "${OPENWRT_RELEASE}" VERSION "${OPENWRT_VERSION}" TARGET "${TARGET}"
SUBTARGET "${SUBTARGET}" FILES "${CMAKE_CURRENT_BINARY_DIR}/files"
PACKAGES "${ALL_PACKAGES}" PROFILE "${PROFILE}" SKIP_MD5 ${SKIP_MD5}
REPO_CONF "${REPO_CONF}" USE_LOCAL ${LOCAL} DEBUG ${DEBUG} DL_DIR ${DL_DIR})
endif()
##################################################################################################
# CREATE UPGRADE BUNDLES
##################################################################################################
if(IS_DIRECTORY ${UPGRADES_DIR} AND EXISTS ${UPGRADES_DIR}/manifest)
set(MAKE_BUNDLES ON CACHE BOOL "Turn built images into Commotion upgrade bundles")
set(SIGN_UPGRADE OFF CACHE BOOL "Sign upgrade manifest with a Serval signing key")
set(KEYRING "" CACHE FILEPATH "Serval keyring for signing upgrade manifest (optional)")
set(PUBLIC_KEY "" CACHE STRING "Public Serval SID key used to sign upgrade manifest (required)")
set(COMMOTIOND_SOCKET "/var/run/commotiond.sock" CACHE FILEPATH "Management socket of commotiond
instance")
if(MAKE_BUNDLES)
file(COPY "${UPGRADES_DIR}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}")
# prepare upgrade package
if(SIGN_UPGRADE AND PUBLIC_KEY)
if(KEYRING)
message(STATUS "Creating signed upgrade package using key ${PUBLIC_KEY} in keyring
${KEYRING}...")
execute_process(
COMMAND "${PROJECT_SOURCE_DIR}/upgrade-builder.sh" prepare -v -d
"${CMAKE_CURRENT_BINARY_DIR}/upgrades" -o "${CMAKE_CURRENT_BINARY_DIR}/upgrades.tar.gz"
-s "${PUBLIC_KEY}" -b "${COMMOTIOND_SOCKET}" -k "${KEYRING}"
RESULT_VARIABLE EXEC_SUCCESS
)
else()
message(STATUS "Creating signed upgrade package using key ${PUBLIC_KEY} in default
keyring...")
execute_process(
COMMAND "${PROJECT_SOURCE_DIR}/upgrade-builder.sh" prepare -v -d
"${CMAKE_CURRENT_BINARY_DIR}/upgrades" -o "${CMAKE_CURRENT_BINARY_DIR}/upgrades.tar.gz"
-s "${PUBLIC_KEY}" -b "${COMMOTIOND_SOCKET}"
RESULT_VARIABLE EXEC_SUCCESS
)
endif()
else()
message(STATUS "Creating unsigned upgrade package...")
execute_process(
COMMAND "${PROJECT_SOURCE_DIR}/upgrade-builder.sh" prepare -v -d
"${CMAKE_CURRENT_BINARY_DIR}/upgrades" -o "${CMAKE_CURRENT_BINARY_DIR}/upgrades.tar.gz"
RESULT_VARIABLE EXEC_SUCCESS
)
endif()
if(NOT EXEC_SUCCESS EQUAL 0)
message(FATAL_ERROR "Error: Failed to create upgrade package!")
endif()
if(BUILD_IMAGES)
add_custom_target(bundle ALL
COMMAND "${PROJECT_SOURCE_DIR}/upgrade-builder.sh" build -v -p
"${CMAKE_CURRENT_BINARY_DIR}/upgrades.tar.gz" -d
"${CMAKE_CURRENT_BINARY_DIR}/bin/${TARGET}/${SUBTARGET}" -r "${COMMOTION_VERSION}"
DEPENDS image_builder
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Bundling release images..." VERBATIM
)
endif()
endif()
endif()