-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathble.cmake
116 lines (104 loc) · 3.75 KB
/
ble.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
set(LIBFMT_VENDORIZE OFF)
set(SIMPLEBLE_INSTALL OFF)
block()
if(MSVC)
add_compile_options("/w")
else()
add_compile_options("-w")
endif()
add_subdirectory(3rdparty/SimpleBLE/simpleble "${CMAKE_BINARY_DIR}/simpleble-build" SYSTEM)
endblock()
set(ble-database_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/bluetooth-numbers-database/")
set(BLE_SERVICE_UUIDS_JSON "${ble-database_SOURCE_DIR}/v1/service_uuids.json")
file(READ "${BLE_SERVICE_UUIDS_JSON}" BLE_SERVICE_UUIDS)
string(JSON BLE_SERVICE_COUNT LENGTH "${BLE_SERVICE_UUIDS}")
math(EXPR BLE_SERVICE_COUNT "${BLE_SERVICE_COUNT} - 1")
function(ble_reformat_uuid var)
set(varname "${var}")
set(val "${${var}}")
string(LENGTH "${val}" len)
if("${len}" EQUAL 4)
set("${var}" "0000${val}-0000-1000-8000-00805F9B34FB" PARENT_SCOPE)
endif()
endfunction()
set(BLE_SERVICE_ARRAY "")
foreach(IDX RANGE ${BLE_SERVICE_COUNT})
string(JSON BLE_SERVICE_NAME GET "${BLE_SERVICE_UUIDS}" "${IDX}" name)
string(JSON BLE_SERVICE_UUID GET "${BLE_SERVICE_UUIDS}" "${IDX}" uuid)
ble_reformat_uuid(BLE_SERVICE_UUID)
string(APPEND BLE_SERVICE_ARRAY "ble_services_table[\"${BLE_SERVICE_UUID}\"] = \"${BLE_SERVICE_NAME}\";\n")
endforeach()
set(BLE_CHAR_UUIDS_JSON "${ble-database_SOURCE_DIR}/v1/characteristic_uuids.json")
file(READ "${BLE_CHAR_UUIDS_JSON}" BLE_CHAR_UUIDS)
string(JSON BLE_CHAR_COUNT LENGTH "${BLE_CHAR_UUIDS}")
math(EXPR BLE_CHAR_COUNT "${BLE_CHAR_COUNT} - 1")
set(BLE_CHAR_ARRAY "")
foreach(IDX RANGE ${BLE_CHAR_COUNT})
string(JSON BLE_CHAR_NAME GET "${BLE_CHAR_UUIDS}" "${IDX}" name)
string(JSON BLE_CHAR_UUID GET "${BLE_CHAR_UUIDS}" "${IDX}" uuid)
ble_reformat_uuid(BLE_CHAR_UUID)
string(APPEND BLE_CHAR_ARRAY "ble_characteristic_table[\"${BLE_CHAR_UUID}\"] = \"${BLE_CHAR_NAME}\";\n")
endforeach()
set(BLE_DESC_UUIDS_JSON "${ble-database_SOURCE_DIR}/v1/descriptor_uuids.json")
file(READ "${BLE_DESC_UUIDS_JSON}" BLE_DESC_UUIDS)
string(JSON BLE_DESC_COUNT LENGTH "${BLE_DESC_UUIDS}")
math(EXPR BLE_DESC_COUNT "${BLE_DESC_COUNT} - 1")
set(BLE_DESC_ARRAY "")
foreach(IDX RANGE ${BLE_DESC_COUNT})
string(JSON BLE_DESC_NAME GET "${BLE_DESC_UUIDS}" "${IDX}" name)
string(JSON BLE_DESC_UUID GET "${BLE_DESC_UUIDS}" "${IDX}" uuid)
ble_reformat_uuid(BLE_DESC_UUID)
string(APPEND BLE_DESC_ARRAY "ble_descriptor_table[\"${BLE_DESC_UUID}\"] = \"${BLE_DESC_NAME}\";\n")
endforeach()
file(CONFIGURE
OUTPUT
"${PROJECT_BINARY_DIR}/ble_service_map.cpp"
CONTENT
"#include <ossia/detail/case_insensitive.hpp>\n\
namespace ossia {\n\
using ble_map_type = ossia::case_insensitive_string_map<std::string>;\n\
const ble_map_type& ble_service_map() {\n\
static const ble_map_type res = [] {\n\
ble_map_type ble_services_table;\n\
${BLE_SERVICE_ARRAY}\n\
return ble_services_table;\n\
}();\n\
return res;\n\
}\n\
}\n\
")
file(CONFIGURE
OUTPUT
"${PROJECT_BINARY_DIR}/ble_characteristic_map.cpp"
CONTENT
"#include <ossia/detail/case_insensitive.hpp>\n\
namespace ossia {\n\
using ble_map_type = ossia::case_insensitive_string_map<std::string>;\n\
const ble_map_type& ble_characteristic_map() {\n\
static const ble_map_type res = [] {\n\
ble_map_type ble_characteristic_table;\n\
${BLE_CHAR_ARRAY}\n\
return ble_characteristic_table;\n\
}();\n\
return res;\n\
}\n\
}\n\
")
file(CONFIGURE
OUTPUT
"${PROJECT_BINARY_DIR}/ble_descriptor_map.cpp"
CONTENT
"#include <ossia/detail/case_insensitive.hpp>\n\
namespace ossia {\n\
using ble_map_type = ossia::case_insensitive_string_map<std::string>;\n\
const ble_map_type& ble_descriptor_map() {\n\
static const ble_map_type res = [] {\n\
ble_map_type ble_descriptor_table;\n\
${BLE_DESC_ARRAY}\n\
return ble_descriptor_table;\n\
}();\n\
return res;\n\
}\n\
}\n\
"
)