From e60c9dff03c5be90a2a2c1c8461bb18f563be426 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Sep 2025 14:38:51 +0000 Subject: [PATCH 1/3] Initial plan From 17bfbdebc6cff0cf0d404be61b34c81fae22f154 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Sep 2025 14:47:28 +0000 Subject: [PATCH 2/3] Implement hyperpage_add_archive CMake function Co-authored-by: johnpatek <31934875+johnpatek@users.noreply.github.com> --- CMakeLists.txt | 62 ++++++++++++++++++++++++++++++++++++ test_build/test_dir/test.txt | 1 + 2 files changed, 63 insertions(+) create mode 100644 test_build/test_dir/test.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 6066c32..4e140e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,68 @@ add_executable(hyperpack ${CMAKE_CURRENT_SOURCE_DIR}/hyperpack.cpp) target_include_directories(hyperpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) target_link_libraries(hyperpack PRIVATE argparse hyperpage mio::mio) +# CMake function for creating hyperpack archives +# +# Usage: hyperpage_add_archive( ) +# +# This function creates a CMake target that will run hyperpack to create +# an archive database from the specified directory during the build process. +# +# Parameters: +# name - Name of the target and output database file (without .db extension) +# directory - Directory to pack into the hyperpage database +# +# The function will: +# - Create a custom target named +# - Generate .db in CMAKE_CURRENT_BINARY_DIR +# - Add dependency on the hyperpack executable +# - Set HYPERPAGE_ARCHIVE_FILE property on the target for the output file path +# +# Example: +# hyperpage_add_archive(my_content "${CMAKE_CURRENT_SOURCE_DIR}/web_assets") +# add_dependencies(my_server my_content) # Ensure archive is built before server +# +function(hyperpage_add_archive name directory) + # Validate arguments + if(NOT name) + message(FATAL_ERROR "hyperpage_add_archive: Archive name must be specified") + endif() + + if(NOT directory) + message(FATAL_ERROR "hyperpage_add_archive: Directory must be specified") + endif() + + # Convert to absolute path for better reliability + get_filename_component(abs_directory "${directory}" ABSOLUTE) + + # Create the output database file name + set(output_file "${CMAKE_CURRENT_BINARY_DIR}/${name}.db") + + # Create a custom target for this archive + add_custom_target(${name} + DEPENDS ${output_file} + COMMENT "Building hyperpack archive: ${name}" + ) + + # Add dependency on hyperpack executable + add_dependencies(${name} hyperpack) + + # Create custom command to generate the archive + add_custom_command( + OUTPUT ${output_file} + COMMAND $ -o ${output_file} ${abs_directory} + DEPENDS hyperpack + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMENT "Creating hyperpack archive ${name} from directory: ${abs_directory}" + VERBATIM + ) + + # Set a property so consumers can find the generated file + set_target_properties(${name} PROPERTIES + HYPERPAGE_ARCHIVE_FILE "${output_file}" + ) +endfunction() + if(HYPERPAGE_TESTS) include(CTest) enable_testing() diff --git a/test_build/test_dir/test.txt b/test_build/test_dir/test.txt new file mode 100644 index 0000000..08cf610 --- /dev/null +++ b/test_build/test_dir/test.txt @@ -0,0 +1 @@ +test content \ No newline at end of file From 867aaf6c340b4728e185ebe2f85c323201105284 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 18 Sep 2025 14:49:53 +0000 Subject: [PATCH 3/3] Add usage example and clean up test artifacts Co-authored-by: johnpatek <31934875+johnpatek@users.noreply.github.com> --- example/CMakeLists.txt | 13 ++++++++++++- test_build/test_dir/test.txt | 1 - 2 files changed, 12 insertions(+), 2 deletions(-) delete mode 100644 test_build/test_dir/test.txt diff --git a/example/CMakeLists.txt b/example/CMakeLists.txt index f2dc318..72782be 100644 --- a/example/CMakeLists.txt +++ b/example/CMakeLists.txt @@ -40,10 +40,21 @@ add_custom_command( COMMENT "Building React frontend" ) +# Traditional approach using custom commands add_custom_command( TARGET server POST_BUILD COMMAND $ -o $/hyperpage.db ${CMAKE_CURRENT_SOURCE_DIR}/react-app/dist COMMENT "Building hyperpack archive from React app dist folder" ) -add_dependencies(server hyperpack) \ No newline at end of file +add_dependencies(server hyperpack) + +# Alternative approach using the new hyperpage_add_archive function: +# This would replace the above custom command and dependency: +# +# hyperpage_add_archive(react_content "${CMAKE_CURRENT_SOURCE_DIR}/react-app/dist") +# add_dependencies(server react_content) +# +# Then in the C++ code, you could access the archive at: +# get_target_property(ARCHIVE_FILE react_content HYPERPAGE_ARCHIVE_FILE) +# Or simply use: ${CMAKE_CURRENT_BINARY_DIR}/react_content.db \ No newline at end of file diff --git a/test_build/test_dir/test.txt b/test_build/test_dir/test.txt deleted file mode 100644 index 08cf610..0000000 --- a/test_build/test_dir/test.txt +++ /dev/null @@ -1 +0,0 @@ -test content \ No newline at end of file