Skip to content

Commit 0632da8

Browse files
committed
Download SQLite
1 parent 480e9d8 commit 0632da8

File tree

8 files changed

+150
-31
lines changed

8 files changed

+150
-31
lines changed

.github/workflows/ci.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ jobs:
5858
build-essential \
5959
libssl-dev \
6060
libpcre2-dev \
61-
libsqlite3-dev \
6261
libbz2-dev \
6362
libcurl4-openssl-dev \
6463
libdb5.3++-dev \

cmake/cmake/Configuration.cmake

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,6 @@ endblock()
199199
# Minimum required version for the OpenSSL dependency.
200200
set(PHP_OPENSSL_MIN_VERSION 1.0.2)
201201

202-
# Minimum required version for the SQLite dependency.
203-
set(PHP_SQLITE_MIN_VERSION 3.7.7)
204-
205202
# Minimum required version for the PostgreSQL dependency.
206203
set(PHP_POSTGRESQL_MIN_VERSION 9.1)
207204

@@ -241,13 +238,6 @@ set_package_properties(
241238
DESCRIPTION "PostgreSQL database library"
242239
)
243240

244-
set_package_properties(
245-
SQLite3
246-
PROPERTIES
247-
URL "https://www.sqlite.org/"
248-
DESCRIPTION "SQL database engine library"
249-
)
250-
251241
# Set base directory for ExternalProject CMake module.
252242
set_directory_properties(
253243
PROPERTIES EP_BASE ${PHP_BINARY_DIR}/CMakeFiles/PHP/ExternalProject
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#[=============================================================================[
2+
# PHP/Package/SQLite3
3+
4+
Finds or downloads the SQLite library:
5+
6+
```cmake
7+
include(PHP/Package/SQLite3)
8+
```
9+
10+
This module is a wrapper for finding the `SQLite` library. It first tries to
11+
find the `SQLite` library on the system. If not successful it tries to download
12+
it from the upstream source and builds it together with the PHP build.
13+
14+
See: https://cmake.org/cmake/help/latest/module/FindSQLite3.html
15+
16+
## Examples
17+
18+
Basic usage:
19+
20+
```cmake
21+
include(PHP/Package/SQLite3)
22+
php_package_sqlite3_find()
23+
target_link_libraries(php_ext_foo PRIVATE SQLite::SQLite3)
24+
```
25+
#]=============================================================================]
26+
27+
include(ExternalProject)
28+
include(FeatureSummary)
29+
include(FetchContent)
30+
31+
set_package_properties(
32+
SQLite3
33+
PROPERTIES
34+
URL "https://www.sqlite.org/"
35+
DESCRIPTION "SQL database engine library"
36+
)
37+
38+
# Minimum required version for the SQLite dependency.
39+
set(PHP_SQLITE3_MIN_VERSION 3.7.7)
40+
41+
# Download version when system dependency is not found.
42+
set(PHP_SQLITE3_DOWNLOAD_VERSION 3.50.2)
43+
44+
macro(php_package_sqlite3_find)
45+
if(TARGET SQLite::SQLite3)
46+
set(SQLite3_FOUND TRUE)
47+
get_property(SQLite3_DOWNLOADED GLOBAL PROPERTY _PHP_SQLite3_DOWNLOADED)
48+
else()
49+
find_package(SQLite3 ${PHP_SQLITE3_MIN_VERSION})
50+
51+
if(NOT SQLite3_FOUND)
52+
_php_package_sqlite3_download()
53+
endif()
54+
endif()
55+
endmacro()
56+
57+
macro(_php_package_sqlite3_download)
58+
message(STATUS "Downloading SQLite ${PHP_SQLITE3_DOWNLOAD_VERSION}")
59+
60+
FetchContent_Declare(
61+
SQLite3
62+
URL https://github.com/sjinks/sqlite3-cmake/archive/refs/tags/v${PHP_SQLITE3_DOWNLOAD_VERSION}.tar.gz
63+
SOURCE_SUBDIR non-existing
64+
OVERRIDE_FIND_PACKAGE
65+
)
66+
67+
FetchContent_MakeAvailable(SQLite3)
68+
69+
set(options "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>")
70+
71+
ExternalProject_Add(
72+
SQLite3
73+
STEP_TARGETS build install
74+
SOURCE_DIR ${sqlite3_SOURCE_DIR}
75+
BINARY_DIR ${sqlite3_BINARY_DIR}
76+
CMAKE_ARGS ${options}
77+
INSTALL_DIR ${FETCHCONTENT_BASE_DIR}/sqlite3-install
78+
INSTALL_BYPRODUCTS <INSTALL_DIR>/lib/libsqlite3${CMAKE_STATIC_LIBRARY_SUFFIX}
79+
)
80+
81+
ExternalProject_Get_Property(SQLite3 INSTALL_DIR)
82+
83+
# Bypass missing directory error for the imported target below.
84+
file(MAKE_DIRECTORY ${INSTALL_DIR}/include)
85+
86+
add_library(SQLite::SQLite3 STATIC IMPORTED GLOBAL)
87+
add_dependencies(SQLite::SQLite3 SQLite3-install)
88+
set_target_properties(
89+
SQLite::SQLite3
90+
PROPERTIES
91+
INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include
92+
IMPORTED_LOCATION ${INSTALL_DIR}/lib/libsqlite3${CMAKE_STATIC_LIBRARY_SUFFIX}
93+
)
94+
95+
# Move dependency to PACKAGES_FOUND.
96+
block()
97+
set(package "SQLite3")
98+
get_property(packagesNotFound GLOBAL PROPERTY PACKAGES_NOT_FOUND)
99+
list(REMOVE_ITEM packagesNotFound ${package})
100+
set_property(GLOBAL PROPERTY PACKAGES_NOT_FOUND ${packagesNotFound})
101+
get_property(packagesFound GLOBAL PROPERTY PACKAGES_FOUND)
102+
list(FIND packagesFound ${package} found)
103+
if(found EQUAL -1)
104+
set_property(GLOBAL APPEND PROPERTY PACKAGES_FOUND ${package})
105+
endif()
106+
endblock()
107+
108+
# Mark package as found.
109+
set(SQLite3_FOUND TRUE)
110+
111+
define_property(
112+
GLOBAL
113+
PROPERTY _PHP_SQLite3_DOWNLOADED
114+
BRIEF_DOCS "Marker that SQLite3 library will be downloaded"
115+
)
116+
117+
set_property(GLOBAL PROPERTY _PHP_SQLite3_DOWNLOADED TRUE)
118+
set(SQLite3_DOWNLOADED TRUE)
119+
endmacro()
120+
121+
php_package_sqlite3_find()

cmake/cmake/modules/PHP/Package/ZLIB.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ set_package_properties(
3737

3838
# Minimum required version for the zlib dependency.
3939
set(PHP_ZLIB_MIN_VERSION 1.2.0.4)
40-
set(PHP_ZLIB_MIN_VERSION 1.3.1)
4140

4241
# Download version when system dependency is not found.
4342
set(PHP_ZLIB_DOWNLOAD_VERSION 1.3.1)

cmake/cmake/modules/PHP/Package/libzip.cmake

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,38 @@ include(FeatureSummary)
2626
include(FetchContent)
2727

2828
# Minimum required version for the libzip dependency.
29+
# Also accepted libzip version ranges are from 0.11-1.7 with 1.3.1 and 1.7.0
30+
# excluded due to upstream bugs.
2931
set(PHP_libzip_MIN_VERSION 1.7.1)
3032

3133
# Download version when system dependency is not found.
3234
set(PHP_libzip_DOWNLOAD_VERSION 1.11.4)
3335

34-
3536
macro(php_package_libzip_find)
3637
if(TARGET libzip::libzip)
3738
set(libzip_FOUND TRUE)
3839
get_property(libzip_DOWNLOADED GLOBAL PROPERTY _PHP_libzip_DOWNLOADED)
40+
get_property(libzip_VERSION GLOBAL PROPERTY _PHP_libzip_VERSION)
3941
else()
4042
# libzip depends on ZLIB
4143
include(PHP/Package/ZLIB)
4244

4345
find_package(libzip ${PHP_libzip_MIN_VERSION})
4446

47+
if(NOT libzip_FOUND)
48+
find_package(libzip 1.3.2...1.6.999)
49+
endif()
50+
51+
if(NOT libzip_FOUND)
52+
find_package(libzip 0.11...1.3.0)
53+
endif()
54+
4555
if(NOT libzip_FOUND)
4656
_php_package_libzip_download()
57+
else()
58+
set_property(
59+
GLOBAL PROPERTY _PHP_libzip_VERSION ${libzip_VERSION}
60+
)
4761
endif()
4862
endif()
4963
endmacro()
@@ -61,6 +75,7 @@ macro(_php_package_libzip_download)
6175
FetchContent_MakeAvailable(libzip)
6276

6377
set(options "-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>")
78+
list(APPEND options -DBUILD_SHARED_LIBS=OFF)
6479

6580
if(ZLIB_DOWNLOADED)
6681
ExternalProject_Get_Property(ZLIB INSTALL_DIR)
@@ -117,6 +132,15 @@ macro(_php_package_libzip_download)
117132

118133
set_property(GLOBAL PROPERTY _PHP_libzip_DOWNLOADED TRUE)
119134
set(libzip_DOWNLOADED TRUE)
135+
136+
set_property(
137+
GLOBAL PROPERTY _PHP_libzip_VERSION ${PHP_libzip_DOWNLOAD_VERSION}
138+
)
139+
set(libzip_VERSION ${PHP_libzip_DOWNLOAD_VERSION})
140+
endmacro()
141+
142+
macro(_php_package_libzip_set_vars)
143+
120144
endmacro()
121145

122146
php_package_libzip_find()

cmake/ext/pdo_sqlite/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ target_include_directories(
7575
${CMAKE_CURRENT_SOURCE_DIR}/..
7676
)
7777

78-
find_package(SQLite3 ${PHP_SQLITE_MIN_VERSION})
78+
include(PHP/Package/SQLite3)
7979
set_package_properties(
8080
SQLite3
8181
PROPERTIES

cmake/ext/sqlite3/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ target_sources(
6767

6868
target_compile_definitions(php_ext_sqlite3 PRIVATE ZEND_ENABLE_STATIC_TSRMLS_CACHE)
6969

70-
find_package(SQLite3 ${PHP_SQLITE_MIN_VERSION})
70+
include(PHP/Package/SQLite3)
7171
set_package_properties(
7272
SQLite3
7373
PROPERTIES

cmake/ext/zip/CMakeLists.txt

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,8 @@ set_package_properties(
7676
PURPOSE "Necessary to enable the zip extension."
7777
)
7878

79-
if(NOT libzip_FOUND)
80-
find_package(libzip 1.3.2...1.6.999)
81-
endif()
82-
83-
if(NOT libzip_FOUND)
84-
find_package(libzip 0.11...1.3.0)
85-
endif()
86-
87-
if(libzip_VERSION VERSION_EQUAL 1.3.1 OR libzip_VERSION VERSION_EQUAL 1.7.0)
88-
message(
89-
FATAL_ERROR
90-
"ext/zip: libzip ${libzip_VERSION} is not supported. Try upgrading libzip."
91-
)
92-
endif()
93-
94-
target_link_libraries(php_ext_zip PRIVATE libzip::libzip)
79+
# Link publicly for internal_functions files.
80+
target_link_libraries(php_ext_zip PUBLIC libzip::libzip)
9581

9682
# Note: ZIP_STATIC needs to be defined when using static libzip on Windows only
9783
# since version 1.0 to 1.3.2

0 commit comments

Comments
 (0)