From c38dca203dbb34e6f1dc122f8f68054f4e98b6f6 Mon Sep 17 00:00:00 2001 From: Frank Riley Date: Sun, 24 May 2020 23:07:22 +0000 Subject: [PATCH] Fix build of sqlite3. Move sqlite3 defines to the top level so they are on all. Signed-off-by: Frank Riley --- src/CMakeLists.txt | 13 ++++++++++--- src/api/CMakeLists.txt | 1 + src/database/CMakeLists.txt | 24 ++++++------------------ src/dnsmasq/CMakeLists.txt | 1 + 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bf137842..e902d676 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,14 @@ endif() # Put runtime output, i.e. pihole-FTL, in the root of the build dir set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) +# SQLITE_OMIT_LOAD_EXTENSION: This option omits the entire extension loading mechanism from SQLite, including sqlite3_enable_load_extension() and sqlite3_load_extension() interfaces. (needs -ldl linking option, otherwise) +# SQLITE_DEFAULT_MEMSTATUS=0: This setting causes the sqlite3_status() interfaces that track memory usage to be disabled. This helps the sqlite3_malloc() routines run much faster, and since SQLite uses sqlite3_malloc() internally, this helps to make the entire library faster. +# SQLITE_OMIT_DEPRECATED: Omitting deprecated interfaces and features will not help SQLite to run any faster. It will reduce the library footprint, however. And it is the right thing to do. +# SQLITE_OMIT_PROGRESS_CALLBACK: The progress handler callback counter must be checked in the inner loop of the bytecode engine. By omitting this interface, a single conditional is removed from the inner loop of the bytecode engine, helping SQL statements to run slightly faster. +# SQLITE_DEFAULT_FOREIGN_KEYS=1: This macro determines whether enforcement of foreign key constraints is enabled or disabled by default for new database connections. +# SQLITE_DQS=0: This setting disables the double-quoted string literal misfeature. +set(SQLITE_DEFINES "-DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_DEFAULT_MEMSTATUS=0 -DSQLITE_OMIT_DEPRECATED -DSQLITE_OMIT_PROGRESS_CALLBACK -DSQLITE_OMIT_MEMORYDB -DSQLITE_DEFAULT_FOREIGN_KEYS=1 -DSQLITE_DQS=0") + # Code hardening and debugging improvements # -fstack-protector-strong: The program will be resistant to having its stack overflowed # -Wp,-D_FORTIFY_SOURCE=2 and -O1 or higher: This causes certain unsafe glibc functions to be replaced with their safer counterparts @@ -75,7 +83,7 @@ endif() # -FILE_OFFSET_BITS=64: used by stat(). Avoids problems with files > 2 GB on 32bit machines # We define HAVE_POLL_H as this is needed for the musl builds to succeed -set(CMAKE_C_FLAGS "-pipe ${WARN_FLAGS} -D_FILE_OFFSET_BITS=64 ${HARDENING_FLAGS} ${DEBUG_FLAGS} ${CMAKE_C_FLAGS} -DHAVE_POLL_H") +set(CMAKE_C_FLAGS "-pipe ${WARN_FLAGS} -D_FILE_OFFSET_BITS=64 ${HARDENING_FLAGS} ${DEBUG_FLAGS} ${CMAKE_C_FLAGS} -DHAVE_POLL_H ${SQLITE_DEFINES}") set(CMAKE_C_FLAGS_DEBUG "-O0 -g3") set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG") @@ -127,8 +135,6 @@ set(sources set_source_files_properties(version.h PROPERTIES GENERATED TRUE) -include_directories(${CMAKE_CURRENT_SOURCE_DIR}) - add_custom_target( gen_version ALL COMMAND ${CMAKE_COMMAND} -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} -P ${CMAKE_CURRENT_SOURCE_DIR}/gen_version.cmake @@ -142,6 +148,7 @@ add_executable(pihole-FTL $ ) target_compile_options(pihole-FTL PRIVATE ${EXTRAWARN}) +target_include_directories(pihole-FTL PRIVATE ${PROJECT_SOURCE_DIR}/src) add_dependencies(pihole-FTL gen_version) set(CMAKE_THREAD_PREFER_PTHREAD TRUE) diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index 789f2ed2..b4ba5003 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -11,3 +11,4 @@ set(sources add_library(api OBJECT ${sources}) add_dependencies(api gen_version) target_compile_options(api PRIVATE ${EXTRAWARN}) +target_include_directories(api PRIVATE ${PROJECT_SOURCE_DIR}/src) diff --git a/src/database/CMakeLists.txt b/src/database/CMakeLists.txt index 7c58519b..f86a1e57 100644 --- a/src/database/CMakeLists.txt +++ b/src/database/CMakeLists.txt @@ -1,26 +1,12 @@ -# SQLITE_OMIT_LOAD_EXTENSION: This option omits the entire extension loading mechanism from SQLite, including sqlite3_enable_load_extension() and sqlite3_load_extension() interfaces. (needs -ldl linking option, otherwise) -# SQLITE_DEFAULT_MEMSTATUS=0: This setting causes the sqlite3_status() interfaces that track memory usage to be disabled. This helps the sqlite3_malloc() routines run much faster, and since SQLite uses sqlite3_malloc() internally, this helps to make the entire library faster. -# SQLITE_OMIT_DEPRECATED: Omitting deprecated interfaces and features will not help SQLite to run any faster. It will reduce the library footprint, however. And it is the right thing to do. -# SQLITE_OMIT_PROGRESS_CALLBACK: The progress handler callback counter must be checked in the inner loop of the bytecode engine. By omitting this interface, a single conditional is removed from the inner loop of the bytecode engine, helping SQL statements to run slightly faster. -# SQLITE_DEFAULT_FOREIGN_KEYS=1: This macro determines whether enforcement of foreign key constraints is enabled or disabled by default for new database connections. -# SQLITE_DQS=0: This setting disables the double-quoted string literal misfeature. -set(SQLITE_DEFINES - SQLITE_OMIT_LOAD_EXTENSION - SQLITE_DEFAULT_MEMSTATUS=0 - SQLITE_OMIT_DEPRECATED - SQLITE_OMIT_PROGRESS_CALLBACK - SQLITE_OMIT_MEMORYDB - SQLITE_DEFAULT_FOREIGN_KEYS=1 - SQLITE_DQS=0 - ) - +# This file has no dependencies on other code in the repo and takes a long time +# to build. It is placed in its own target so that it does not include any other +# headers in the build command and thus does not need to be rebuilt when headers +# are modified. set(sqlite3_sources sqlite3.c - sqlite3.h ) add_library(sqlite3 OBJECT ${sqlite3_sources}) -target_compile_definitions(sqlite3 PRIVATE ${SQLITE_DEFINES}) target_compile_options(sqlite3 PRIVATE -Wno-implicit-fallthrough -Wno-cast-function-type) set(database_sources @@ -36,9 +22,11 @@ set(database_sources network-table.h query-table.c query-table.h + sqlite3.h sqlite3-ext.c sqlite3-ext.h ) add_library(database OBJECT ${database_sources}) target_compile_options(database PRIVATE "${EXTRAWARN}") +target_include_directories(database PRIVATE ${PROJECT_SOURCE_DIR}/src) diff --git a/src/dnsmasq/CMakeLists.txt b/src/dnsmasq/CMakeLists.txt index 1711f9a0..79269922 100644 --- a/src/dnsmasq/CMakeLists.txt +++ b/src/dnsmasq/CMakeLists.txt @@ -51,3 +51,4 @@ set(sources add_library(dnsmasq OBJECT ${sources}) target_compile_definitions(dnsmasq PRIVATE VERSION=\"${DNSMASQ_VERSION}\" HAVE_DNSSEC HAVE_DNSSEC_STATIC HAVE_IDN) target_compile_options(dnsmasq PRIVATE -Wno-maybe-uninitialized) +target_include_directories(dnsmasq PRIVATE ${PROJECT_SOURCE_DIR}/src)