Screenplay: Making SQLite3
Optional (target_compile_definitions()
)¶
What If We Know How to Live Without SQLite3?¶
toolcase/data-logger
hassink-sqlite3.h
andsink-sqlite3.cpp
only 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.h
andsink-sqlite3.cpp
, depending onSQLite3_FOUND
if (SQLite3_FOUND) set(inc_sink_sqlite3 sink-sqlite3.h) set(src_sink_sqlite3 sink-sqlite3.cpp) endif()
… and substitute accordingly
Library depends on
SQLite::SQLite3
if (SQLite3_FOUND) target_link_libraries(data-logger SQLite::SQLite3) endif()
Library propagates dependency information to its users (see below);
INTERFACE
because 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_SQLITE3
availableLitter
#ifdef
all across your code#ifdef HAVE_SQLITE3 # include <sink-sqlite3.h> #else # include <sink-terminal.h> #endif
It is a massacre, inevitably!