Make sqlite backend optional (enabled by default)
This commit is contained in:
parent
d707b882e8
commit
2fabf991ab
@ -90,21 +90,42 @@ endif(NOT ZLIB_LIBRARY OR NOT ZLIB_INCLUDE_DIR)
|
||||
find_package(PkgConfig)
|
||||
include(FindPackageHandleStandardArgs)
|
||||
|
||||
# Find libsqlite3
|
||||
# Find database(s)
|
||||
set(USE_SQLITE3 0)
|
||||
set(USE_LEVELDB 0)
|
||||
set(USE_REDIS 0)
|
||||
|
||||
OPTION(ENABLE_ANY_DATABASE "Enable any available database backends")
|
||||
OPTION(ENABLE_SQLITE3 "Enable sqlite3 backend" True)
|
||||
OPTION(ENABLE_LEVELDB "Enable LevelDB backend")
|
||||
OPTION(ENABLE_REDIS "Enable redis backend")
|
||||
|
||||
MACRO(backend_message IS_FATAL text)
|
||||
if(S_FATAL)
|
||||
message(FATAL_ERROR text)
|
||||
else(IS_FATAL)
|
||||
message(STATUS text)
|
||||
endif(IS_FATAL)
|
||||
ENDMACRO(backend_message)
|
||||
|
||||
# Find sqlite3
|
||||
if(ENABLE_SQLITE3 OR ENABLE_ANY_DATABASE)
|
||||
find_library(SQLITE3_LIBRARY sqlite3)
|
||||
find_path(SQLITE3_INCLUDE_DIR zlib.h)
|
||||
message (STATUS "sqlite3 library: ${SQLITE3_LIBRARY}")
|
||||
message (STATUS "sqlite3 headers: ${SQLITE3_INCLUDE_DIR}")
|
||||
if(NOT SQLITE3_LIBRARY OR NOT SQLITE3_INCLUDE_DIR)
|
||||
message(FATAL_ERROR "sqlite3 not found!")
|
||||
endif(NOT SQLITE3_LIBRARY OR NOT SQLITE3_INCLUDE_DIR)
|
||||
if(SQLITE3_LIBRARY AND SQLITE3_INCLUDE_DIR)
|
||||
set(USE_SQLITE3 1)
|
||||
message(STATUS "sqlite3 backend enabled")
|
||||
include_directories(${SQLITE3_INCLUDE_DIR})
|
||||
else(SQLITE3_LIBRARY AND SQLITE3_INCLUDE_DIR)
|
||||
set(USE_SQLITE3 0)
|
||||
backend_message((NOT ENABLE_ANY_DATABASE) "sqlite3 backend requested but sqlite3 libraries not found!")
|
||||
endif(SQLITE3_LIBRARY AND SQLITE3_INCLUDE_DIR)
|
||||
endif(ENABLE_SQLITE3 OR ENABLE_ANY_DATABASE)
|
||||
|
||||
# Find leveldb
|
||||
set(USE_LEVELDB 0)
|
||||
|
||||
OPTION(ENABLE_LEVELDB "Enable LevelDB backend")
|
||||
|
||||
if(ENABLE_LEVELDB)
|
||||
if(ENABLE_LEVELDB OR ENABLE_ANY_DATABASE)
|
||||
find_library(LEVELDB_LIBRARY leveldb)
|
||||
find_path(LEVELDB_INCLUDE_DIR db.h PATH_SUFFIXES leveldb)
|
||||
message (STATUS "LevelDB library: ${LEVELDB_LIBRARY}")
|
||||
@ -115,16 +136,12 @@ if(ENABLE_LEVELDB)
|
||||
include_directories(${LEVELDB_INCLUDE_DIR})
|
||||
else(LEVELDB_LIBRARY AND LEVELDB_INCLUDE_DIR)
|
||||
set(USE_LEVELDB 0)
|
||||
message(STATUS "LevelDB not found!")
|
||||
backend_message((NOT ENABLE_ANY_DATABASE) "LevelDB backend requested but LevelDB libraries not found!")
|
||||
endif(LEVELDB_LIBRARY AND LEVELDB_INCLUDE_DIR)
|
||||
endif(ENABLE_LEVELDB)
|
||||
endif(ENABLE_LEVELDB OR ENABLE_ANY_DATABASE)
|
||||
|
||||
# Find redis
|
||||
set(USE_REDIS 0)
|
||||
|
||||
OPTION(ENABLE_REDIS "Enable redis backend")
|
||||
|
||||
if(ENABLE_REDIS)
|
||||
if(ENABLE_REDIS OR ENABLE_ANY_DATABASE)
|
||||
find_library(REDIS_LIBRARY hiredis)
|
||||
find_path(REDIS_INCLUDE_DIR hiredis.h PATH_SUFFIXES hiredis)
|
||||
message (STATUS "redis library: ${REDIS_LIBRARY}")
|
||||
@ -135,15 +152,18 @@ if(ENABLE_REDIS)
|
||||
include_directories(${REDIS_INCLUDE_DIR})
|
||||
else(REDIS_LIBRARY AND REDIS_INCLUDE_DIR)
|
||||
set(USE_REDIS 0)
|
||||
message(STATUS "redis not found!")
|
||||
backend_message((NOT ENABLE_ANY_DATABASE) "redis backend requested but redis libraries not found!")
|
||||
endif(REDIS_LIBRARY AND REDIS_INCLUDE_DIR)
|
||||
endif(ENABLE_REDIS)
|
||||
endif(ENABLE_REDIS OR ENABLE_ANY_DATABASE)
|
||||
|
||||
if(NOT ENABLE_SQLITE3 AND NOT ENABLE_LEVELDB AND NOT ENABLE_REDIS)
|
||||
message(FATAL_ERROR "No database backends are configured, or none could be found")
|
||||
endif(NOT ENABLE_SQLITE3 AND NOT ENABLE_LEVELDB AND NOT ENABLE_REDIS)
|
||||
|
||||
include_directories(
|
||||
"${PROJECT_BINARY_DIR}"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||
${SQLITE3_INCLUDE_DIR}
|
||||
${LIBGD_INCLUDE_DIR}
|
||||
${ZLIB_INCLUDE_DIR}
|
||||
)
|
||||
@ -161,9 +181,12 @@ set(mapper_SRCS
|
||||
ZlibDecompressor.cpp
|
||||
Color.cpp
|
||||
mapper.cpp
|
||||
db-sqlite3.cpp
|
||||
)
|
||||
|
||||
if(USE_SQLITE3)
|
||||
set(mapper_SRCS ${mapper_SRCS} db-sqlite3.cpp)
|
||||
endif(USE_SQLITE3)
|
||||
|
||||
if(USE_LEVELDB)
|
||||
set(mapper_SRCS ${mapper_SRCS} db-leveldb.cpp)
|
||||
endif(USE_LEVELDB)
|
||||
|
@ -7,7 +7,7 @@ Requirements
|
||||
------------
|
||||
|
||||
* libgd
|
||||
* sqlite3
|
||||
* sqlite3 (enabled by default, set ENABLE_SQLITE3=0 in CMake to disable)
|
||||
* leveldb (optional, set ENABLE_LEVELDB=1 in CMake to enable leveldb support)
|
||||
* hiredis (optional, set ENABLE_REDIS=1 in CMake to enable redis support)
|
||||
|
||||
@ -42,7 +42,6 @@ Release version:
|
||||
cmake -DCMAKE_BUILD_TYPE:STRING=Release .
|
||||
make
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
|
@ -22,7 +22,9 @@
|
||||
#include "PlayerAttributes.h"
|
||||
#include "TileGenerator.h"
|
||||
#include "ZlibDecompressor.h"
|
||||
#if USE_SQLITE3
|
||||
#include "db-sqlite3.h"
|
||||
#endif
|
||||
#if USE_LEVELDB
|
||||
#include "db-leveldb.h"
|
||||
#endif
|
||||
@ -93,7 +95,7 @@ TileGenerator::TileGenerator():
|
||||
m_drawAlpha(false),
|
||||
m_shading(true),
|
||||
m_border(0),
|
||||
m_backend("sqlite3"),
|
||||
m_backend(DEFAULT_BACKEND),
|
||||
m_shrinkGeometry(true),
|
||||
m_blockGeometry(false),
|
||||
m_sqliteCacheWorldRow(false),
|
||||
@ -378,11 +380,15 @@ void TileGenerator::parseColorsStream(std::istream &in, const std::string &filen
|
||||
|
||||
void TileGenerator::openDb(const std::string &input)
|
||||
{
|
||||
if(m_backend == "sqlite3") {
|
||||
if (false) {
|
||||
}
|
||||
#if USE_SQLITE3
|
||||
else if(m_backend == "sqlite3") {
|
||||
DBSQLite3 *db;
|
||||
m_db = db = new DBSQLite3(input);
|
||||
db->cacheWorldRow = m_sqliteCacheWorldRow;
|
||||
}
|
||||
#endif
|
||||
#if USE_LEVELDB
|
||||
else if(m_backend == "leveldb")
|
||||
m_db = new DBLevelDB(input);
|
||||
|
@ -3,6 +3,7 @@
|
||||
#ifndef CMAKE_CONFIG_H
|
||||
#define CMAKE_CONFIG_H
|
||||
|
||||
#define USE_SQLITE3 @USE_SQLITE3@
|
||||
#define USE_LEVELDB @USE_LEVELDB@
|
||||
#define USE_REDIS @USE_REDIS@
|
||||
|
||||
|
40
config.h
40
config.h
@ -23,3 +23,43 @@
|
||||
#else
|
||||
#define USE_LEVELDB 0
|
||||
#endif
|
||||
|
||||
// List of possible database names (for usage message)
|
||||
#if USE_SQLITE3
|
||||
#define USAGE_NAME_SQLITE "sqlite3"
|
||||
#else
|
||||
#define USAGE_NAME_SQLITE
|
||||
#endif
|
||||
#if USE_SQLITE3 && USE_LEVELDB
|
||||
#define USAGE_SEP_SQLITE_LEVELDB "/"
|
||||
#else
|
||||
#define USAGE_SEP_SQLITE_LEVELDB
|
||||
#endif
|
||||
#if USE_LEVELDB
|
||||
#define USAGE_NAME_LEVELDB "leveldb"
|
||||
#else
|
||||
#define USAGE_NAME_LEVELDB
|
||||
#endif
|
||||
#if USE_LEVELDB && USE_REDIS
|
||||
#define USAGE_SEP_LEVELDB_REDIS "/"
|
||||
#else
|
||||
#define USAGE_SEP_LEVELDB_REDIS
|
||||
#endif
|
||||
#if USE_REDIS
|
||||
#define USAGE_NAME_REDIS "redis"
|
||||
#else
|
||||
#define USAGE_NAME_REDIS
|
||||
#endif
|
||||
#define USAGE_DATABASES USAGE_NAME_SQLITE USAGE_SEP_SQLITE_LEVELDB USAGE_NAME_LEVELDB USAGE_SEP_LEVELDB_REDIS USAGE_NAME_REDIS
|
||||
|
||||
// default database to use
|
||||
#if USE_SQLITE3
|
||||
#define DEFAULT_BACKEND "sqlite3"
|
||||
#elif USE_LEVELDB
|
||||
#define DEFAULT_BACKEND "leveldb"
|
||||
#elif USE_REDIS
|
||||
#define DEFAULT_BACKEND "redis"
|
||||
#else
|
||||
#error No database backends configured !
|
||||
#endif
|
||||
|
||||
|
@ -44,12 +44,14 @@ void usage()
|
||||
" --noshading\n"
|
||||
" --min-y <y>\n"
|
||||
" --max-y <y>\n"
|
||||
" --backend <sqlite3/leveldb/redis>\n"
|
||||
" --backend <" USAGE_DATABASES ">\n"
|
||||
" --geometry <geometry>\n"
|
||||
" --cornergeometry <geometry>\n"
|
||||
" --centergeometry <geometry>\n"
|
||||
" --geometrymode pixel,block,fixed,shrink\n"
|
||||
#if USE_SQLITE3
|
||||
" --sqlite-cacheworldrow\n"
|
||||
#endif
|
||||
" --tiles <tilesize>[+<border>]\n"
|
||||
" --tileorigin <x>,<y>|center-world|center-map\n"
|
||||
" --verbose[=n]\n"
|
||||
|
Loading…
x
Reference in New Issue
Block a user