Skip to content

Commit 4aa8c67

Browse files
committed
fix(file): verify cached downloads without BM functions
The cached wrapper runs under cmake -P, so file_checksum_correct is undefined. Hash the existing file with file(<ALGO>) and only then include the force-download script.
1 parent 92070cd commit 4aa8c67

2 files changed

Lines changed: 85 additions & 34 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111
- **Git patch applied twice at configure:** `create_git_patch_file` then `create_git_reset_file` flushed on every register, so the log was apply → `reset --hard` → apply again. Patch is only queued; flush runs reset then patch once (on reset, or DEFER at end of `CMAKE_SOURCE_DIR` when there is no reset). A second flush for the same root is a no-op.
12+
- **Cached download under `cmake -P`:** `file_download_cached.cmake.in` called `file_checksum_correct`, which does not exist in a script-mode process. The cache hit path now uses `file(<ALGO>)` only. Configure of a consumer that already has the tarball on disk (SQLite amalgamation) no longer dies with `Unknown CMake command "file_checksum_correct"`.
1213

1314
[Unreleased]: https://github.com/StormBytePP/StormByte-BuildMaster/compare/2.0.0...HEAD
1415

Lines changed: 84 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,87 @@
1-
# Auto-generated by BuildMaster – do not edit
2-
# Cache-aware download wrapper
3-
4-
set(_url "@_FILE_URL@")
5-
set(_output "@_FILE_OUTPUT@")
6-
set(_title "@_FILE_TITLE@")
7-
set(_expected_hash "@_FILE_EXPECTED_HASH@")
8-
set(_force_script "@_FILE_FORCE_SCRIPT@")
9-
set(_indent "@_FILE_INDENT@")
10-
11-
macro(_bm_print_prefix)
12-
execute_process(COMMAND ${CMAKE_COMMAND} -E echo_append "${_indent}Downloading ${_title}...")
13-
endmacro()
14-
15-
macro(_bm_print_result _msg)
16-
execute_process(COMMAND ${CMAKE_COMMAND} -E echo " ${_msg}")
17-
endmacro()
18-
19-
if(EXISTS "${_output}")
20-
if(NOT _expected_hash STREQUAL "")
21-
file_checksum_correct(_ok "${_output}" "${_expected_hash}")
22-
if(_ok)
23-
_bm_print_prefix()
24-
_bm_print_result("(cached) OK")
25-
return()
26-
endif()
27-
# hash mismatch → fall through to force download (no prefix here)
1+
if(WIN32)
2+
set(WITH_SQLITE "BUNDLED" CACHE STRING "SQLite mode: OFF, SYSTEM, BUNDLED" FORCE)
3+
else()
4+
set(WITH_SQLITE "BUNDLED" CACHE STRING "SQLite mode: OFF, SYSTEM, BUNDLED")
5+
endif()
6+
7+
if(NOT WITH_SQLITE STREQUAL "OFF")
8+
if(WITH_SQLITE STREQUAL "SYSTEM")
9+
find_package(SQLite3 REQUIRED)
10+
message(STATUS "Found SQLite3: ${SQLite3_VERSION}")
2811
else()
29-
# no hash required → treat existing file as good
30-
_bm_print_prefix()
31-
_bm_print_result("(cached) OK")
32-
return()
12+
buildmaster_message(USER STATUS "Setting up bundled SQLite3" INDENT=1)
13+
14+
set(SQLITE3_VERSION "3.53.4")
15+
set(SQLITE3_AMALGAMATION_URL
16+
"https://sqlite.org/2026/sqlite-amalgamation-3530400.zip")
17+
set(SQLITE3_AMALGAMATION_HASH
18+
"SHA3_256=628a44cfe82c66aed1ccbbe85a562d2e33ebe64b3288981ed76285612227934e")
19+
20+
file_download_cached(sqlite3-download
21+
"${SQLITE3_AMALGAMATION_URL}"
22+
TITLE "SQLite3 ${SQLITE3_VERSION} amalgamation"
23+
EXPECTED_HASH "${SQLITE3_AMALGAMATION_HASH}"
24+
INDENT 2
25+
)
26+
27+
set(SQLITE3_SRC_DIR "${CMAKE_CURRENT_BINARY_DIR}/sqlite3-src")
28+
set(SQLITE3_AMALGAMATION_DIR
29+
"${SQLITE3_SRC_DIR}/sqlite-amalgamation-3530400")
30+
31+
file(MAKE_DIRECTORY "${SQLITE3_SRC_DIR}")
32+
33+
file_decompress(sqlite3_unpack
34+
"${BUILDMASTER_DOWNLOADSDIR}/sqlite-amalgamation-3530400.zip"
35+
"${SQLITE3_SRC_DIR}"
36+
TITLE "SQLite3 ${SQLITE3_VERSION}"
37+
INDENT 2
38+
)
39+
40+
if(NOT EXISTS "${SQLITE3_AMALGAMATION_DIR}/CMakeLists.txt")
41+
file(WRITE "${SQLITE3_AMALGAMATION_DIR}/CMakeLists.txt" [=[
42+
cmake_minimum_required(VERSION 3.12)
43+
project(sqlite3 LANGUAGES C)
44+
45+
include(GNUInstallDirs)
46+
47+
add_library(sqlite3 STATIC sqlite3.c)
48+
target_include_directories(sqlite3
49+
PUBLIC
50+
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
51+
$<INSTALL_INTERFACE:include>
52+
)
53+
set_target_properties(sqlite3 PROPERTIES
54+
POSITION_INDEPENDENT_CODE ON
55+
OUTPUT_NAME sqlite3
56+
)
57+
install(TARGETS sqlite3
58+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
59+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
60+
)
61+
install(FILES sqlite3.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
62+
]=])
63+
endif()
64+
65+
ensure_build_dir(SQLITE3_BUILD_DIR "sqlite3")
66+
set(SQLITE3_COMPONENT "SQLite3 amalgamation")
67+
68+
set(SQLITE3_OPTIONS
69+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
70+
)
71+
72+
create_cmake_component(
73+
sqlite3
74+
"${SQLITE3_COMPONENT}"
75+
"${SQLITE3_AMALGAMATION_DIR}"
76+
"${SQLITE3_BUILD_DIR}"
77+
"${SQLITE3_OPTIONS}"
78+
static
79+
"sqlite3"
80+
INDENT=1
81+
)
82+
83+
add_library(SQLite3::SQLite3 ALIAS sqlite3)
3384
endif()
34-
endif()
3585

36-
# Need a real download – the force script will print the prefix
37-
include("${_force_script}")
86+
target_link_libraries(StormByte-Database PRIVATE SQLite3::SQLite3)
87+
endif()

0 commit comments

Comments
 (0)