Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Test lmdb #1259

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ option(OLP_SDK_BUILD_EXTERNAL_DEPS "Download and build external dependencies" ON
option(OLP_SDK_BUILD_EXAMPLES "Enable examples targets" OFF)
option(OLP_SDK_MSVC_PARALLEL_BUILD_ENABLE "Enable parallel build on MSVC" ON)
option(OLP_SDK_DISABLE_DEBUG_LOGGING "Disable debug and trace level logging" OFF)
option(OLP_SDK_ENABLE_DEFAULT_CACHE "Enable default cache implementation" ON)
option(OLP_SDK_ENABLE_DEFAULT_CACHE "Enable default cache implementation based on LevelDB" OFF)
option(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB "Enable default cache implementation based on LMDB" ON)

# C++ standard version. Minimum supported version is 11.
set(CMAKE_CXX_STANDARD 11)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ cmake --build . --target docs
| `OLP_SDK_MSVC_PARALLEL_BUILD_ENABLE` (Windows Only) | Defaults to `ON`. If enabled, the `/MP` compilation flag is added to build the Data SDK using multiple cores. |
| `OLP_SDK_DISABLE_DEBUG_LOGGING`| Defaults to `OFF`. If enabled, the debug and trace level log messages are not printed. |
| `OLP_SDK_ENABLE_DEFAULT_CACHE `| Defaults to `ON`. If enabled, the default cache implementation based on the LevelDB backend is enabled. |
| `OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB `| Defaults to `OFF`. If enabled, the default cache implementation based on the LMDB backend is enabled. |

## Use the SDK

Expand Down
4 changes: 4 additions & 0 deletions examples/android/app/CMakeLists.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ find_package(olp-cpp-sdk-dataservice-write REQUIRED)
find_package(leveldb REQUIRED)
find_package(Threads REQUIRED)

if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB)
find_package(lmdb REQUIRED)
endif()

add_library(@OLP_SDK_EXAMPLE_TARGET_NAME@ SHARED
${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/Examples.h
${CMAKE_CURRENT_SOURCE_DIR}/src/main/cpp/ReadExample.h
Expand Down
5 changes: 4 additions & 1 deletion examples/android/app/build.gradle.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ android {
// 2. OLP_SDK_HTTP_CLIENT_JAR - path to the OlpHttpClient.jar file; usually it stored in the <olp-build-folder>/olp-cpp-sdk-core/
// 3. (If not installed to the sysroot) path to the levelDB library:
// - leveldb_DIR;
// 4. (If not installed to the sysroot) - path to the OLP SDK cmake config files:
// 4. (If not installed to the sysroot) path to the lmdb library:
// - lmdb_DIR;
// 5. (If not installed to the sysroot) - path to the OLP SDK cmake config files:
// - olp-cpp-sdk-core_DIR;
// - olp-cpp-sdk-dataservice-write_DIR;
// - olp-cpp-sdk-authentication_DIR
arguments "@OLP_SDK_EXAMPLE_ANDROID_TOOLCHAIN_FILE@",
"@OLP_SDK_EXAMPLE_HTTP_CLIENT_JAR@",
"@OLP_SDK_EXAMPLE_LEVELDB_DIR@",
"@OLP_SDK_EXAMPLE_LMDB_DIR@",
// required for finding installed packages in sysroot
"-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=BOTH",
"-DBOOST_ROOT=@BOOST_ROOT@",
Expand Down
7 changes: 7 additions & 0 deletions examples/cmake/gen_android_example.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ function(gen_android_example_application
if (DEFINED leveldb_DIR)
set(OLP_SDK_EXAMPLE_LEVELDB_DIR "-Dleveldb_DIR=${leveldb_DIR}")
endif()

if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB)
set(OLP_SDK_EXAMPLE_LMDB_DIR "-Dlmdb_DIR='path to the directory which contains LMDB cmake config files'")
if (DEFINED lmdb_DIR)
set(OLP_SDK_EXAMPLE_LMDB_DIR "-Dlmdb_DIR=${lmdb_DIR}")
endif()
endif()

configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/android/app/build.gradle.in
Expand Down
14 changes: 13 additions & 1 deletion external/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (C) 2019-2020 HERE Europe B.V.
# Copyright (C) 2019-2021 HERE Europe B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,6 +54,9 @@ set(OLP_SDK_CPP_RAPIDJSON_TAG "master")
set(OLP_SDK_CPP_BOOST_URL "https://github.com/boostorg/boost.git")
set(OLP_SDK_CPP_BOOST_TAG "boost-1.72.0")

set(OLP_SDK_CPP_LMDB_URL "https://github.com/LMDB/lmdb.git")
set(OLP_SDK_CPP_LMDB_TAG "LMDB_0.9.29")

# Add external projects
find_package(GTest QUIET)
if(NOT TARGET GTest AND NOT GTest_FOUND)
Expand All @@ -75,6 +78,15 @@ if(OLP_SDK_ENABLE_DEFAULT_CACHE)
endif()
endif()

if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB)
find_package(lmdb QUIET)
if(NOT TARGET lmdb AND NOT lmdb_FOUND)
add_subdirectory(lmdb)
set(lmdb_DIR ${EXTERNAL_lmdb_DIR} PARENT_SCOPE)
set(lmdb_INCLUDE_DIR ${EXTERNAL_lmdb_INCLUDE_DIR} PARENT_SCOPE)
endif()
endif()

find_package(Boost QUIET)
if(NOT TARGET Boost AND NOT Boost_FOUND)
add_subdirectory(boost)
Expand Down
66 changes: 66 additions & 0 deletions external/lmdb/CMakeLists-lmdb.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright (C) 2021 HERE Europe B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# License-Filename: LICENSE

cmake_minimum_required(VERSION 3.9)

project(lmdb VERSION 0.9.29 LANGUAGES C)

set(CMAKE_C_STANDARD 11)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)

set(LMDB_SOURCE_DIR "libraries/liblmdb")

add_library(lmdb "")

target_sources(lmdb
PRIVATE
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/lmdb.h"
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/mdb.c"
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/midl.c"
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/midl.h"
)

target_include_directories(lmdb
PUBLIC
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

include(GNUInstallDirs)
install(TARGETS lmdb
EXPORT lmdbTargets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
install(
FILES
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/lmdb.h"
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/midl.h"
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lmdb
)
install(
EXPORT lmdbTargets
NAMESPACE lmdb::
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/lmdb"
)
install(
FILES
"${PROJECT_SOURCE_DIR}/cmake/lmdbConfig.cmake"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/lmdb"
)
49 changes: 49 additions & 0 deletions external/lmdb/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright (C) 2021 HERE Europe B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# License-Filename: LICENSE

# Download and unpack lmdb at configure time
configure_file(CMakeLists.txt.lmdb.in download/CMakeLists.txt)

execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . ${COMMON_GENERATE_FLAGS}
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/download)
if(result)
message(FATAL_ERROR "CMake step for lmdb failed: ${result}")
endif()

# Copy CMakeLists
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists-lmdb.txt
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/config/lmdb)
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/config/lmdb/CMakeLists-lmdb.txt
${CMAKE_CURRENT_BINARY_DIR}/config/lmdb/CMakeLists.txt)

# Copy lmdbConfig.cmake
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/lmdbConfig.cmake.in
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/config/lmdb/cmake)
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/config/lmdb/cmake/lmdbConfig.cmake.in
${CMAKE_CURRENT_BINARY_DIR}/config/lmdb/cmake/lmdbConfig.cmake)

execute_process(COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE}
RESULT_VARIABLE result
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/download)
if(result)
message(FATAL_ERROR "Build step for lmdb failed: ${result}")
endif()

# Provide the dir to the lmdb cmake configuration files
set(EXTERNAL_lmdb_DIR ${EXTERNAL_BINARY_INSTALL_DIR}/lib/cmake/lmdb PARENT_SCOPE)
set(EXTERNAL_lmdb_INCLUDE_DIR ${EXTERNAL_BINARY_INSTALL_DIR}/include PARENT_SCOPE)
36 changes: 36 additions & 0 deletions external/lmdb/CMakeLists.txt.lmdb.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (C) 2021 HERE Europe B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# License-Filename: LICENSE

cmake_minimum_required(VERSION 3.9)

project(lmdb-download NONE)

include(ExternalProject)

ExternalProject_Add(lmdb
GIT_REPOSITORY @OLP_SDK_CPP_LMDB_URL@
GIT_TAG @OLP_SDK_CPP_LMDB_TAG@
GIT_SHALLOW 1
INSTALL_DIR "@EXTERNAL_BINARY_INSTALL_DIR@"
PATCH_COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_BINARY_DIR}/config/lmdb" "${CMAKE_CURRENT_BINARY_DIR}/download/lmdb-prefix/src/lmdb/."
CMAKE_ARGS @COMMON_PLATFORM_FLAGS@
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
-DCMAKE_BUILD_TYPE=@CMAKE_BUILD_TYPE@
-DCMAKE_SYSTEM_PREFIX_PATH=<INSTALL_DIR>
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
TEST_COMMAND ""
)
18 changes: 18 additions & 0 deletions external/lmdb/lmdbConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (C) 2021 HERE Europe B.V.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
# License-Filename: LICENSE

include("${CMAKE_CURRENT_LIST_DIR}/lmdbTargets.cmake")
15 changes: 15 additions & 0 deletions olp-cpp-sdk-core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ if(OLP_SDK_ENABLE_DEFAULT_CACHE)
find_package(leveldb REQUIRED)
endif()

if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB)
find_package(lmdb REQUIRED)
endif()

configure_file(./include/olp/core/Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/olp/core/Config.h)

include(configs/ConfigNetwork.cmake)
Expand Down Expand Up @@ -428,6 +432,17 @@ if(OLP_SDK_ENABLE_DEFAULT_CACHE)
)
endif()

if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB)
target_include_directories(${PROJECT_NAME}
PRIVATE
$<BUILD_INTERFACE:${lmdb_INCLUDE_DIR}>
)
target_link_libraries(${PROJECT_NAME}
PRIVATE
lmdb::lmdb
)
endif()

if(IOS)
if (CMAKE_GENERATOR MATCHES "Xcode")
set_target_properties (
Expand Down
1 change: 1 addition & 0 deletions scripts/linux/psv/build_psv_no_cache.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cd build
cmake \
-DOLP_SDK_ENABLE_TESTING=OFF \
-DOLP_SDK_ENABLE_DEFAULT_CACHE=OFF \
-DOLP_SDK_ENABLE_DEFAULT_CACHE_LMDB=OFF \
-DBUILD_SHARED_LIBS=ON \
..

Expand Down