Skip to content

Commit bd381c1

Browse files
Extract the playground in its own HTML file (quackscience#24)
1 parent 547bbf1 commit bd381c1

File tree

5 files changed

+846
-16
lines changed

5 files changed

+846
-16
lines changed

CMakeLists.txt

+18-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,24 @@ set(EXTENSION_NAME ${TARGET_NAME}_extension)
66
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)
77

88
project(${TARGET_NAME})
9-
include_directories(src/include duckdb/third_party/httplib duckdb/parquet/include)
10-
11-
set(EXTENSION_SOURCES src/httpserver_extension.cpp)
9+
include_directories(
10+
src/include
11+
${CMAKE_CURRENT_BINARY_DIR}
12+
duckdb/third_party/httplib
13+
duckdb/parquet/include
14+
)
15+
16+
# Embed ./src/assets/index.html as a C++ header
17+
add_custom_command(
18+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/playground.hpp
19+
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/embed.cmake ${PROJECT_SOURCE_DIR}/src/assets/index.html ${CMAKE_CURRENT_BINARY_DIR}/playground.hpp playgroundContent
20+
DEPENDS ${PROJECT_SOURCE_DIR}/src/assets/index.html
21+
)
22+
23+
set(EXTENSION_SOURCES
24+
src/httpserver_extension.cpp
25+
${CMAKE_CURRENT_BINARY_DIR}/playground.hpp
26+
)
1227

1328
if(MINGW)
1429
set(OPENSSL_USE_STATIC_LIBS TRUE)

embed.cmake

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
set(resource_file_name ${CMAKE_ARGV3})
2+
set(output_file_name ${CMAKE_ARGV4})
3+
set(variable_name ${CMAKE_ARGV5})
4+
5+
file(READ "${resource_file_name}" hex_content HEX)
6+
7+
string(REPEAT "[0-9a-f]" 32 pattern)
8+
string(REGEX REPLACE "(${pattern})" "\\1\n" content "${hex_content}")
9+
10+
string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " content "${content}")
11+
12+
string(REGEX REPLACE ", $" "" content "${content}")
13+
14+
set(array_definition "static const unsigned char ${variable_name}[] =\n{\n${content}\n};")
15+
16+
set(output "// Auto generated file.\n${array_definition}\n")
17+
18+
file(WRITE "${output_file_name}" "${output}")

0 commit comments

Comments
 (0)