From fdcb45adb687a54401d21f24526c498456193662 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Sep 2025 04:18:58 +0000 Subject: [PATCH 1/7] Initial plan From c78d64bff00911fcc216e4aec9ae201d5bd32292 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Sep 2025 04:24:11 +0000 Subject: [PATCH 2/7] Initial analysis and build setup Co-authored-by: johnpatek <31934875+johnpatek@users.noreply.github.com> --- CMakeLists.txt | 13 +++++-------- tests/CMakeLists.txt | 8 ++++---- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e140e5..0b34866 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,12 +38,9 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(MegaMimes) -FetchContent_Declare( - sqlite3 - GIT_REPOSITORY https://github.com/sjinks/sqlite3-cmake.git - GIT_TAG master -) -FetchContent_MakeAvailable(sqlite3) +# Use system SQLite3 instead of fetching +find_package(PkgConfig REQUIRED) +pkg_check_modules(SQLITE3 REQUIRED sqlite3) FetchContent_Declare( argparse @@ -66,8 +63,8 @@ add_library( ) target_include_directories(hyperpage PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - ${megamimes_SOURCE_DIR}/src) -target_link_libraries(hyperpage PUBLIC SQLite::SQLite3) + ${megamimes_SOURCE_DIR}/src ${SQLITE3_INCLUDE_DIRS}) +target_link_libraries(hyperpage PUBLIC ${SQLITE3_LIBRARIES}) add_executable(hyperpack ${CMAKE_CURRENT_SOURCE_DIR}/hyperpack.cpp) target_include_directories(hyperpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6da6b86..1d6556e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,15 +30,15 @@ maxtest_add_executable( ${CMAKE_CURRENT_SOURCE_DIR}/../hyperpage.cpp ${megamimes_SOURCE_DIR}/src/MegaMimes.c) -target_include_directories(unit PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../ ${megamimes_SOURCE_DIR}/src) +target_include_directories(unit PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../ ${megamimes_SOURCE_DIR}/src ${SQLITE3_INCLUDE_DIRS}) if(HYPERPAGE_COVER) if(WIN32) message("skipping code coverage for windows") - target_link_libraries(unit PRIVATE SQLite::SQLite3) + target_link_libraries(unit PRIVATE ${SQLITE3_LIBRARIES}) else() target_compile_options(unit PRIVATE -fprofile-arcs -ftest-coverage -g -O0) - target_link_libraries(unit PRIVATE SQLite::SQLite3 gcov "--coverage") + target_link_libraries(unit PRIVATE ${SQLITE3_LIBRARIES} gcov "--coverage") add_custom_target( cover DEPENDS unit) @@ -47,7 +47,7 @@ if(HYPERPAGE_COVER) COMMAND gcovr -r ${CMAKE_CURRENT_SOURCE_DIR}/.. -e ${CMAKE_CURRENT_SOURCE_DIR}) endif() else() - target_link_libraries(unit PRIVATE SQLite::SQLite3) + target_link_libraries(unit PRIVATE ${SQLITE3_LIBRARIES}) endif() maxtest_add_test(unit store_load $) From 6753dd52f7f5a3416dae1b0d4041a20407380e7d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Sep 2025 04:34:16 +0000 Subject: [PATCH 3/7] Fix archive overwrite functionality and add comprehensive tests Co-authored-by: johnpatek <31934875+johnpatek@users.noreply.github.com> --- hyperpage.cpp | 50 +++++++++++++++++++++----- tests/CMakeLists.txt | 4 ++- tests/unit.cpp | 83 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 128 insertions(+), 9 deletions(-) diff --git a/hyperpage.cpp b/hyperpage.cpp index af43c8f..8efac0d 100644 --- a/hyperpage.cpp +++ b/hyperpage.cpp @@ -23,6 +23,7 @@ #include #include +#include extern "C" { #include @@ -39,9 +40,16 @@ static void close_handle(void *handle) sqlite3 *db = static_cast(handle); if (IsWriter) { - sqlite3_exec(db, "VACUUM;", nullptr, nullptr, nullptr); + // Ensure any pending transaction is committed + sqlite3_exec(db, "COMMIT;", nullptr, nullptr, nullptr); + // Removed VACUUM for now to see if it's causing locking issues + // sqlite3_exec(db, "VACUUM;", nullptr, nullptr, nullptr); + } + // Use sqlite3_close_v2 to finalize any remaining prepared statements + int rc = sqlite3_close_v2(db); + if (rc != SQLITE_OK) { + std::cerr << "Warning: Failed to close database properly: " << rc << std::endl; } - sqlite3_close(db); } template @@ -133,29 +141,55 @@ hyperpage::writer::writer(const std::string &db_path) : _handle(nullptr, close_h { throw std::runtime_error("Failed to open database: " + db_path); } + + // Set a busy timeout to handle locking issues + sqlite3_busy_timeout(db, 5000); // 5 second timeout + + // Set journal mode to DELETE to avoid WAL mode locking issues + sqlite3_exec(db, "PRAGMA journal_mode=DELETE;", nullptr, nullptr, nullptr); + + // Create table const std::string create_table_query = "CREATE TABLE IF NOT EXISTS hyperpage (" "path TEXT PRIMARY KEY, " "mime_type TEXT, " - "content BLOB);" - "CREATE UNIQUE INDEX IF NOT EXISTS path_index ON hyperpage (path);"; + "content BLOB);"; sqlite3_exec(db, create_table_query.c_str(), nullptr, nullptr, nullptr); + + // Create index + const std::string create_index_query = + "CREATE UNIQUE INDEX IF NOT EXISTS path_index ON hyperpage (path);"; + sqlite3_exec(db, create_index_query.c_str(), nullptr, nullptr, nullptr); + _handle.reset(db); } void hyperpage::writer::store(const hyperpage::page &page) { + std::cerr << "DEBUG: store() called for path: " << page.get_path() << std::endl; sqlite3 *db = get_handle(_handle); const std::string query = - "INSERT INTO hyperpage (path, mime_type, content) VALUES (?, ?, ?);" - "ON CONFLICT(path) DO UPDATE SET mime_type=excluded.mime_type, content=excluded.content;"; + "INSERT OR REPLACE INTO hyperpage (path, mime_type, content) VALUES (?, ?, ?);"; sqlite3_stmt *stmt = nullptr; - sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr); + int rc = sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr); + if (rc != SQLITE_OK) { + std::cerr << "Prepare failed: " << sqlite3_errmsg(db) << std::endl; + sqlite3_finalize(stmt); + return; + } + sqlite3_bind_text(stmt, 1, page.get_path().c_str(), -1, SQLITE_STATIC); sqlite3_bind_text(stmt, 2, page.get_mime_type().c_str(), -1, SQLITE_STATIC); sqlite3_bind_blob(stmt, 3, page.get_content(), static_cast(page.get_length()), SQLITE_STATIC); - sqlite3_step(stmt); + + rc = sqlite3_step(stmt); + if (rc != SQLITE_DONE) { + std::cerr << "Step failed: " << sqlite3_errmsg(db) << " (code: " << rc << ")" << std::endl; + } else { + std::cerr << "Step succeeded" << std::endl; + } + sqlite3_finalize(stmt); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1d6556e..b1fbcd1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -52,4 +52,6 @@ endif() maxtest_add_test(unit store_load $) maxtest_add_test(unit open_database $) -maxtest_add_test(unit mime_type $) \ No newline at end of file +maxtest_add_test(unit mime_type $) +maxtest_add_test(unit overwrite_test $) +maxtest_add_test(unit overwrite_cross_writer_test $) \ No newline at end of file diff --git a/tests/unit.cpp b/tests/unit.cpp index 1765979..ac97c6e 100644 --- a/tests/unit.cpp +++ b/tests/unit.cpp @@ -146,4 +146,87 @@ MAXTEST_MAIN auto file_type = hyperpage::mime_type(json_path); MAXTEST_ASSERT(file_type == json_mime_type); }; + + MAXTEST_TEST_CASE(overwrite_test) + { + std::filesystem::path db_path = std::filesystem::path(args[0]) / "hyperpage_overwrite_test.db"; + + // Remove any existing database file to start fresh + if (std::filesystem::exists(db_path)) { + std::filesystem::remove(db_path); + } + + hyperpage::writer writer(db_path.string()); + + // Create a page and store it + test_page original_page("/index.html", "text/html", "Original Content"); + writer.store(original_page); + + // Now overwrite with updated content using the same writer + test_page updated_page("/index.html", "text/html", "Updated Content"); + writer.store(updated_page); + + // Verify updated content is actually stored + hyperpage::reader reader(db_path.string()); + auto loaded_page = reader.load("/index.html"); + MAXTEST_ASSERT(loaded_page != nullptr); + MAXTEST_ASSERT(loaded_page->get_path() == "/index.html"); + MAXTEST_ASSERT(loaded_page->get_mime_type() == "text/html"); + + // Check updated content - this is where the issue should manifest + std::string updated_content = "Updated Content"; + MAXTEST_ASSERT(loaded_page->get_length() == updated_content.size()); + MAXTEST_ASSERT(match_buffers(loaded_page->get_content(), loaded_page->get_length(), + reinterpret_cast(updated_content.data()), updated_content.size())); + }; + + MAXTEST_TEST_CASE(overwrite_cross_writer_test) + { + std::filesystem::path db_path = std::filesystem::path(args[0]) / "hyperpage_cross_writer_test.db"; + + // Remove any existing database file to start fresh + if (std::filesystem::exists(db_path)) { + std::filesystem::remove(db_path); + } + + // Create a page and store it with one writer + { + hyperpage::writer writer(db_path.string()); + test_page original_page("/index.html", "text/html", "Original Content"); + writer.store(original_page); + } + + // Read the content to verify it was stored + { + hyperpage::reader reader(db_path.string()); + auto loaded_page = reader.load("/index.html"); + MAXTEST_ASSERT(loaded_page != nullptr); + std::string original_content = "Original Content"; + MAXTEST_ASSERT(loaded_page->get_length() == original_content.size()); + MAXTEST_ASSERT(match_buffers(loaded_page->get_content(), loaded_page->get_length(), + reinterpret_cast(original_content.data()), original_content.size())); + } + + // Now overwrite with updated content using a new writer + { + hyperpage::writer writer(db_path.string()); + test_page updated_page("/index.html", "text/html", "Updated Content"); + writer.store(updated_page); + } + + // Verify updated content is actually stored with a new reader + { + hyperpage::reader reader(db_path.string()); + auto loaded_page = reader.load("/index.html"); + MAXTEST_ASSERT(loaded_page != nullptr); + MAXTEST_ASSERT(loaded_page->get_path() == "/index.html"); + MAXTEST_ASSERT(loaded_page->get_mime_type() == "text/html"); + + // Check updated content - this is where the issue should manifest + std::string updated_content = "Updated Content"; + MAXTEST_ASSERT(loaded_page->get_length() == updated_content.size()); + MAXTEST_ASSERT(match_buffers(loaded_page->get_content(), loaded_page->get_length(), + reinterpret_cast(updated_content.data()), updated_content.size())); + } + }; } \ No newline at end of file From 5bb66b1ba895cc56f713a2652f1a1eeb35583313 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Sep 2025 04:38:56 +0000 Subject: [PATCH 4/7] Complete fix for archive overwrite functionality Co-authored-by: johnpatek <31934875+johnpatek@users.noreply.github.com> --- hyperpage.cpp | 33 ++++------------------------- tests/CMakeLists.txt | 3 +-- tests/unit.cpp | 50 -------------------------------------------- 3 files changed, 5 insertions(+), 81 deletions(-) diff --git a/hyperpage.cpp b/hyperpage.cpp index 8efac0d..1c31040 100644 --- a/hyperpage.cpp +++ b/hyperpage.cpp @@ -23,7 +23,6 @@ #include #include -#include extern "C" { #include @@ -40,16 +39,9 @@ static void close_handle(void *handle) sqlite3 *db = static_cast(handle); if (IsWriter) { - // Ensure any pending transaction is committed - sqlite3_exec(db, "COMMIT;", nullptr, nullptr, nullptr); - // Removed VACUUM for now to see if it's causing locking issues - // sqlite3_exec(db, "VACUUM;", nullptr, nullptr, nullptr); - } - // Use sqlite3_close_v2 to finalize any remaining prepared statements - int rc = sqlite3_close_v2(db); - if (rc != SQLITE_OK) { - std::cerr << "Warning: Failed to close database properly: " << rc << std::endl; + sqlite3_exec(db, "VACUUM;", nullptr, nullptr, nullptr); } + sqlite3_close(db); } template @@ -142,9 +134,6 @@ hyperpage::writer::writer(const std::string &db_path) : _handle(nullptr, close_h throw std::runtime_error("Failed to open database: " + db_path); } - // Set a busy timeout to handle locking issues - sqlite3_busy_timeout(db, 5000); // 5 second timeout - // Set journal mode to DELETE to avoid WAL mode locking issues sqlite3_exec(db, "PRAGMA journal_mode=DELETE;", nullptr, nullptr, nullptr); @@ -166,30 +155,16 @@ hyperpage::writer::writer(const std::string &db_path) : _handle(nullptr, close_h void hyperpage::writer::store(const hyperpage::page &page) { - std::cerr << "DEBUG: store() called for path: " << page.get_path() << std::endl; sqlite3 *db = get_handle(_handle); const std::string query = "INSERT OR REPLACE INTO hyperpage (path, mime_type, content) VALUES (?, ?, ?);"; sqlite3_stmt *stmt = nullptr; - int rc = sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr); - if (rc != SQLITE_OK) { - std::cerr << "Prepare failed: " << sqlite3_errmsg(db) << std::endl; - sqlite3_finalize(stmt); - return; - } - + sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr); sqlite3_bind_text(stmt, 1, page.get_path().c_str(), -1, SQLITE_STATIC); sqlite3_bind_text(stmt, 2, page.get_mime_type().c_str(), -1, SQLITE_STATIC); sqlite3_bind_blob(stmt, 3, page.get_content(), static_cast(page.get_length()), SQLITE_STATIC); - - rc = sqlite3_step(stmt); - if (rc != SQLITE_DONE) { - std::cerr << "Step failed: " << sqlite3_errmsg(db) << " (code: " << rc << ")" << std::endl; - } else { - std::cerr << "Step succeeded" << std::endl; - } - + sqlite3_step(stmt); sqlite3_finalize(stmt); } diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b1fbcd1..aee79eb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -53,5 +53,4 @@ endif() maxtest_add_test(unit store_load $) maxtest_add_test(unit open_database $) maxtest_add_test(unit mime_type $) -maxtest_add_test(unit overwrite_test $) -maxtest_add_test(unit overwrite_cross_writer_test $) \ No newline at end of file +maxtest_add_test(unit overwrite_test $) \ No newline at end of file diff --git a/tests/unit.cpp b/tests/unit.cpp index ac97c6e..95a0a02 100644 --- a/tests/unit.cpp +++ b/tests/unit.cpp @@ -179,54 +179,4 @@ MAXTEST_MAIN MAXTEST_ASSERT(match_buffers(loaded_page->get_content(), loaded_page->get_length(), reinterpret_cast(updated_content.data()), updated_content.size())); }; - - MAXTEST_TEST_CASE(overwrite_cross_writer_test) - { - std::filesystem::path db_path = std::filesystem::path(args[0]) / "hyperpage_cross_writer_test.db"; - - // Remove any existing database file to start fresh - if (std::filesystem::exists(db_path)) { - std::filesystem::remove(db_path); - } - - // Create a page and store it with one writer - { - hyperpage::writer writer(db_path.string()); - test_page original_page("/index.html", "text/html", "Original Content"); - writer.store(original_page); - } - - // Read the content to verify it was stored - { - hyperpage::reader reader(db_path.string()); - auto loaded_page = reader.load("/index.html"); - MAXTEST_ASSERT(loaded_page != nullptr); - std::string original_content = "Original Content"; - MAXTEST_ASSERT(loaded_page->get_length() == original_content.size()); - MAXTEST_ASSERT(match_buffers(loaded_page->get_content(), loaded_page->get_length(), - reinterpret_cast(original_content.data()), original_content.size())); - } - - // Now overwrite with updated content using a new writer - { - hyperpage::writer writer(db_path.string()); - test_page updated_page("/index.html", "text/html", "Updated Content"); - writer.store(updated_page); - } - - // Verify updated content is actually stored with a new reader - { - hyperpage::reader reader(db_path.string()); - auto loaded_page = reader.load("/index.html"); - MAXTEST_ASSERT(loaded_page != nullptr); - MAXTEST_ASSERT(loaded_page->get_path() == "/index.html"); - MAXTEST_ASSERT(loaded_page->get_mime_type() == "text/html"); - - // Check updated content - this is where the issue should manifest - std::string updated_content = "Updated Content"; - MAXTEST_ASSERT(loaded_page->get_length() == updated_content.size()); - MAXTEST_ASSERT(match_buffers(loaded_page->get_content(), loaded_page->get_length(), - reinterpret_cast(updated_content.data()), updated_content.size())); - } - }; } \ No newline at end of file From 7f7e2b8c6eb191c24ea657fd4ccfe4c8a3691cda Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Sep 2025 04:53:24 +0000 Subject: [PATCH 5/7] Fix SQL syntax spacing in multiline query while preserving ON CONFLICT behavior Co-authored-by: johnpatek <31934875+johnpatek@users.noreply.github.com> --- hyperpage.cpp | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/hyperpage.cpp b/hyperpage.cpp index 1c31040..19a8d38 100644 --- a/hyperpage.cpp +++ b/hyperpage.cpp @@ -133,23 +133,13 @@ hyperpage::writer::writer(const std::string &db_path) : _handle(nullptr, close_h { throw std::runtime_error("Failed to open database: " + db_path); } - - // Set journal mode to DELETE to avoid WAL mode locking issues - sqlite3_exec(db, "PRAGMA journal_mode=DELETE;", nullptr, nullptr, nullptr); - - // Create table const std::string create_table_query = "CREATE TABLE IF NOT EXISTS hyperpage (" "path TEXT PRIMARY KEY, " "mime_type TEXT, " - "content BLOB);"; - sqlite3_exec(db, create_table_query.c_str(), nullptr, nullptr, nullptr); - - // Create index - const std::string create_index_query = + "content BLOB);" "CREATE UNIQUE INDEX IF NOT EXISTS path_index ON hyperpage (path);"; - sqlite3_exec(db, create_index_query.c_str(), nullptr, nullptr, nullptr); - + sqlite3_exec(db, create_table_query.c_str(), nullptr, nullptr, nullptr); _handle.reset(db); } @@ -157,7 +147,8 @@ void hyperpage::writer::store(const hyperpage::page &page) { sqlite3 *db = get_handle(_handle); const std::string query = - "INSERT OR REPLACE INTO hyperpage (path, mime_type, content) VALUES (?, ?, ?);"; + "INSERT INTO hyperpage (path, mime_type, content) VALUES (?, ?, ?) " + "ON CONFLICT(path) DO UPDATE SET mime_type=excluded.mime_type, content=excluded.content;"; sqlite3_stmt *stmt = nullptr; sqlite3_prepare_v2(db, query.c_str(), -1, &stmt, nullptr); From bc158c83d1e05dc037108f89c8fb077ae553cb20 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Sep 2025 04:59:44 +0000 Subject: [PATCH 6/7] Add database size growth test to verify ON CONFLICT behavior prevents unnecessary growth Co-authored-by: johnpatek <31934875+johnpatek@users.noreply.github.com> --- tests/CMakeLists.txt | 3 ++- tests/unit.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index aee79eb..50430cb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -53,4 +53,5 @@ endif() maxtest_add_test(unit store_load $) maxtest_add_test(unit open_database $) maxtest_add_test(unit mime_type $) -maxtest_add_test(unit overwrite_test $) \ No newline at end of file +maxtest_add_test(unit overwrite_test $) +maxtest_add_test(unit archive_size_no_growth_test $) \ No newline at end of file diff --git a/tests/unit.cpp b/tests/unit.cpp index 95a0a02..13bd0c9 100644 --- a/tests/unit.cpp +++ b/tests/unit.cpp @@ -179,4 +179,47 @@ MAXTEST_MAIN MAXTEST_ASSERT(match_buffers(loaded_page->get_content(), loaded_page->get_length(), reinterpret_cast(updated_content.data()), updated_content.size())); }; + + MAXTEST_TEST_CASE(archive_size_no_growth_test) + { + std::filesystem::path db_path = std::filesystem::path(args[0]) / "hyperpage_size_test.db"; + + // Remove any existing database file to start fresh + if (std::filesystem::exists(db_path)) { + std::filesystem::remove(db_path); + } + + // Create initial content + test_page test_page_content("/test.html", "text/html", "Test Content"); + + // Store initial content and record database size + { + hyperpage::writer writer(db_path.string()); + writer.store(test_page_content); + } + + size_t initial_size = std::filesystem::file_size(db_path); + + // Overwrite with identical content multiple times + for (int i = 0; i < 5; ++i) { + hyperpage::writer writer(db_path.string()); + writer.store(test_page_content); // Same content each time + } + + size_t final_size = std::filesystem::file_size(db_path); + + // The database size should not grow significantly when overwriting with identical content + // Allow for some variance due to SQLite overhead, but it shouldn't grow substantially + MAXTEST_ASSERT(final_size <= initial_size * 1.1); // Max 10% growth tolerance + + // Verify content is still correct + hyperpage::reader reader(db_path.string()); + auto loaded_page = reader.load("/test.html"); + MAXTEST_ASSERT(loaded_page != nullptr); + MAXTEST_ASSERT(loaded_page->get_path() == "/test.html"); + std::string expected_content = "Test Content"; + MAXTEST_ASSERT(loaded_page->get_length() == expected_content.size()); + MAXTEST_ASSERT(match_buffers(loaded_page->get_content(), loaded_page->get_length(), + reinterpret_cast(expected_content.data()), expected_content.size())); + }; } \ No newline at end of file From db661c0f18e5b1584bb66141b1a5a18944821c2f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Sep 2025 05:07:22 +0000 Subject: [PATCH 7/7] Revert CMakeLists.txt to use FetchContent for SQLite3 instead of find_package Co-authored-by: johnpatek <31934875+johnpatek@users.noreply.github.com> --- CMakeLists.txt | 13 ++++++++----- tests/CMakeLists.txt | 8 ++++---- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b34866..4e140e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,9 +38,12 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(MegaMimes) -# Use system SQLite3 instead of fetching -find_package(PkgConfig REQUIRED) -pkg_check_modules(SQLITE3 REQUIRED sqlite3) +FetchContent_Declare( + sqlite3 + GIT_REPOSITORY https://github.com/sjinks/sqlite3-cmake.git + GIT_TAG master +) +FetchContent_MakeAvailable(sqlite3) FetchContent_Declare( argparse @@ -63,8 +66,8 @@ add_library( ) target_include_directories(hyperpage PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} - ${megamimes_SOURCE_DIR}/src ${SQLITE3_INCLUDE_DIRS}) -target_link_libraries(hyperpage PUBLIC ${SQLITE3_LIBRARIES}) + ${megamimes_SOURCE_DIR}/src) +target_link_libraries(hyperpage PUBLIC SQLite::SQLite3) add_executable(hyperpack ${CMAKE_CURRENT_SOURCE_DIR}/hyperpack.cpp) target_include_directories(hyperpack PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 50430cb..d6f1b38 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -30,15 +30,15 @@ maxtest_add_executable( ${CMAKE_CURRENT_SOURCE_DIR}/../hyperpage.cpp ${megamimes_SOURCE_DIR}/src/MegaMimes.c) -target_include_directories(unit PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../ ${megamimes_SOURCE_DIR}/src ${SQLITE3_INCLUDE_DIRS}) +target_include_directories(unit PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../ ${megamimes_SOURCE_DIR}/src) if(HYPERPAGE_COVER) if(WIN32) message("skipping code coverage for windows") - target_link_libraries(unit PRIVATE ${SQLITE3_LIBRARIES}) + target_link_libraries(unit PRIVATE SQLite::SQLite3) else() target_compile_options(unit PRIVATE -fprofile-arcs -ftest-coverage -g -O0) - target_link_libraries(unit PRIVATE ${SQLITE3_LIBRARIES} gcov "--coverage") + target_link_libraries(unit PRIVATE SQLite::SQLite3 gcov "--coverage") add_custom_target( cover DEPENDS unit) @@ -47,7 +47,7 @@ if(HYPERPAGE_COVER) COMMAND gcovr -r ${CMAKE_CURRENT_SOURCE_DIR}/.. -e ${CMAKE_CURRENT_SOURCE_DIR}) endif() else() - target_link_libraries(unit PRIVATE ${SQLITE3_LIBRARIES}) + target_link_libraries(unit PRIVATE SQLite::SQLite3) endif() maxtest_add_test(unit store_load $)