Skip to content

Commit

Permalink
add sqlite3 vendor package for cross-platform capabilities (ros2#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
Karsten1987 authored Jul 16, 2018
1 parent 779eaae commit 178477d
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 0 deletions.
33 changes: 33 additions & 0 deletions sqlite3_vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
cmake_minimum_required(VERSION 3.5)
project(sqlite3_vendor)

list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules")
find_package(SQLite3)

if (NOT SQLite3_FOUND)
include(ExternalProject)
ExternalProject_Add(sqlite3-3.24.0
PREFIX sqlite3-3.24.0
URL https://www.sqlite.org/2018/sqlite-amalgamation-3240000.zip
URL_MD5 4ea1e0c6e7e82cb0490d4753d6878698
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/sqlite3_install
INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/sqlite3_install"
PATCH_COMMAND
${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_SOURCE_DIR}/sqlite3_cmakelists.txt" <SOURCE_DIR>/CMakeLists.txt
)

# The external project will install to the build folder, but we'll install that on make install.
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/sqlite3_install/ DESTINATION ${CMAKE_INSTALL_PREFIX})
else ()
message(STATUS "Found SQLite3. Using SQLite3 from system.")
endif ()

configure_file(sqlite3_vendorConfig.cmake.in "${PROJECT_BINARY_DIR}/sqlite3_vendorConfig.cmake" @ONLY)
configure_file(sqlite3_vendorConfig-version.cmake.in "${PROJECT_BINARY_DIR}/sqlite3_vendorConfig-version.cmake" @ONLY)

install(DIRECTORY cmake DESTINATION share/${PROJECT_NAME})

install(FILES
"${PROJECT_BINARY_DIR}/sqlite3_vendorConfig.cmake"
"${PROJECT_BINARY_DIR}/sqlite3_vendorConfig-version.cmake"
DESTINATION share/${PROJECT_NAME}/cmake)
81 changes: 81 additions & 0 deletions sqlite3_vendor/cmake/Modules/FindSQLite3.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
##################################################################################################
#
# CMake script for finding SQLite3.
#
# Input variables:
#
# - SQLite3_ROOT_DIR (optional): When specified, header files and libraries will be searched for in
# ${SQLite3_ROOT_DIR}/include
# ${SQLite3_ROOT_DIR}/libs
# respectively, and the default CMake search order will be ignored. When unspecified, the default
# CMake search order is used.
# This variable can be specified either as a CMake or environment variable. If both are set,
# preference is given to the CMake variable.
# Use this variable for finding packages installed in a nonstandard location, or for enforcing
# that one of multiple package installations is picked up.
#
#
# Cache variables (not intended to be used in CMakeLists.txt files)
#
# - SQLite3_INCLUDE_DIR: Absolute path to package headers.
# - SQLite3_LIBRARY: Absolute path to library.
#
#
# Output variables:
#
# - SQLite3_FOUND: Boolean that indicates if the package was found
# - SQLite3_INCLUDE_DIRS: Paths to the necessary header files
# - SQLite3_LIBRARIES: Package libraries
#
#
# Example usage:
#
# find_package(SQLite3)
# if(NOT SQLite3_FOUND)
# # Error handling
# endif()
# ...
# include_directories(${SQLite3_INCLUDE_DIRS} ...)
# ...
# target_link_libraries(my_target ${SQLite3_LIBRARIES})
#
##################################################################################################

# First attempt to find Config-file package
find_package(SQLite3 CONFIG QUIET)

if (NOT SQLite3_FOUND)


# Get package location hint from environment variable (if any)
if(NOT SQLite3_ROOT_DIR AND DEFINED ENV{SQLite3_ROOT_DIR})
set(SQLite3_ROOT_DIR "$ENV{SQLite3_ROOT_DIR}" CACHE PATH
"SQLite3 base directory location (optional, used for nonstandard installation paths)")
endif()

# Search path for nonstandard package locations
if(SQLite3_ROOT_DIR)
set(SQLite3_INCLUDE_PATH PATHS "${SQLite3_ROOT_DIR}/include" NO_DEFAULT_PATH)
set(SQLite3_LIBRARY_PATH PATHS "${SQLite3_ROOT_DIR}/lib" NO_DEFAULT_PATH)
endif()

# Find headers and libraries
find_path(SQLite3_INCLUDE_DIR NAMES sqlite3.h PATH_SUFFIXES "SQLite3" ${SQLite3_INCLUDE_PATH})
find_library(SQLite3_LIBRARY NAMES sqlite3 PATH_SUFFIXES "SQLite3" ${SQLite3_LIBRARY_PATH})

mark_as_advanced(SQLite3_INCLUDE_DIR
SQLite3_LIBRARY)

# Output variables generation
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(SQLite3 DEFAULT_MSG SQLite3_LIBRARY
SQLite3_INCLUDE_DIR)

set(SQLite3_FOUND ${SQLITE3_FOUND}) # Enforce case-correctness: Set appropriately cased variable...
unset(SQLITE3_FOUND) # ...and unset uppercase variable generated by find_package_handle_standard_args

if(SQLite3_FOUND)
set(SQLite3_INCLUDE_DIRS ${SQLite3_INCLUDE_DIR})
set(SQLite3_LIBRARIES ${SQLite3_LIBRARY})
endif()
endif()
15 changes: 15 additions & 0 deletions sqlite3_vendor/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>sqlite3_vendor</name>
<version>0.0.0</version>
<description>SQLite 3 vendor package</description>
<maintainer email="karsten.knese@googlemail.com">Karsten Knese</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>cmake</buildtool_depend>

<export>
<build_type>cmake</build_type>
</export>
</package>
10 changes: 10 additions & 0 deletions sqlite3_vendor/sqlite3_cmakelists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.5)
add_library(sqlite3 sqlite3.c)
set_target_properties(sqlite3 PROPERTIES
INSTALL_NAME_DIR ${CMAKE_INSTALL_PREFIX}/lib)

install(TARGETS sqlite3
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin)
install(FILES sqlite3.h sqlite3ext.h DESTINATION include)
13 changes: 13 additions & 0 deletions sqlite3_vendor/sqlite3_vendorConfig-version.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
set(PACKAGE_VERSION @PACKAGE_VERSION@)

set(PACKAGE_VERSION_EXACT False)
set(PACKAGE_VERSION_COMPATIBLE False)

if("${PACKAGE_FIND_VERSION}" VERSION_EQUAL "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_EXACT True)
set(PACKAGE_VERSION_COMPATIBLE True)
endif()

if("${PACKAGE_FIND_VERSION}" VERSION_LESS "${PACKAGE_VERSION}")
set(PACKAGE_VERSION_COMPATIBLE True)
endif()
13 changes: 13 additions & 0 deletions sqlite3_vendor/sqlite3_vendorConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# prevent multiple inclusion
if(_@PROJECT_NAME@_CONFIG_INCLUDED)
return()
endif()
set(_@PROJECT_NAME@_CONFIG_INCLUDED TRUE)

# output package information
if(NOT @PROJECT_NAME@_FIND_QUIETLY)
message(STATUS "Found @PROJECT_NAME@: @PACKAGE_VERSION@ (${@PROJECT_NAME@_DIR})")
endif()

# add the local Modules directory to the modules path, so FindSQLite3.cmake is considered.
list(INSERT CMAKE_MODULE_PATH 0 "${@PROJECT_NAME@_DIR}/Modules")

0 comments on commit 178477d

Please sign in to comment.