-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
182 lines (147 loc) · 5.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
cmake_minimum_required (VERSION 3.13.4)
project(ufw C CXX)
include(CheckIncludeFile)
include(CheckSymbolExists)
include(CTest)
enable_testing()
option(UFW_USE_BUILTIN_SWAP "Use __builtin_bswapXX() if available." ON)
set(UFW_PRIVATE_ERRNO_OFFSET 16384 CACHE STRING "Offset for errno-extensions")
if (ZEPHYR_BASE)
include(zephyr/cmake-cache.cmake)
endif()
if ((NOT CMAKE_BUILD_TYPE) OR ("${CMAKE_BUILD_TYPE}" STREQUAL ""))
set(CMAKE_BUILD_TYPE "debug")
endif()
if (NOT MICROFRAMEWORK_ROOT)
set(MICROFRAMEWORK_ROOT ${PROJECT_SOURCE_DIR})
endif()
if (NOT MICROFRAMEWORK_BINARY_ROOT)
set(MICROFRAMEWORK_BINARY_ROOT ${PROJECT_BINARY_DIR})
endif()
include(InitialiseToolchain OPTIONAL RESULT_VARIABLE WITH_INITIALISE_TOOLCHAIN)
if (NOT WITH_INITIALISE_TOOLCHAIN)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules")
message(STATUS "InitialiseToolchain missing; trying local cmake-modules")
include(InitialiseToolchain OPTIONAL RESULT_VARIABLE WITH_INITIALISE_TOOLCHAIN)
endif()
include(UFWCompiler)
if (WITH_INITIALISE_TOOLCHAIN)
initialise_toolchain()
else()
message(FATAL_ERROR "InitialiseToolchain missing! Giving up!")
endif()
include(SetupTargetCPU)
check_include_file("sys/types.h" WITH_SYS_TYPES_H)
check_include_file("ctype.h" WITH_CTYPE_H)
if (WITH_CTYPE_H)
check_symbol_exists(isprint "ctype.h" UFW_HAVE_CTYPE_ISPRINT)
endif()
check_include_file("unistd.h" WITH_UNISTD_H)
if (WITH_UNISTD_H)
check_symbol_exists(read "unistd.h" UFW_HAVE_POSIX_READ)
check_symbol_exists(write "unistd.h" UFW_HAVE_POSIX_WRITE)
endif()
ufw_compiler_has_type(uint8_t WITH_UINT8_T)
ufw_force_compat(force_compat)
if (${force_compat} EQUAL 0)
check_symbol_exists(strlcat "string.h" UFW_COMPAT_HAVE_STRLCAT)
check_symbol_exists(strlcpy "string.h" UFW_COMPAT_HAVE_STRLCPY)
check_symbol_exists(strnlen "string.h" UFW_COMPAT_HAVE_STRNLEN)
else()
set(UFW_COMPAT_HAVE_STRLCAT 0)
set(UFW_COMPAT_HAVE_STRLCPY 0)
set(UFW_COMPAT_HAVE_STRNLEN 0)
endif()
configure_file("${PROJECT_SOURCE_DIR}/include/ufw/toolchain.h.in"
"${PROJECT_BINARY_DIR}/include/ufw/toolchain.h" )
set(__ufw_sources src/allocator.c
src/crc-16-arc.c
src/endpoints/buffer.c
src/endpoints/continuable-sink.c
src/endpoints/core.c
src/endpoints/instrumentable.c
src/endpoints/posix.c
src/endpoints/trivial.c
src/length-prefix.c
src/hexdump.c
src/byte-buffer.c
src/persistent-storage.c
src/registers/core.c
src/registers/utilities.c
src/register-protocol.c
src/rfc1055.c
src/ring-buffer-iter.c
src/variable-length-integer.c)
if (WITH_UINT8_T)
list(APPEND __ufw_sources src/octet-ring.c)
endif()
set(__ufw_include ${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include)
set(__ufw_tap_sources src/test/memdiff.c
src/test/output-utils.c
src/test/tap.c)
set(__ufw_sx_sources src/sx.c)
set(__ufw_targets)
function(__ufw_setup lib)
list(APPEND __ufw_targets "${lib}")
set(__ufw_targets "${__ufw_targets}" PARENT_SCOPE)
set_property(TARGET ${lib} PROPERTY C_STANDARD 99)
set_target_cpu(${lib})
MakeStrictCompilerC(${lib})
endfunction()
function(__ufw_sanitise lib)
ufw_toolchain(${lib} FEATURES sanitize-address
sanitize-integer
sanitize-undefined-behaviour)
endfunction()
if (NOT UFW_COMPAT_HAVE_STRLCAT)
list(APPEND __ufw_sources src/compat/strlcat.c)
endif()
if (NOT UFW_COMPAT_HAVE_STRLCPY)
list(APPEND __ufw_sources src/compat/strlcpy.c)
endif()
if (NOT UFW_COMPAT_HAVE_STRNLEN)
list(APPEND __ufw_sources src/compat/strnlen.c)
endif()
add_library(ufw STATIC ${__ufw_sources})
__ufw_setup(ufw)
__ufw_sanitise(ufw)
target_include_directories(ufw PUBLIC ${__ufw_include})
if (UFW_USE_BUILTIN_SWAP)
target_compile_definitions(ufw PUBLIC UFW_USE_BUILTIN_SWAP)
endif()
# TODO: Can we test for this requirement? Picolibc needs this.
target_compile_definitions(ufw PUBLIC _DEFAULT_SOURCE)
if (NOT ("${TOOLCHAIN_ID}" MATCHES "^ti-"))
target_link_libraries(ufw PUBLIC m)
endif()
add_library(ufw-tap STATIC ${__ufw_tap_sources})
add_library(ufw-sx STATIC ${__ufw_sx_sources})
foreach (__lib ufw-tap ufw-sx)
__ufw_setup(${__lib})
__ufw_sanitise(${__lib})
target_link_libraries(${__lib} PUBLIC ufw)
endforeach()
if ("${PROJECT_TARGET_CPU}" STREQUAL "native")
add_library(ufw-nosan STATIC ${__ufw_sources})
__ufw_setup(ufw-nosan)
target_include_directories(ufw-nosan PUBLIC ${__ufw_include})
if (UFW_USE_BUILTIN_SWAP)
target_compile_definitions(ufw-nosan PUBLIC UFW_USE_BUILTIN_SWAP)
endif()
if (NOT ("${TOOLCHAIN_ID}" MATCHES "^ti-"))
target_link_libraries(ufw-nosan PUBLIC m)
endif()
add_library(ufw-tap-nosan STATIC ${__ufw_tap_sources})
add_library(ufw-sx-nosan STATIC ${__ufw_sx_sources})
foreach (__lib ufw-tap ufw-sx)
__ufw_setup(${__lib}-nosan)
target_link_libraries(${__lib}-nosan PUBLIC ufw-nosan)
endforeach()
endif()
if (ZEPHYR_BASE)
add_subdirectory_ifdef(CONFIG_UFW_ZEPHYR src/z)
endif()
add_subdirectory(examples)
add_subdirectory(test)
add_subdirectory(doc)