-
Notifications
You must be signed in to change notification settings - Fork 5
/
CMakeLists.txt
175 lines (143 loc) · 5.54 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
# The following lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.14)
set(TARGET_TYPE "freertos_idf"
CACHE STRING "Type of build: 'linux', 'freertos_idf', 'arduino_esp32'")
file(TO_CMAKE_PATH "$ENV{IDF_PATH}" ENV_IDF_PATH)
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
# This is the entry point for the ESP/IDF build system. What is
# happening there is managed by the build environment of Espressif.
if("${TARGET_TYPE}" STREQUAL "" OR "${TARGET_TYPE}" STREQUAL "freertos_idf")
if(NOT "$ENV{IDF_PATH}" STREQUAL "")
# Set a default target type.
set(TARGET_TYPE "freertos_idf")
set(ENV{TARGET_TYPE} "freertos_idf")
message("Configuring: ESP-IDF build")
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
add_compile_definitions(configUSE_POSIX_ERRNO=1)
project(RINA_sensor)
else()
message(FATAL_ERROR "The 'freertos_idf' target needs the IDF_PATH environment variable to be defined")
endif()
else()
if(${TARGET_TYPE} STREQUAL "arduino_esp32")
# This really needs to be set before the call to project()
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/Arduino-CMake-Toolchain/Arduino-toolchain.cmake)
endif()
project(RINA_sensor)
#
# This is the entry point for all platform support building through
# CMake and GCC.
#
include(lib.common)
include(lib.${TARGET_TYPE})
# Declares which components needs to be built in the shared library.
set(shared_library_components
BufferManagement
CdapProto
Common
configRINA
configSensor
EFCP
Enrollment
FlowAllocator
IPCP
Portability
Ribd
RINA_API
Rmt
Shim)
# Common warnings and options.
add_compile_options(
-Wall -Werror -Wextra
# Disable some warnings while development is active. It drowns the
# other more important warnings.
-Wno-unused-but-set-variable
-Wno-unused-function
-Wno-unused-variable
-Wno-unused-parameter
# Debugging information
-ggdb3
# Disables optimisation
-O0
# Automatically add 'stdbool.h' as an include file to all
# files. It is a bit weird to add it here so maybe I should
# consider including it in the Portability component, or in Common
-include stdbool.h
)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ggdb3 -O0 -include stdbool.h")
# Automagically find all the components in the source tree.
rs_scan_cmakelists()
# Runs a sanity check on the dependencies and add all the required
# include paths to each libraries.
rs_resolve_dependencies()
#
# Target specific code starts here.
#
if(${TARGET_TYPE} STREQUAL "arduino_esp32")
#
# ESP32 + Arduino!
#
# The Arduino/ESP32 port needs more component
list(APPEND shared_library_components
FreeRTOS-Plus-POSIX
)
# Add all components objects in the Linux shared library.
foreach(component IN LISTS shared_library_components)
list(APPEND shared_library_objects $<TARGET_OBJECTS:${component}>)
rs_get_component_include_dirs(${component} component_includes)
list(APPEND shared_library_includes ${component_includes})
endforeach()
# GCC sets this in Linux but the Arduino toolchain apparently does
# not.
add_compile_definitions(__LONG_WIDTH__=32)
add_library(RINA ${shared_library_objects})
target_include_directories(RINA PUBLIC ${shared_library_includes})
target_link_arduino_libraries(RINA PRIVATE core)
add_subdirectory(test_arduino)
elseif(${TARGET_TYPE} STREQUAL "linux")
#
# Linux/POSIX
#
include(CTest)
include(GNUInstallDirs)
add_compile_definitions(configUSE_POSIX_ERRNO=1)
# Add all components objects in the Linux shared library.
foreach(component IN LISTS shared_library_components)
list(APPEND shared_library_objects $<TARGET_OBJECTS:${component}>)
rs_get_component_include_dirs(${component} component_includes)
list(APPEND shared_library_includes ${component_includes})
target_compile_options(${component} PRIVATE -fPIC)
endforeach()
# Public headers we'll install with the target
#
# FIXME: We need a better way than this to identify headers which
# should be part of the install.
set(public_headers
"components/RINA_API/include/RINA_API.h"
"components/RINA_API/include/RINA_API_flows.h"
"components/configRINA/include/configRINA.h"
"components/IPCP/include/IPCP.h"
"components/Portability/include/portability/port.h"
"components/Portability/include/portability/rsassert.h"
"components/Portability/include/portability/rsdefs.h"
"components/Portability/include/portability/rslog.h"
"components/Portability/include/portability/rsmem.h"
"components/Portability/include/portability/rsnet.h"
"components/Portability/include/portability/rsposix.h"
"components/Portability/include/portability/rsqueue.h"
"components/Portability/include/portability/rstime.h"
"components/Common/include/common/rina_gpha.h"
"components/Common/include/common/rina_name.h")
# Declare the shared library.
add_library(RINA SHARED ${shared_library_objects})
target_sources(RINA PUBLIC ${public_headers})
target_include_directories(RINA PUBLIC ${shared_library_includes})
install(TARGETS RINA)
install(FILES ${public_headers} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/RINA)
add_subdirectory(test_linux)
# We do not want the 'install()' function to work at all anymore.
rs_disable_install()
add_subdirectory(unity)
endif()
endif()