forked from u-blox/ubxlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathubxlib.cmake
157 lines (142 loc) · 6.11 KB
/
ubxlib.cmake
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
# This is a shared CMake file used for the ports using CMake build system.
# It is used for collecting source code files and include directories
# that are selected based on UBXLIB_FEATURES. Check README.md for details.
cmake_minimum_required(VERSION 3.13.1)
# Always include base feature
list(APPEND UBXLIB_FEATURES base)
# Conditionally add one .c file to UBXLIB_SRC
function(u_add_source_file feature file)
if (NOT EXISTS ${file})
message(FATAL_ERROR "File does not exist: ${file}")
endif()
if (${feature} IN_LIST UBXLIB_FEATURES)
list(APPEND UBXLIB_SRC ${file})
set(UBXLIB_SRC ${UBXLIB_SRC} PARENT_SCOPE)
endif()
endfunction()
# Conditionally add all .c files in a directory to UBXLIB_SRC
function(u_add_source_dir feature src_dir)
if (NOT EXISTS ${src_dir})
message(FATAL_ERROR "Directory does not exist: ${src_dir}")
endif()
if (${feature} IN_LIST UBXLIB_FEATURES)
file(GLOB SRCS ${src_dir}/*.c)
list(APPEND UBXLIB_SRC ${SRCS})
set(UBXLIB_SRC ${UBXLIB_SRC} PARENT_SCOPE)
endif()
endfunction()
# Conditionally add all .c files in a directory to UBXLIB_TEST_SRC
function(u_add_test_source_dir feature src_dir)
if (NOT EXISTS ${src_dir})
message(FATAL_ERROR "Directory does not exist: ${src_dir}")
endif()
if (${feature} IN_LIST UBXLIB_FEATURES)
file(GLOB SRCS ${src_dir}/*.c)
if (NOT SRCS)
message(FATAL_ERROR "No source files found in directory: ${src_dir}")
endif()
list(APPEND UBXLIB_TEST_SRC ${SRCS})
set(UBXLIB_TEST_SRC ${UBXLIB_TEST_SRC} PARENT_SCOPE)
endif()
endfunction()
# This function will take a module directory and:
# - Add <module_dir>/src/*.c to UBXLIB_SRC
# - Add <module_dir>/src to UBXLIB_PRIVATE_INC
# - Add <module_dir>/api to UBXLIB_INC
# - Add <module_dir>/test/*.c to UBXLIB_TEST_SRC
# - Add <module_dir>/test to UBXLIB_TEST_INC
# but only if the feature is enabled
function(u_add_module_dir feature module_dir)
if (NOT EXISTS ${module_dir})
message(FATAL_ERROR "Directory does not exist: ${module_dir}")
endif()
if (${feature} IN_LIST UBXLIB_FEATURES)
if(EXISTS ${module_dir}/src)
u_add_source_dir(${feature} ${module_dir}/src)
endif()
if(EXISTS ${module_dir}/test)
u_add_test_source_dir(${feature} ${module_dir}/test)
endif()
if(EXISTS ${module_dir}/api)
list(APPEND UBXLIB_INC ${module_dir}/api)
endif()
if(EXISTS ${module_dir}/src)
list(APPEND UBXLIB_PRIVATE_INC ${module_dir}/src)
endif()
if(EXISTS ${module_dir}/test)
list(APPEND UBXLIB_TEST_INC ${module_dir}/test)
endif()
set(UBXLIB_SRC ${UBXLIB_SRC} PARENT_SCOPE)
set(UBXLIB_INC ${UBXLIB_INC} PARENT_SCOPE)
set(UBXLIB_PRIVATE_INC ${UBXLIB_PRIVATE_INC} PARENT_SCOPE)
set(UBXLIB_TEST_SRC ${UBXLIB_TEST_SRC} PARENT_SCOPE)
set(UBXLIB_TEST_INC ${UBXLIB_TEST_INC} PARENT_SCOPE)
endif()
endfunction()
# ubxlib base source and includes
# Add /api, /src and /test sub folders for these:
u_add_module_dir(base ${UBXLIB_BASE}/common/at_client)
u_add_module_dir(base ${UBXLIB_BASE}/common/error)
u_add_module_dir(base ${UBXLIB_BASE}/common/assert)
u_add_module_dir(base ${UBXLIB_BASE}/common/location)
u_add_module_dir(base ${UBXLIB_BASE}/common/mqtt_client)
u_add_module_dir(base ${UBXLIB_BASE}/common/security)
u_add_module_dir(base ${UBXLIB_BASE}/common/sock)
u_add_module_dir(base ${UBXLIB_BASE}/common/ubx_protocol)
u_add_module_dir(base ${UBXLIB_BASE}/common/utils)
# Additional source directories
u_add_source_dir(base ${UBXLIB_BASE}/port/platform/common/event_queue)
u_add_source_dir(base ${UBXLIB_BASE}/port/platform/common/mutex_debug)
# Additional include directories
list(APPEND UBXLIB_INC
${UBXLIB_BASE}/cfg
${UBXLIB_BASE}/port/api
)
list(APPEND UBXLIB_PRIVATE_INC
${UBXLIB_BASE}/port/platform/common/event_queue
${UBXLIB_BASE}/port/platform/common/mutex_debug
)
# Network requires special care since it contains stub & optional files
list(APPEND UBXLIB_SRC ${UBXLIB_BASE}/common/network/src/u_network.c)
list(APPEND UBXLIB_INC ${UBXLIB_BASE}/common/network/api)
list(APPEND UBXLIB_PRIVATE_INC ${UBXLIB_BASE}/common/network/src)
# Optional features
# short range
u_add_module_dir(short_range ${UBXLIB_BASE}/common/short_range)
u_add_module_dir(short_range ${UBXLIB_BASE}/ble)
u_add_module_dir(short_range ${UBXLIB_BASE}/wifi)
u_add_source_file(short_range ${UBXLIB_BASE}/common/network/src/u_network_private_ble_extmod.c)
u_add_source_file(short_range ${UBXLIB_BASE}/common/network/src/u_network_private_ble_intmod.c)
u_add_source_file(short_range ${UBXLIB_BASE}/common/network/src/u_network_private_wifi.c)
u_add_source_file(short_range ${UBXLIB_BASE}/common/network/src/u_network_private_short_range.c)
# cell
u_add_module_dir(cell ${UBXLIB_BASE}/cell)
u_add_source_file(cell ${UBXLIB_BASE}/common/network/src/u_network_private_cell.c)
# gnss
u_add_module_dir(gnss ${UBXLIB_BASE}/gnss)
u_add_source_file(gnss ${UBXLIB_BASE}/common/network/src/u_network_private_gnss.c)
# lib_common
# We have a dependency issue with libfibonacci so lib_common/test needs to manually
# included by the runner app instead at the moment. For this reason we just add the
# source and include dir here.
if (u_lib IN_LIST UBXLIB_FEATURES)
list(APPEND UBXLIB_INC ${UBXLIB_BASE}/common/lib_common/api)
u_add_source_dir(u_lib ${UBXLIB_BASE}/common/lib_common/src)
endif()
# Test related files and directories
list(APPEND UBXLIB_TEST_INC
${UBXLIB_BASE}/common/network/test
)
u_add_test_source_dir(base ${UBXLIB_BASE}/port/platform/common/test)
u_add_test_source_dir(base ${UBXLIB_BASE}/port/test)
u_add_test_source_dir(base ${UBXLIB_BASE}/common/network/test)
# Examples are compiled as tests
u_add_test_source_dir(base ${UBXLIB_BASE}/example/sockets)
u_add_test_source_dir(base ${UBXLIB_BASE}/example/security/e2e)
u_add_test_source_dir(base ${UBXLIB_BASE}/example/security/psk)
u_add_test_source_dir(base ${UBXLIB_BASE}/example/security/c2c)
u_add_test_source_dir(base ${UBXLIB_BASE}/example/mqtt_client)
u_add_test_source_dir(base ${UBXLIB_BASE}/example/location)
u_add_test_source_dir(base ${UBXLIB_BASE}/example/cell/lte_cfg)
u_add_test_source_dir(base ${UBXLIB_BASE}/example/cell/power_saving)
u_add_test_source_dir(base ${UBXLIB_BASE}/example/utilities/c030_module_fw_update)