From 73e787a9ecc9f9e459afb61dab1ffd13e31abacf Mon Sep 17 00:00:00 2001 From: Thomas Winget Date: Wed, 6 Oct 2021 19:04:23 -0400 Subject: [PATCH] sqlitecpp cmake nonsense --- CMakeLists.txt | 5 ++--- cmake/StaticBuild.cmake | 11 ++++++++++- external/CMakeLists.txt | 21 +++++++++++++++++---- src/cryptonote_core/CMakeLists.txt | 2 +- src/wallet/api/CMakeLists.txt | 2 +- 5 files changed, 31 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d82b0ce11..fe884b54f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -506,10 +506,9 @@ endif() if(NOT BUILD_STATIC_DEPS) - add_library(sqlite3 INTERFACE) - pkg_check_modules(SQLITE3 REQUIRED sqlite3 IMPORTED_TARGET) + pkg_check_modules(SQLITE3 REQUIRED sqlite3 IMPORTED_TARGET GLOBAL) message(STATUS "Found sqlite3 ${SQLITE3_VERSION}") - target_link_libraries(sqlite3 INTERFACE PkgConfig::SQLITE3) + add_library(SQLite::SQLite3 ALIAS PkgConfig::SQLITE3) endif() add_subdirectory(external) diff --git a/cmake/StaticBuild.cmake b/cmake/StaticBuild.cmake index 3fd4c46b2..a13d1a9df 100644 --- a/cmake/StaticBuild.cmake +++ b/cmake/StaticBuild.cmake @@ -54,6 +54,15 @@ set(SQLITE3_SOURCE sqlite-autoconf-${SQLITE3_VERSION}.tar.gz) set(SQLITE3_HASH SHA512=039af796f79fc4517be0bd5ba37886264d49da309e234ae6fccdb488ef0109ed2b917fc3e6c1fc7224dff4f736824c653aaf8f0a37550c5ebc14d035cb8ac737 CACHE STRING "sqlite3 source hash") +if(SQLITE3_VERSION MATCHES "^([0-9]+)(0([0-9])|([1-9][0-9]))(0([0-9])|([1-9][0-9]))[0-9][0-9]$") + set(SQLite3_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_3}${CMAKE_MATCH_4}.${CMAKE_MATCH_6}${CMAKE_MATCH_7}" CACHE STRING "" FORCE) + mark_as_advanced(SQLite3_VERSION) + message(STATUS "Building static sqlite3 ${SQLite3_VERSION}") +else() + message(FATAL_ERROR "Couldn't figure out sqlite3 version from '${SQLITE3_VERSION}'") +endif() + + set(EUDEV_VERSION 3.2.10 CACHE STRING "eudev version") set(EUDEV_MIRROR ${LOCAL_MIRROR} https://github.com/gentoo/eudev/archive/ CACHE STRING "eudev download mirror(s)") @@ -430,7 +439,7 @@ set(Boost_VERSION ${BOOST_VERSION}) build_external(sqlite3 BUILD_COMMAND true INSTALL_COMMAND make install-includeHEADERS install-libLTLIBRARIES) -add_static_target(sqlite3 sqlite3_external libsqlite3.a) +add_static_target( SQLite::SQLite3 sqlite3_external libsqlite3.a) diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 4046190a9..b05f46f26 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -145,8 +145,21 @@ target_include_directories(cpr PUBLIC cpr/include) target_compile_definitions(cpr PUBLIC CPR_CURL_NOSIGNAL) add_library(cpr::cpr ALIAS cpr) -# disable bundled sqlite3 in sqlitecpp -if(TARGET sqlite3) - option(SQLITECPP_INTERNAL_SQLITE "" OFF) -endif() +# Hack around SQLiteCpp's attempts to locate sqlite3 because we *don't* want to link against the +# system one, but don't download and build the embedded one until build time. Thankfully it +# actually links against the SQLite::SQLite3 cmake target if it already exists, so all we have to do +# is set that up and circumvent some of the non-target bits of its FindSQLite3.cmake. +set(SQLite3_FOUND TRUE CACHE BOOL "" FORCE) +file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/ignored") +file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/ignored/sqlite3.h" "#define SQLITE_VERSION \"${SQLite3_VERSION}\"") +set(SQLite3_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/ignored" CACHE STRING "" FORCE) +set(SQLite3_LIBRARY "ignored" CACHE STRING "" FORCE) +set(SQLITECPP_INTERNAL_SQLITE OFF CACHE BOOL "don't build SQLiteCpp's internal sqlite3" FORCE) +set(SQLITE_ENABLE_COLUMN_METADATA OFF CACHE BOOL "" FORCE) +set(SQLITECPP_RUN_CPPLINT OFF CACHE BOOL "" FORCE) +set(SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "" FORCE) +set(SQLITECPP_RUN_DOXYGEN OFF CACHE BOOL "" FORCE) +set(SQLITECPP_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE) +set(SQLITECPP_BUILD_TESTS OFF CACHE BOOL "" FORCE) + add_subdirectory(SQLiteCpp) diff --git a/src/cryptonote_core/CMakeLists.txt b/src/cryptonote_core/CMakeLists.txt index e022212fc..d7f2284d3 100644 --- a/src/cryptonote_core/CMakeLists.txt +++ b/src/cryptonote_core/CMakeLists.txt @@ -52,7 +52,7 @@ target_link_libraries(cryptonote_core ringct device checkpoints - sqlite3 + SQLite::SQLite3 PRIVATE Boost::program_options systemd diff --git a/src/wallet/api/CMakeLists.txt b/src/wallet/api/CMakeLists.txt index fc889116e..d5e36b5a4 100644 --- a/src/wallet/api/CMakeLists.txt +++ b/src/wallet/api/CMakeLists.txt @@ -128,7 +128,7 @@ if (STATIC AND BUILD_STATIC_DEPS) OpenSSL::SSL OpenSSL::Crypto expat libunbound - sqlite3 + SQLite::SQLite3 ${merged_protobuf} sodium libzmq