diff --git a/CMakeLists.txt b/CMakeLists.txt index 9eeef49..435c3dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,24 @@ set(EXTENSION_NAME ${TARGET_NAME}_extension) 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) diff --git a/embed.cmake b/embed.cmake new file mode 100644 index 0000000..f60cc4d --- /dev/null +++ b/embed.cmake @@ -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}") diff --git a/src/assets/index.html b/src/assets/index.html new file mode 100644 index 0000000..c74d80c --- /dev/null +++ b/src/assets/index.html @@ -0,0 +1,808 @@ + + + + +
+ + + +"; - -#endif //PLAY_H