|
1 | | -# CMake file for compiling the sqlite3 static library under Windows (for ease of use) |
2 | | -# |
3 | | -# Copyright (c) 2012-2025 Sebastien Rombauts (sebastien.rombauts@gmail.com) |
4 | | -# |
5 | | -# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt |
6 | | -# or copy at http://opensource.org/licenses/MIT) |
7 | | - |
8 | | -# add sources of the "sqlite3" static library |
9 | | -add_library(sqlite3 |
10 | | - sqlite3.c |
11 | | - sqlite3.h |
12 | | -) |
13 | | - |
14 | | -if (WIN32) |
15 | | - if (BUILD_SHARED_LIBS) |
16 | | - add_definitions("-DSQLITE_API=__declspec(dllexport)") |
17 | | - endif() |
18 | | -endif() |
19 | | - |
20 | | -add_library(SQLite::SQLite3 ALIAS sqlite3) |
21 | | - |
22 | | -target_include_directories(sqlite3 |
23 | | - PUBLIC |
24 | | - $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> |
25 | | - $<INSTALL_INTERFACE:include/>) |
26 | | - |
27 | | -if (SQLITE_ENABLE_COLUMN_METADATA) |
28 | | - # Enable the use of SQLite column metadata method |
29 | | - # Require that the sqlite3 library is also compiled with this flag: |
30 | | - target_compile_definitions(sqlite3 PUBLIC SQLITE_ENABLE_COLUMN_METADATA) |
31 | | -endif (SQLITE_ENABLE_COLUMN_METADATA) |
32 | | - |
33 | | -if (SQLITE_ENABLE_RTREE) |
34 | | - # Enable RTree extension when building sqlite3 |
35 | | - # See more here: https://sqlite.org/rtree.html |
36 | | - target_compile_definitions(sqlite3 PUBLIC SQLITE_ENABLE_RTREE) |
37 | | - message(STATUS "Compile sqlite3 with SQLITE_ENABLE_RTREE") |
38 | | -endif (SQLITE_ENABLE_RTREE) |
39 | | - |
40 | | -if (SQLITE_ENABLE_DBSTAT_VTAB) |
41 | | - # Enable DBSTAT extension when building sqlite3 |
42 | | - # See more here: https://www.sqlite.org/dbstat.html |
43 | | - target_compile_definitions(sqlite3 PUBLIC SQLITE_ENABLE_DBSTAT_VTAB) |
44 | | - message(STATUS "Compile sqlite3 with SQLITE_ENABLE_DBSTAT_VTAB") |
45 | | -endif (SQLITE_ENABLE_DBSTAT_VTAB) |
46 | | - |
47 | | -if (SQLITE_OMIT_LOAD_EXTENSION) |
48 | | - target_compile_definitions(sqlite3 PUBLIC SQLITE_OMIT_LOAD_EXTENSION) |
49 | | - message(STATUS "Compile sqlite3 with SQLITE_OMIT_LOAD_EXTENSION") |
50 | | -endif (SQLITE_OMIT_LOAD_EXTENSION) |
51 | | - |
52 | | -if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) |
53 | | - set_target_properties(sqlite3 PROPERTIES COMPILE_FLAGS "-fPIC") |
54 | | - |
55 | | - # Put each function in its own section to allow the linker garbage |
56 | | - # collection to remove unused section and produced a smaller |
57 | | - # statically-lined executables. |
58 | | - target_compile_options(sqlite3 PRIVATE "-ffunction-sections") |
59 | | -endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) |
60 | | - |
61 | | -if (UNIX AND CMAKE_COMPILER_IS_GNUCXX) |
62 | | - if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0) |
63 | | - target_compile_options(sqlite3 PRIVATE "-Wimplicit-fallthrough=0") |
64 | | - endif() |
65 | | - if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0) |
66 | | - target_compile_options(sqlite3 PRIVATE "-Wno-cast-function-type") |
67 | | - endif() |
68 | | -endif() |
69 | | - |
70 | | -# Allow the library to be installed via "make install" and found with "find_package" |
71 | | - |
72 | | -include(GNUInstallDirs) |
73 | | -install(TARGETS sqlite3 |
74 | | - EXPORT ${PROJECT_NAME}Targets |
75 | | - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
76 | | - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
77 | | - COMPONENT libraries) |
78 | | -install(FILES sqlite3.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers) |
| 1 | +# CMake file for compiling the sqlite3 static library under Windows (for ease of use) |
| 2 | +# |
| 3 | +# Copyright (c) 2012-2026 Sebastien Rombauts (sebastien.rombauts@gmail.com) |
| 4 | +# |
| 5 | +# Distributed under the MIT License (MIT) (See accompanying file LICENSE.txt |
| 6 | +# or copy at http://opensource.org/licenses/MIT) |
| 7 | + |
| 8 | +# add sources of the "sqlite3" static library |
| 9 | +add_library(sqlite3 |
| 10 | + sqlite3.c |
| 11 | + sqlite3.h |
| 12 | +) |
| 13 | + |
| 14 | +if (WIN32) |
| 15 | + if (BUILD_SHARED_LIBS) |
| 16 | + add_definitions("-DSQLITE_API=__declspec(dllexport)") |
| 17 | + endif() |
| 18 | +endif() |
| 19 | + |
| 20 | +add_library(SQLite::SQLite3 ALIAS sqlite3) |
| 21 | + |
| 22 | +target_include_directories(sqlite3 |
| 23 | + PUBLIC |
| 24 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}> |
| 25 | + $<INSTALL_INTERFACE:include/>) |
| 26 | + |
| 27 | +if (SQLITE_ENABLE_COLUMN_METADATA) |
| 28 | + # Enable the use of SQLite column metadata method |
| 29 | + # Require that the sqlite3 library is also compiled with this flag: |
| 30 | + target_compile_definitions(sqlite3 PUBLIC SQLITE_ENABLE_COLUMN_METADATA) |
| 31 | +endif (SQLITE_ENABLE_COLUMN_METADATA) |
| 32 | + |
| 33 | +if (SQLITE_ENABLE_RTREE) |
| 34 | + # Enable RTree extension when building sqlite3 |
| 35 | + # See more here: https://sqlite.org/rtree.html |
| 36 | + target_compile_definitions(sqlite3 PUBLIC SQLITE_ENABLE_RTREE) |
| 37 | + message(STATUS "Compile sqlite3 with SQLITE_ENABLE_RTREE") |
| 38 | +endif (SQLITE_ENABLE_RTREE) |
| 39 | + |
| 40 | +if (SQLITE_ENABLE_DBSTAT_VTAB) |
| 41 | + # Enable DBSTAT extension when building sqlite3 |
| 42 | + # See more here: https://www.sqlite.org/dbstat.html |
| 43 | + target_compile_definitions(sqlite3 PUBLIC SQLITE_ENABLE_DBSTAT_VTAB) |
| 44 | + message(STATUS "Compile sqlite3 with SQLITE_ENABLE_DBSTAT_VTAB") |
| 45 | +endif (SQLITE_ENABLE_DBSTAT_VTAB) |
| 46 | + |
| 47 | +if (SQLITE_OMIT_LOAD_EXTENSION) |
| 48 | + target_compile_definitions(sqlite3 PUBLIC SQLITE_OMIT_LOAD_EXTENSION) |
| 49 | + message(STATUS "Compile sqlite3 with SQLITE_OMIT_LOAD_EXTENSION") |
| 50 | +endif (SQLITE_OMIT_LOAD_EXTENSION) |
| 51 | + |
| 52 | +if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) |
| 53 | + set_target_properties(sqlite3 PROPERTIES COMPILE_FLAGS "-fPIC") |
| 54 | + |
| 55 | + # Put each function in its own section to allow the linker garbage |
| 56 | + # collection to remove unused section and produced a smaller |
| 57 | + # statically-lined executables. |
| 58 | + target_compile_options(sqlite3 PRIVATE "-ffunction-sections") |
| 59 | +endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) |
| 60 | + |
| 61 | +if (UNIX AND CMAKE_COMPILER_IS_GNUCXX) |
| 62 | + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 7.0) |
| 63 | + target_compile_options(sqlite3 PRIVATE "-Wimplicit-fallthrough=0") |
| 64 | + endif() |
| 65 | + if (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 8.0) |
| 66 | + target_compile_options(sqlite3 PRIVATE "-Wno-cast-function-type") |
| 67 | + endif() |
| 68 | +endif() |
| 69 | + |
| 70 | +# Allow the library to be installed via "make install" and found with "find_package" |
| 71 | + |
| 72 | +include(GNUInstallDirs) |
| 73 | +install(TARGETS sqlite3 |
| 74 | + EXPORT ${PROJECT_NAME}Targets |
| 75 | + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 76 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} |
| 77 | + COMPONENT libraries) |
| 78 | +install(FILES sqlite3.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers) |
0 commit comments