Screenplay: Making SQLite3 Optional (target_compile_definitions())#
What If We Know How to Live Without SQLite3?#
toolcase/data-loggerhassink-sqlite3.handsink-sqlite3.cpponly conditionally⟶
SQLite3_FOUND(see FindSQLite3)
Optionally Not Depending On SQLite3#
Toplevel: make SQLite3 not required
find_package(SQLite3)
toolcase/data-logger/depends on SQLite3 (SQLite::SQLite3)Library contains
sink-sqlite3.handsink-sqlite3.cpp, depending onSQLite3_FOUNDif (SQLite3_FOUND) set(inc_sink_sqlite3 sink-sqlite3.h) set(src_sink_sqlite3 sink-sqlite3.cpp) endif()
… and substitute accordingly
Library depends on
SQLite::SQLite3if (SQLite3_FOUND) target_link_libraries(data-logger SQLite::SQLite3) endif()
Library propagates dependency information to its users (see below);
INTERFACEbecause it does not need that information itselfif (SQLite3_FOUND) target_compile_definitions(data-logger INTERFACE HAVE_SQLITE3=1) endif()
Optionally Not Depending On Someone Who Depends On SQLite3#
firmware/data-logger.cpp(nodeapp-data-logger) uses/includes<sink-sqlite3.h>In that node -
app-data-logger- it would be nice to have a macroHAVE_SQLITE3availableLitter
#ifdefall across your code#ifdef HAVE_SQLITE3 # include <sink-sqlite3.h> #else # include <sink-terminal.h> #endif
It is a massacre, inevitably!