@@ -80,10 +80,73 @@ find_package(CURL REQUIRED)
80
80
find_package (SQLiteCpp REQUIRED )
81
81
find_package (eventpp CONFIG REQUIRED )
82
82
83
+ ## Generating openapi json
84
+ file (READ "${CMAKE_CURRENT_SOURCE_DIR} /../docs/static/openapi/jan.json" JSON_CONTENT )
85
+ string (LENGTH "${JSON_CONTENT} " CONTENT_LENGTH )
86
+ message ("Content length: ${CONTENT_LENGTH} " )
87
+
88
+ file (WRITE "${CMAKE_CURRENT_BINARY_DIR} /cortex_openapi.h"
89
+ "#pragma once\n "
90
+ "#include <string>\n "
91
+ "#include <sstream>\n\n "
92
+ "namespace CortexOpenApi {\n "
93
+ )
94
+
95
+ set (CHUNK_SIZE 2000 )
96
+ set (OFFSET 0 )
97
+ set (CHUNK_INDEX 0 )
98
+
99
+ while (${OFFSET} LESS ${CONTENT_LENGTH} )
100
+ math (EXPR REMAINING "${CONTENT_LENGTH} - ${OFFSET} " )
101
+
102
+ if (${REMAINING} LESS ${CHUNK_SIZE} )
103
+ string (SUBSTRING "${JSON_CONTENT} " ${OFFSET} ${REMAINING} CHUNK_CONTENT )
104
+ math (EXPR OFFSET "${OFFSET} + ${REMAINING} " )
105
+ else ()
106
+ string (SUBSTRING "${JSON_CONTENT} " ${OFFSET} ${CHUNK_SIZE} CHUNK_CONTENT )
107
+ math (EXPR OFFSET "${OFFSET} + ${CHUNK_SIZE} " )
108
+ endif ()
109
+
110
+ # Escape special characters
111
+ string (REPLACE "\\ " "\\\\ " CHUNK_CONTENT "${CHUNK_CONTENT} " )
112
+ string (REPLACE "\" " "\\\" " CHUNK_CONTENT "${CHUNK_CONTENT} " )
113
+ string (REPLACE "\n " "\\ n" CHUNK_CONTENT "${CHUNK_CONTENT} " )
114
+
115
+ file (APPEND "${CMAKE_CURRENT_BINARY_DIR} /cortex_openapi.h"
116
+ " inline std::string const json_part_${CHUNK_INDEX} = \" ${CHUNK_CONTENT} \" ;\n "
117
+ )
118
+
119
+ math (EXPR CHUNK_INDEX "${CHUNK_INDEX} + 1" )
120
+ endwhile ()
121
+
122
+ # Add the get function that concatenates all parts
123
+ file (APPEND "${CMAKE_CURRENT_BINARY_DIR} /cortex_openapi.h"
124
+ "\n inline std::string GetOpenApiJson() {\n "
125
+ " std::ostringstream ss;\n "
126
+ )
127
+
128
+ # Add each part to the stream
129
+ set (INDEX 0 )
130
+ while (${INDEX} LESS ${CHUNK_INDEX} )
131
+ file (APPEND "${CMAKE_CURRENT_BINARY_DIR} /cortex_openapi.h"
132
+ " ss << json_part_${INDEX} ;\n "
133
+ )
134
+ math (EXPR INDEX "${INDEX} + 1" )
135
+ endwhile ()
136
+
137
+ file (APPEND "${CMAKE_CURRENT_BINARY_DIR} /cortex_openapi.h"
138
+ " return ss.str();\n "
139
+ " }\n "
140
+ "}\n "
141
+ )
142
+ ## End of generating openapi json
143
+
83
144
add_executable (${TARGET_NAME} main.cc
84
145
${CMAKE_CURRENT_SOURCE_DIR} /utils/cpuid/cpu_info.cc
85
146
${CMAKE_CURRENT_SOURCE_DIR} /utils/file_logger.cc
86
- )
147
+ )
148
+
149
+ target_include_directories (${TARGET_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR} )
87
150
88
151
target_link_libraries (${TARGET_NAME} PRIVATE httplib::httplib )
89
152
target_link_libraries (${TARGET_NAME} PRIVATE nlohmann_json::nlohmann_json )
@@ -124,4 +187,4 @@ set_target_properties(${TARGET_NAME} PROPERTIES
124
187
RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_BINARY_DIR}
125
188
RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_BINARY_DIR}
126
189
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
127
- )
190
+ )
0 commit comments