Skip to content

Commit

Permalink
CMake: using external sqlite3 is available, otherwise use internal copy.
Browse files Browse the repository at this point in the history
  • Loading branch information
matlabbe committed Sep 5, 2018
1 parent 9c70b71 commit 43e144e
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 27 deletions.
11 changes: 11 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ endif()

FIND_PACKAGE(ZLIB REQUIRED QUIET)

FIND_PACKAGE(Sqlite3 QUIET)
IF(Sqlite3_FOUND)
MESSAGE(STATUS "Found Sqlite3: ${Sqlite3_INCLUDE_DIRS} ${Sqlite3_LIBRARIES}")
ENDIF(Sqlite3_FOUND)

if(NOT "${PCL_LIBRARIES}" STREQUAL "")
# fix libproj.so not found on Xenial
list(REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
Expand Down Expand Up @@ -879,6 +884,12 @@ IF(OpenCV_FOUND)
ENDIF()
ENDIF(OpenCV_FOUND)

IF(SQLITE3_FOUND)
MESSAGE(STATUS " With external SQLite3 = YES")
ELSE()
MESSAGE(STATUS " With external SQLite3 = NO (sqlite3 not found, internal version is used for convenience)")
ENDIF()

IF(Freenect_FOUND)
MESSAGE(STATUS " With Freenect = YES (License: Apache v2 and/or GPLv2)")
ELSEIF(NOT WITH_FREENECT)
Expand Down
48 changes: 25 additions & 23 deletions cmake_modules/FindSqlite3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,48 @@
# This module finds an installed Sqlite3 package.
#
# It sets the following variables:
# SQLITE3_FOUND - Set to false, or undefined, if Sqlite3 isn't found.
# SQLITE3_INCLUDE_DIR - The Sqlite3 include directory.
# SQLITE3_LIBRARY - The Sqlite3 library to link against.
# Sqlite3_FOUND - Set to false, or undefined, if Sqlite3 isn't found.
# Sqlite3_INCLUDE_DIR - The Sqlite3 include directory.
# Sqlite3_LIBRARY - The Sqlite3 library to link against.

SET(SQLITE3_VERSION_REQUIRED "3.6.0")
SET(Sqlite3_VERSION_REQUIRED "3.6.0")

IF(UNIX)
FIND_PROGRAM(SQLITE3_EXEC NAME sqlite3 PATHS)
IF(SQLITE3_EXEC)
MESSAGE(STATUS "Found Sqlite3 executable : ${SQLITE3_EXEC}")
EXECUTE_PROCESS(COMMAND ${SQLITE3_EXEC} --version
OUTPUT_VARIABLE SQLITE3_VERSION
FIND_PROGRAM(Sqlite3_EXEC NAME sqlite3 PATHS $ENV{Sqlite3_ROOT_DIR}/bin $ENV{Sqlite3_ROOT_DIR})
IF(Sqlite3_EXEC)
MESSAGE(STATUS "Found Sqlite3 executable : ${Sqlite3_EXEC}")
EXECUTE_PROCESS(COMMAND ${Sqlite3_EXEC} --version
OUTPUT_VARIABLE Sqlite3_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
WORKING_DIRECTORY "./"
)
IF(SQLITE3_VERSION VERSION_LESS SQLITE3_VERSION_REQUIRED)
MESSAGE(FATAL_ERROR "Sqlite ${SQLITE3_VERSION} found, but version ${SQLITE3_VERSION_REQUIRED} minimum is required")
ENDIF(SQLITE3_VERSION VERSION_LESS SQLITE3_VERSION_REQUIRED)
ELSE(SQLITE3_EXEC)
IF(Sqlite3_VERSION VERSION_LESS Sqlite3_VERSION_REQUIRED)
MESSAGE(FATAL_ERROR "Sqlite ${Sqlite3_VERSION} found, but version ${Sqlite3_VERSION_REQUIRED} minimum is required")
ENDIF(Sqlite3_VERSION VERSION_LESS Sqlite3_VERSION_REQUIRED)
ELSE(Sqlite3_EXEC)
MESSAGE(FATAL_ERROR "Could not find Sqlite3 executable")
ENDIF(SQLITE3_EXEC)
ENDIF(Sqlite3_EXEC)
ENDIF(UNIX)

FIND_PATH(SQLITE3_INCLUDE_DIR sqlite3.h)
FIND_PATH(Sqlite3_INCLUDE_DIR sqlite3.h PATHS $ENV{Sqlite3_ROOT_DIR}/include $ENV{Sqlite3_ROOT_DIR})

FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3.dll sqlite3)
FIND_LIBRARY(Sqlite3_LIBRARY NAMES sqlite3 PATHS $ENV{Sqlite3_ROOT_DIR}/lib $ENV{Sqlite3_ROOT_DIR})

IF (SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY)
SET(SQLITE3_FOUND TRUE)
ENDIF (SQLITE3_INCLUDE_DIR AND SQLITE3_LIBRARY)
IF (Sqlite3_INCLUDE_DIR AND Sqlite3_LIBRARY)
SET(Sqlite3_FOUND TRUE)
SET(Sqlite3_INCLUDE_DIRS ${Sqlite3_INCLUDE_DIR})
SET(Sqlite3_LIBRARIES ${Sqlite3_LIBRARY})
ENDIF (Sqlite3_INCLUDE_DIR AND Sqlite3_LIBRARY)

IF (SQLITE3_FOUND)
IF (Sqlite3_FOUND)
# show which Sqlite3 was found only if not quiet
IF (NOT Sqlite3_FIND_QUIETLY)
MESSAGE(STATUS "Found Sqlite3")
MESSAGE(STATUS "Found Sqlite3: ${Sqlite3_INCLUDE_DIRS} ${Sqlite3_LIBRARIES}")
ENDIF (NOT Sqlite3_FIND_QUIETLY)
ELSE (SQLITE3_FOUND)
ELSE (Sqlite3_FOUND)
# fatal error if Sqlite3 is required but not found
IF (Sqlite3_FIND_REQUIRED)
MESSAGE(FATAL_ERROR "Could not find Sqlite3")
ENDIF (Sqlite3_FIND_REQUIRED)
ENDIF (SQLITE3_FOUND)
ENDIF (Sqlite3_FOUND)

24 changes: 21 additions & 3 deletions corelib/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ SET(SRC_FILES

rtflann/ext/lz4.c
rtflann/ext/lz4hc.c
FlannIndex.cpp

sqlite3/sqlite3.c
FlannIndex.cpp

#clams stuff
clams/discrete_depth_distortion_model_helpers.cpp
Expand Down Expand Up @@ -129,6 +127,26 @@ SET(LIBRARIES
${ZLIB_LIBRARIES}
)

IF(Sqlite3_FOUND)
SET(INCLUDE_DIRS
${INCLUDE_DIRS}
${Sqlite3_INCLUDE_DIRS}
)
SET(LIBRARIES
${LIBRARIES}
${Sqlite3_LIBRARIES}
)
ELSE()
SET(SRC_FILES
${SRC_FILES}
sqlite3/sqlite3.c
)
SET(INCLUDE_DIRS
${CMAKE_CURRENT_SOURCE_DIR}/sqlite3
${INCLUDE_DIRS}
)
ENDIF()

IF(Freenect_FOUND)
IF(Freenect_DASH_INCLUDES)
ADD_DEFINITIONS("-DFREENECT_DASH_INCLUDES")
Expand Down
2 changes: 1 addition & 1 deletion corelib/src/DBDriverSqlite3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "rtabmap/core/DBDriverSqlite3.h"
#include "sqlite3/sqlite3.h"
#include <sqlite3.h>

#include "rtabmap/core/Signature.h"
#include "rtabmap/core/VisualWord.h"
Expand Down

0 comments on commit 43e144e

Please sign in to comment.