Screenplay: Adding SQLite3 External Dependency#
Add SQLite3 Capability To Datalogger#
Add to
toolcase/data-logger…Use in
firmware/data-logger.cppif (argc != 2) { std::cerr << "Usage: " << argv[0] << " <SQLITE3-DB>" << std::endl; std::cerr << " (Create: \"" << SinkSQLite3::create_table_statement << "\")" << std::endl; return 1; } ... auto sink = std::make_unique<SinkSQLite3>(argv[1]);
Build
In file included from .../toolcase/data-logger/src/sink-sqlite3.cpp:1:
.../toolcase/data-logger/./include/public/sink-sqlite3.h:5:10: fatal error: sqlite3.h: No such file or directory
5 | #include <sqlite3.h>
| ^~~~~~~~~~~
FIND_PACKAGE()#
Pulling in parameters for
SQLite3ToplevelCMakeLists.txt#find_package(SQLite3) # <--- continues if not found
Not found unless
sqlite3is available$ cmake ... ... -- Could NOT find SQLite3 (missing: SQLite3_INCLUDE_DIR SQLite3_LIBRARY) ...
Not an error though
⟶ error remains:
sqlite3.h: No such file or directoryCould continue if we could handle optional dependencies
⟶ Later (Screenplay: Making SQLite3 Optional (target_compile_definitions()), Screenplay: Making SQLite3 Optional (configure_file()))
FIND_PACKAGE(... REQUIRED)#
C code cannot handle SQLite3 non-availablility
⟶ better to fail early/clearly
find_package(SQLite3 REQUIRED)
$ cmake ... CMake Error at /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:230 (message): Could NOT find SQLite3 (missing: SQLite3_INCLUDE_DIR SQLite3_LIBRARY) Call Stack (most recent call first): /usr/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE) /usr/share/cmake/Modules/FindSQLite3.cmake:54 (find_package_handle_standard_args) CMakeLists.txt:9 (find_package)
Install SQLite3
$ sudo dnf install sqlite-devel
Try again
$ cmake ... ... -- Found SQLite3: /usr/include (found version "3.42.0") ...
Bringing A New Node Into The Graph: Theory#
Find-modules (if successful) usually define a node in the dependency graph
Propagate properties across graphs’s edges
From FindSQLite3
SQLite::SQLite3: imported target ⟶ most importantSQLite3_INCLUDE_DIRS: include path (via
SQLite3_LIBRARIES: nodes to depend on (via
SQLite3_VERSION: additional informationSQLite3_FOUND: to check for availablity in CMake code
Temporarily add, to see that information
message("SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIRS}") message("SQLite3_LIBRARIES ${SQLite3_LIBRARIES}") message("SQLite3_VERSION ${SQLite3_VERSION}") message("SQLite3_FOUND ${SQLite3_FOUND}")
But that is mostly not relevant! (Read on)
Bringing A New Node Into The Graph: Practice#
toolcase/data-loggerhassink-sqlite3.hsink-sqlite3.cpp
⟶ depends on node
SQLite::SQLite3Add dependency there …
target_link_libraries(data-logger SQLite::SQLite3)
And that’s all!