Test whether sqlite3 has the FTS3 at compile time, and use the static sqlite3 module if not

This commit is contained in:
David Sansome 2010-06-30 19:55:46 +00:00
parent 88be9986f1
commit a1fbd65f68
6 changed files with 62 additions and 12 deletions

View File

@ -126,6 +126,28 @@ if(ENABLE_VISUALISATIONS)
add_subdirectory(3rdparty/libprojectm)
endif(ENABLE_VISUALISATIONS)
# Test whether libsqlite3 is available and if FTS3 is enabled in it
if(WIN32 OR APPLE)
option(STATIC_SQLITE "Compile and use a static sqlite3 library" ON)
else(WIN32 OR APPLE)
try_run(FTS_TEST_RUN FTS_TEST_COMPILE
${CMAKE_CURRENT_BINARY_DIR}/sqlite3_fts_test
${CMAKE_SOURCE_DIR}/cmake/sqlite3_fts_test.cpp
CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=sqlite3")
if(NOT FTS_TEST_COMPILE OR FTS_TEST_RUN EQUAL 1 OR FTS_TEST_RUN STREQUAL "FAILED_TO_RUN")
option(STATIC_SQLITE "Compile and use a static sqlite3 library" ON)
else(NOT FTS_TEST_COMPILE OR FTS_TEST_RUN EQUAL 1 OR FTS_TEST_RUN STREQUAL "FAILED_TO_RUN")
option(STATIC_SQLITE "Compile and use a static sqlite3 library" OFF)
endif(NOT FTS_TEST_COMPILE OR FTS_TEST_RUN EQUAL 1 OR FTS_TEST_RUN STREQUAL "FAILED_TO_RUN")
endif(WIN32 OR APPLE)
set(HAVE_STATIC_SQLITE ${STATIC_SQLITE})
if(STATIC_SQLITE)
message(STATUS "Building static qsqlite plugin")
add_definitions(-DQT_STATICPLUGIN)
add_subdirectory(3rdparty/qsqlite)
endif(STATIC_SQLITE)
# Subdirectories
add_subdirectory(3rdparty/qtsingleapplication)
add_subdirectory(3rdparty/qtiocompressor)
@ -138,12 +160,6 @@ add_subdirectory(tests)
add_subdirectory(dist)
add_subdirectory(debian)
if (WIN32 OR APPLE)
message(STATUS "Building static qsqlite plugin")
add_definitions(-DQT_STATICPLUGIN)
add_subdirectory(3rdparty/qsqlite)
endif(WIN32 OR APPLE)
# Uninstall support
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/cmake_uninstall.cmake.in"

View File

@ -0,0 +1,32 @@
/* This file is part of Clementine.
Clementine is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Clementine is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include <sqlite3.h>
int main(int argc, char** argv) {
sqlite3* db;
int ret = sqlite3_open(":memory:", &db);
if (ret)
return 1;
char* error = 0;
ret = sqlite3_exec(db, "CREATE VIRTUAL TABLE foo USING fts3()", 0, 0, &error);
if (ret != SQLITE_OK)
return 1;
return 0;
}

View File

@ -523,10 +523,10 @@ else (APPLE)
endif (APPLE)
# Link against the qsqlite plugin on windows and mac
if(WIN32 OR APPLE)
if(HAVE_STATIC_SQLITE)
set(3RDPARTY_SQLITE_LIBRARY qsqlite)
target_link_libraries(clementine_lib qsqlite)
endif(WIN32 OR APPLE)
endif(HAVE_STATIC_SQLITE)
add_dependencies(clementine_lib qtsingleapplication)

View File

@ -36,4 +36,6 @@
#cmakedefine HAVE_LIBXINE
#cmakedefine HAVE_QT_PHONON
#cmakedefine HAVE_STATIC_SQLITE
#endif // CONFIG_H_IN

View File

@ -14,6 +14,7 @@
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include "database.h"
#include <QCoreApplication>
@ -215,7 +216,7 @@ void Database::StaticInit() {
sFTSTokenizer->xNext = &Database::FTSNext;
sFTSTokenizer->xClose = &Database::FTSClose;
#ifndef Q_WS_X11
#ifdef HAVE_STATIC_SQLITE
// We statically link libqsqlite.dll on windows and mac so these symbols are already
// available
_sqlite3_create_function = sqlite3_create_function;
@ -226,7 +227,7 @@ void Database::StaticInit() {
_sqlite3_user_data = sqlite3_user_data;
sLoadedSqliteSymbols = true;
return;
#else // Q_WS_X11
#else // HAVE_STATIC_SQLITE
QString plugin_path = QLibraryInfo::location(QLibraryInfo::PluginsPath) +
"/sqldrivers/libqsqlite";

View File

@ -55,7 +55,7 @@
#endif
// Load sqlite plugin on windows and mac.
#ifndef Q_WS_X11
#ifdef HAVE_STATIC_SQLITE
# include <QtPlugin>
Q_IMPORT_PLUGIN(qsqlite)
#endif
@ -110,7 +110,6 @@ int main(int argc, char *argv[]) {
qRegisterMetaType<GstEnginePipeline*>("GstEnginePipeline*");
#endif
lastfm::ws::ApiKey = LastFMService::kApiKey;
lastfm::ws::SharedSecret = LastFMService::kSecret;