From 598300511a5d103d27d4163984dd536fc1acc155 Mon Sep 17 00:00:00 2001 From: Toyosatomimi no Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Thu, 29 May 2025 01:48:53 -0400 Subject: [PATCH 1/6] Add support for C++ modules --- CMakeLists.txt | 14 ++++++++++++ README.md | 2 ++ docs/README.md | 2 ++ src/modules/CMakeLists.txt | 30 ++++++++++++++++++++++++++ src/modules/Column.cppm | 28 ++++++++++++++++++++++++ src/modules/Database.cppm | 38 +++++++++++++++++++++++++++++++++ src/modules/Exception.cppm | 20 +++++++++++++++++ src/modules/SQLiteCpp.cppm | 12 +++++++++++ src/modules/Statement.cppm | 23 ++++++++++++++++++++ src/modules/Transaction.cppm | 23 ++++++++++++++++++++ src/modules/sqlite3forward.cppm | 35 ++++++++++++++++++++++++++++++ 11 files changed, 227 insertions(+) create mode 100644 src/modules/CMakeLists.txt create mode 100644 src/modules/Column.cppm create mode 100644 src/modules/Database.cppm create mode 100644 src/modules/Exception.cppm create mode 100644 src/modules/SQLiteCpp.cppm create mode 100644 src/modules/Statement.cppm create mode 100644 src/modules/Transaction.cppm create mode 100644 src/modules/sqlite3forward.cppm diff --git a/CMakeLists.txt b/CMakeLists.txt index ab2034db..9d30f696 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -153,6 +153,20 @@ set(SQLITECPP_INC ) source_group(include FILES ${SQLITECPP_INC}) +# modules +option(SQLITECPP_BUILD_MODULES "Build C++ modules support" OFF) + +if(SQLITECPP_BUILD_MODULES) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) + message(STATUS "Building SQLiteCpp C++ modules (CMake ${CMAKE_VERSION} supports modules)") + add_subdirectory(src/modules) + else() + message(WARNING "Skipping SQLiteCpp C++ modules (requires CMake 3.28+, found ${CMAKE_VERSION})") + endif() +else() + message(STATUS "SQLiteCpp C++ modules support is disabled. Enable with -NLOHMANN_JSON_BUILD_MODULES=ON") +endif() + # list of test files of the library set(SQLITECPP_TESTS tests/Column_test.cpp diff --git a/README.md b/README.md index b66fc912..2548b9a5 100644 --- a/README.md +++ b/README.md @@ -192,6 +192,8 @@ cmake --build . ctest --output-on-failure ``` +To enable building with C++20 modules (and importing the library with `import sqlitecpp;`), pass `SQLITECPP_BUILD_MODULES` to the build system. + #### Building with meson You can build SQLiteCpp with [meson](https://mesonbuild.com/) using the provided meson project. diff --git a/docs/README.md b/docs/README.md index 9bf9f0b3..18991fea 100644 --- a/docs/README.md +++ b/docs/README.md @@ -193,6 +193,8 @@ cmake --build . ctest --output-on-failure ``` +To enable building with C++20 modules (and importing the library with `import sqlitecpp;`), pass `SQLITECPP_BUILD_MODULES` to the build system. + #### CMake options * For more options on customizing the build, see the [CMakeLists.txt](https://github.com/SRombauts/SQLiteCpp/blob/master/CMakeLists.txt) file. diff --git a/src/modules/CMakeLists.txt b/src/modules/CMakeLists.txt new file mode 100644 index 00000000..b87e9089 --- /dev/null +++ b/src/modules/CMakeLists.txt @@ -0,0 +1,30 @@ +file(GLOB_RECURSE SQLITECPP_MODULES *.cppm) + +add_library(sqlitecpp_modules) + +cmake_minimum_required(VERSION 3.28) + +if(NOT COMMAND configure_cpp_module_target) + function(configure_cpp_module_target target) + if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.28) + target_sources(${target} PUBLIC FILE_SET CXX_MODULES FILES ${SQLITECPP_MODULES}) + else() + message(WARNING "C++ modules require CMake 3.28+. Using standard compilation.") + target_sources(${target} PRIVATE ${SQLITECPP_MODULES}) + endif() + endfunction() +endif() + +configure_cpp_module_target(sqlitecpp_modules) + +target_link_libraries(sqlitecpp_modules + PUBLIC + sqlitecpp +) + +target_include_directories(sqlitecpp_modules + PRIVATE + ${PROJECT_SOURCE_DIR}/include +) + +target_compile_features(sqlitecpp_modules PUBLIC cxx_std_20) \ No newline at end of file diff --git a/src/modules/Column.cppm b/src/modules/Column.cppm new file mode 100644 index 00000000..c0b6e500 --- /dev/null +++ b/src/modules/Column.cppm @@ -0,0 +1,28 @@ +/** + * @file Column.cppm + * @brief Module file for SQLiteCpp Column class. + */ + +module; + +#include + +export module sqlitecpp.column; + +import sqlitecpp.sqlite3forward; + +/** + * @namespace sqlite + * @brief The SQLite SQLite:: namespace + */ +export namespace SQLite { + using SQLite::INTEGER; + using SQLite::FLOAT; + using SQLite::TEXT; + using SQLite::BLOB; + using SQLite::Null; + + using SQLite::Column; + + using SQLite::operator<<; +} diff --git a/src/modules/Database.cppm b/src/modules/Database.cppm new file mode 100644 index 00000000..fd2dc522 --- /dev/null +++ b/src/modules/Database.cppm @@ -0,0 +1,38 @@ +/** + * @file Exception.cppm + * @brief Module file for SQLiteCpp Exception class. + */ + +module; + +#include + +export module sqlitecpp.database; + +import sqlitecpp.sqlite3forward; + +/** + * @namespace sqlite + * @brief The SQLite SQLite:: namespace + */ +export namespace SQLite { + using SQLite::OPEN_READONLY; + using SQLite::OPEN_READWRITE; + using SQLite::OPEN_CREATE; + using SQLite::OPEN_URI; + using SQLite::OPEN_MEMORY; + using SQLite::OPEN_NOMUTEX; + using SQLite::OPEN_FULLMUTEX; + using SQLite::OPEN_SHAREDCACHE; + using SQLite::OPEN_PRIVATECACHE; + using SQLite::OPEN_NOFOLLOW; + using SQLite::OK; + using SQLite::VERSION; + using SQLite::VERSION_NUMBER; + + using SQLite::getLibVersion; + using SQLite::getLibVersionNumber; + + using SQLite::Header; + using SQLite::Database; +} diff --git a/src/modules/Exception.cppm b/src/modules/Exception.cppm new file mode 100644 index 00000000..e6371f60 --- /dev/null +++ b/src/modules/Exception.cppm @@ -0,0 +1,20 @@ +/** + * @file Exception.cppm + * @brief Module file for SQLiteCpp Exception class. + */ + +module; + +#include + +export module sqlitecpp.exception; + +import sqlitecpp.sqlite3forward; + +/** + * @namespace sqlite + * @brief The SQLite SQLite:: namespace + */ +export namespace SQLite { + using SQLite::Exception; +} diff --git a/src/modules/SQLiteCpp.cppm b/src/modules/SQLiteCpp.cppm new file mode 100644 index 00000000..14c94067 --- /dev/null +++ b/src/modules/SQLiteCpp.cppm @@ -0,0 +1,12 @@ +/** + * @file SQLiteCpp.cppm + * @brief File containing the module declaration for SQLiteC++. + */ + +export module sqlitecpp; + +export import sqlitecpp.column; +export import sqlitecpp.database; +export import sqlitecpp.exception; +export import sqlitecpp.statement; +export import sqlitecpp.transaction; diff --git a/src/modules/Statement.cppm b/src/modules/Statement.cppm new file mode 100644 index 00000000..b941c2f4 --- /dev/null +++ b/src/modules/Statement.cppm @@ -0,0 +1,23 @@ +/** + * @file Statement.cppm + * @brief Module file for SQLiteCpp Statement class. + */ + +module; + +#include + +export module sqlitecpp.statement; + +export import sqlitecpp.column; +export import sqlitecpp.database; + +import sqlitecpp.sqlite3forward; + +/** + * @namespace sqlite + * @brief The SQLite SQLite:: namespace + */ +export namespace SQLite { + using SQLite::Statement; +} diff --git a/src/modules/Transaction.cppm b/src/modules/Transaction.cppm new file mode 100644 index 00000000..9b0e8195 --- /dev/null +++ b/src/modules/Transaction.cppm @@ -0,0 +1,23 @@ +/** + * @file Transaction.cppm + * @brief Module file for SQLiteCpp Transaction class. + */ + +module; + +#include + +export module sqlitecpp.transaction; + +export import sqlitecpp.database; + +import sqlitecpp.sqlite3forward; + +/** + * @namespace sqlite + * @brief The SQLite SQLite:: namespace + */ +export namespace SQLite { + using SQLite::TransactionBehavior; + using SQLite::Transaction; +} diff --git a/src/modules/sqlite3forward.cppm b/src/modules/sqlite3forward.cppm new file mode 100644 index 00000000..df5eee43 --- /dev/null +++ b/src/modules/sqlite3forward.cppm @@ -0,0 +1,35 @@ +/** + * @file sqlite3forward.cppm + * @brief Module file containing forward declarations of sqlite3 structs. + */ + +module; + +#include + +export module sqlitecpp.sqlite3forward; + +/** + * @namespace sqlite + * @brief The SQLite SQLite:: namespace + */ +export namespace SQLite { + using ::sqlite3; + using ::sqlite3_context; + using ::sqlite3_stmt; + using ::sqlite3_value; + + using ::sqlite3_open; + using ::sqlite3_close; + using ::sqlite3_prepare_v2; + using ::sqlite3_step; + using ::sqlite3_finalize; + using ::sqlite3_bind_text; + using ::sqlite3_bind_int; + using ::sqlite3_bind_double; + using ::sqlite3_column_text; + using ::sqlite3_column_int; + using ::sqlite3_column_double; + using ::sqlite3_errmsg; + using ::sqlite3_errcode; +} From 1e26b6020c8ebead3fd39f8a0e27f45d94a0b601 Mon Sep 17 00:00:00 2001 From: Toyosatomimi no Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Thu, 29 May 2025 01:54:46 -0400 Subject: [PATCH 2/6] Fix namespace doxygen comment --- src/modules/Column.cppm | 2 +- src/modules/Database.cppm | 2 +- src/modules/Exception.cppm | 2 +- src/modules/Statement.cppm | 2 +- src/modules/Transaction.cppm | 2 +- src/modules/sqlite3forward.cppm | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/Column.cppm b/src/modules/Column.cppm index c0b6e500..00667794 100644 --- a/src/modules/Column.cppm +++ b/src/modules/Column.cppm @@ -12,7 +12,7 @@ export module sqlitecpp.column; import sqlitecpp.sqlite3forward; /** - * @namespace sqlite + * @namespace SQLite * @brief The SQLite SQLite:: namespace */ export namespace SQLite { diff --git a/src/modules/Database.cppm b/src/modules/Database.cppm index fd2dc522..0ce67d1e 100644 --- a/src/modules/Database.cppm +++ b/src/modules/Database.cppm @@ -12,7 +12,7 @@ export module sqlitecpp.database; import sqlitecpp.sqlite3forward; /** - * @namespace sqlite + * @namespace SQLite * @brief The SQLite SQLite:: namespace */ export namespace SQLite { diff --git a/src/modules/Exception.cppm b/src/modules/Exception.cppm index e6371f60..339f6b3e 100644 --- a/src/modules/Exception.cppm +++ b/src/modules/Exception.cppm @@ -12,7 +12,7 @@ export module sqlitecpp.exception; import sqlitecpp.sqlite3forward; /** - * @namespace sqlite + * @namespace SQLite * @brief The SQLite SQLite:: namespace */ export namespace SQLite { diff --git a/src/modules/Statement.cppm b/src/modules/Statement.cppm index b941c2f4..53f19c56 100644 --- a/src/modules/Statement.cppm +++ b/src/modules/Statement.cppm @@ -15,7 +15,7 @@ export import sqlitecpp.database; import sqlitecpp.sqlite3forward; /** - * @namespace sqlite + * @namespace SQLite * @brief The SQLite SQLite:: namespace */ export namespace SQLite { diff --git a/src/modules/Transaction.cppm b/src/modules/Transaction.cppm index 9b0e8195..1af1d675 100644 --- a/src/modules/Transaction.cppm +++ b/src/modules/Transaction.cppm @@ -14,7 +14,7 @@ export import sqlitecpp.database; import sqlitecpp.sqlite3forward; /** - * @namespace sqlite + * @namespace SQLite * @brief The SQLite SQLite:: namespace */ export namespace SQLite { diff --git a/src/modules/sqlite3forward.cppm b/src/modules/sqlite3forward.cppm index df5eee43..d4ac06af 100644 --- a/src/modules/sqlite3forward.cppm +++ b/src/modules/sqlite3forward.cppm @@ -10,7 +10,7 @@ module; export module sqlitecpp.sqlite3forward; /** - * @namespace sqlite + * @namespace SQLite * @brief The SQLite SQLite:: namespace */ export namespace SQLite { From 9b722f1790a221265b8bf042a5168bd166747bf1 Mon Sep 17 00:00:00 2001 From: Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Thu, 29 May 2025 16:19:25 +0000 Subject: [PATCH 3/6] Forgot to use `SQLITECPP_BUILD_MODULES` in CMakeLists --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d30f696..2b51704f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,7 +164,7 @@ if(SQLITECPP_BUILD_MODULES) message(WARNING "Skipping SQLiteCpp C++ modules (requires CMake 3.28+, found ${CMAKE_VERSION})") endif() else() - message(STATUS "SQLiteCpp C++ modules support is disabled. Enable with -NLOHMANN_JSON_BUILD_MODULES=ON") + message(STATUS "SQLiteCpp C++ modules support is disabled. Enable with -SQLITECPP_BUILD_MODULES=ON") endif() # list of test files of the library From 67688603e4b3ed7b74d7f283bd38f5b2d136bddf Mon Sep 17 00:00:00 2001 From: Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Thu, 29 May 2025 16:48:27 +0000 Subject: [PATCH 4/6] Should have D in front of it --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b51704f..2f444359 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -164,7 +164,7 @@ if(SQLITECPP_BUILD_MODULES) message(WARNING "Skipping SQLiteCpp C++ modules (requires CMake 3.28+, found ${CMAKE_VERSION})") endif() else() - message(STATUS "SQLiteCpp C++ modules support is disabled. Enable with -SQLITECPP_BUILD_MODULES=ON") + message(STATUS "SQLiteCpp C++ modules support is disabled. Enable with -DSQLITECPP_BUILD_MODULES=ON") endif() # list of test files of the library From ab42af8e345af65bc11697ba4e55eb7d1f8c33f5 Mon Sep 17 00:00:00 2001 From: Toyosatomimi no Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Sat, 31 May 2025 02:28:20 -0400 Subject: [PATCH 5/6] Rename sqlitecpp -> sqlite and alias namespace to match --- src/modules/Column.cppm | 6 ++++-- src/modules/Database.cppm | 6 ++++-- src/modules/Exception.cppm | 6 ++++-- src/modules/SQLiteCpp.cppm | 12 ++++++------ src/modules/Statement.cppm | 10 ++++++---- src/modules/Transaction.cppm | 8 +++++--- src/modules/sqlite3forward.cppm | 2 +- 7 files changed, 30 insertions(+), 20 deletions(-) diff --git a/src/modules/Column.cppm b/src/modules/Column.cppm index 00667794..05edfb2e 100644 --- a/src/modules/Column.cppm +++ b/src/modules/Column.cppm @@ -7,9 +7,9 @@ module; #include -export module sqlitecpp.column; +export module sqlite.column; -import sqlitecpp.sqlite3forward; +import sqlite.sqlite3forward; /** * @namespace SQLite @@ -26,3 +26,5 @@ export namespace SQLite { using SQLite::operator<<; } + +export namespace sqlite = SQLite; diff --git a/src/modules/Database.cppm b/src/modules/Database.cppm index 0ce67d1e..366fb5cb 100644 --- a/src/modules/Database.cppm +++ b/src/modules/Database.cppm @@ -7,9 +7,9 @@ module; #include -export module sqlitecpp.database; +export module sqlite.database; -import sqlitecpp.sqlite3forward; +import sqlite.sqlite3forward; /** * @namespace SQLite @@ -36,3 +36,5 @@ export namespace SQLite { using SQLite::Header; using SQLite::Database; } + +export namespace sqlite = SQLite; diff --git a/src/modules/Exception.cppm b/src/modules/Exception.cppm index 339f6b3e..d6dfa557 100644 --- a/src/modules/Exception.cppm +++ b/src/modules/Exception.cppm @@ -7,9 +7,9 @@ module; #include -export module sqlitecpp.exception; +export module sqlite.exception; -import sqlitecpp.sqlite3forward; +import sqlite.sqlite3forward; /** * @namespace SQLite @@ -18,3 +18,5 @@ import sqlitecpp.sqlite3forward; export namespace SQLite { using SQLite::Exception; } + +export namespace sqlite = SQLite; diff --git a/src/modules/SQLiteCpp.cppm b/src/modules/SQLiteCpp.cppm index 14c94067..ce0e42cb 100644 --- a/src/modules/SQLiteCpp.cppm +++ b/src/modules/SQLiteCpp.cppm @@ -3,10 +3,10 @@ * @brief File containing the module declaration for SQLiteC++. */ -export module sqlitecpp; +export module sqlite; -export import sqlitecpp.column; -export import sqlitecpp.database; -export import sqlitecpp.exception; -export import sqlitecpp.statement; -export import sqlitecpp.transaction; +export import sqlite.column; +export import sqlite.database; +export import sqlite.exception; +export import sqlite.statement; +export import sqlite.transaction; diff --git a/src/modules/Statement.cppm b/src/modules/Statement.cppm index 53f19c56..c8d3393b 100644 --- a/src/modules/Statement.cppm +++ b/src/modules/Statement.cppm @@ -7,12 +7,12 @@ module; #include -export module sqlitecpp.statement; +export module sqlite.statement; -export import sqlitecpp.column; -export import sqlitecpp.database; +export import sqlite.column; +export import sqlite.database; -import sqlitecpp.sqlite3forward; +import sqlite.sqlite3forward; /** * @namespace SQLite @@ -21,3 +21,5 @@ import sqlitecpp.sqlite3forward; export namespace SQLite { using SQLite::Statement; } + +export namespace sqlite = SQLite; diff --git a/src/modules/Transaction.cppm b/src/modules/Transaction.cppm index 1af1d675..950497de 100644 --- a/src/modules/Transaction.cppm +++ b/src/modules/Transaction.cppm @@ -7,11 +7,11 @@ module; #include -export module sqlitecpp.transaction; +export module sqlite.transaction; -export import sqlitecpp.database; +export import sqlite.database; -import sqlitecpp.sqlite3forward; +import sqlite.sqlite3forward; /** * @namespace SQLite @@ -21,3 +21,5 @@ export namespace SQLite { using SQLite::TransactionBehavior; using SQLite::Transaction; } + +export namespace sqlite = SQLite; diff --git a/src/modules/sqlite3forward.cppm b/src/modules/sqlite3forward.cppm index d4ac06af..6095cd26 100644 --- a/src/modules/sqlite3forward.cppm +++ b/src/modules/sqlite3forward.cppm @@ -7,7 +7,7 @@ module; #include -export module sqlitecpp.sqlite3forward; +export module sqlite.sqlite3forward; /** * @namespace SQLite From 7f83007e15e8da4ac5dbe2e6191f952e390e3d24 Mon Sep 17 00:00:00 2001 From: Toyosatomimi no Miko <110693261+mikomikotaishi@users.noreply.github.com> Date: Sat, 31 May 2025 02:31:42 -0400 Subject: [PATCH 6/6] Fix docs to match name change --- README.md | 2 +- docs/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2548b9a5..c0224774 100644 --- a/README.md +++ b/README.md @@ -192,7 +192,7 @@ cmake --build . ctest --output-on-failure ``` -To enable building with C++20 modules (and importing the library with `import sqlitecpp;`), pass `SQLITECPP_BUILD_MODULES` to the build system. +To enable building with C++20 modules (and importing the library with `import sqlite;`), pass `SQLITECPP_BUILD_MODULES` to the build system. #### Building with meson diff --git a/docs/README.md b/docs/README.md index 18991fea..ee6de593 100644 --- a/docs/README.md +++ b/docs/README.md @@ -193,7 +193,7 @@ cmake --build . ctest --output-on-failure ``` -To enable building with C++20 modules (and importing the library with `import sqlitecpp;`), pass `SQLITECPP_BUILD_MODULES` to the build system. +To enable building with C++20 modules (and importing the library with `import sqlite;`), pass `SQLITECPP_BUILD_MODULES` to the build system. #### CMake options