Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract the playground in its own HTML file #24

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@
set(LOADABLE_EXTENSION_NAME ${TARGET_NAME}_loadable_extension)

project(${TARGET_NAME})
include_directories(src/include duckdb/third_party/httplib duckdb/parquet/include)

set(EXTENSION_SOURCES src/httpserver_extension.cpp)
include_directories(
src/include
${CMAKE_CURRENT_BINARY_DIR}
duckdb/third_party/httplib
duckdb/parquet/include
)

# Embed ./src/assets/index.html as a C++ header
add_custom_command(
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/playground.hpp
COMMAND ${CMAKE_COMMAND} -P ${PROJECT_SOURCE_DIR}/embed.cmake ${PROJECT_SOURCE_DIR}/src/assets/index.html ${CMAKE_CURRENT_BINARY_DIR}/playground.hpp playgroundContent
DEPENDS ${PROJECT_SOURCE_DIR}/src/assets/index.html
)

set(EXTENSION_SOURCES
src/httpserver_extension.cpp
${CMAKE_CURRENT_BINARY_DIR}/playground.hpp
)

if(MINGW)
set(OPENSSL_USE_STATIC_LIBS TRUE)
Expand Down
18 changes: 18 additions & 0 deletions embed.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
set(resource_file_name ${CMAKE_ARGV3})
set(output_file_name ${CMAKE_ARGV4})
set(variable_name ${CMAKE_ARGV5})

file(READ "${resource_file_name}" hex_content HEX)

string(REPEAT "[0-9a-f]" 32 pattern)
string(REGEX REPLACE "(${pattern})" "\\1\n" content "${hex_content}")

string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " content "${content}")

string(REGEX REPLACE ", $" "" content "${content}")

set(array_definition "static const unsigned char ${variable_name}[] =\n{\n${content}\n};")

set(output "// Auto generated file.\n${array_definition}\n")

file(WRITE "${output_file_name}" "${output}")
Loading
Loading