diff --git a/CMakeLists.txt b/CMakeLists.txt index 66dfe5f51..343369c9d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/README.md b/README.md index afe06bb8e..a08e99e2e 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/examples/android/app/CMakeLists.txt.in b/examples/android/app/CMakeLists.txt.in index 3212b0879..fe47c3584 100644 --- a/examples/android/app/CMakeLists.txt.in +++ b/examples/android/app/CMakeLists.txt.in @@ -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 diff --git a/examples/android/app/build.gradle.in b/examples/android/app/build.gradle.in index d945eb817..f43659593 100644 --- a/examples/android/app/build.gradle.in +++ b/examples/android/app/build.gradle.in @@ -21,13 +21,16 @@ android { // 2. OLP_SDK_HTTP_CLIENT_JAR - path to the OlpHttpClient.jar file; usually it stored in the /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@", diff --git a/examples/cmake/gen_android_example.cmake.in b/examples/cmake/gen_android_example.cmake.in index e33fea071..fc8fffcd0 100644 --- a/examples/cmake/gen_android_example.cmake.in +++ b/examples/cmake/gen_android_example.cmake.in @@ -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 diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 0231813a1..52ad44a2e 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt @@ -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. @@ -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) @@ -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) diff --git a/external/lmdb/CMakeLists-lmdb.txt b/external/lmdb/CMakeLists-lmdb.txt new file mode 100644 index 000000000..a1dfe3494 --- /dev/null +++ b/external/lmdb/CMakeLists-lmdb.txt @@ -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 + $ + $ +) + +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" +) \ No newline at end of file diff --git a/external/lmdb/CMakeLists.txt b/external/lmdb/CMakeLists.txt new file mode 100644 index 000000000..3d2808a39 --- /dev/null +++ b/external/lmdb/CMakeLists.txt @@ -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) diff --git a/external/lmdb/CMakeLists.txt.lmdb.in b/external/lmdb/CMakeLists.txt.lmdb.in new file mode 100644 index 000000000..b1d9f9ac7 --- /dev/null +++ b/external/lmdb/CMakeLists.txt.lmdb.in @@ -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= + -DCMAKE_BUILD_TYPE=@CMAKE_BUILD_TYPE@ + -DCMAKE_SYSTEM_PREFIX_PATH= + -DCMAKE_POSITION_INDEPENDENT_CODE=ON + TEST_COMMAND "" +) diff --git a/external/lmdb/lmdbConfig.cmake.in b/external/lmdb/lmdbConfig.cmake.in new file mode 100644 index 000000000..9508ddfda --- /dev/null +++ b/external/lmdb/lmdbConfig.cmake.in @@ -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") diff --git a/olp-cpp-sdk-core/CMakeLists.txt b/olp-cpp-sdk-core/CMakeLists.txt index 429fa279f..8b1276300 100644 --- a/olp-cpp-sdk-core/CMakeLists.txt +++ b/olp-cpp-sdk-core/CMakeLists.txt @@ -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) @@ -428,6 +432,17 @@ if(OLP_SDK_ENABLE_DEFAULT_CACHE) ) endif() +if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB) + target_include_directories(${PROJECT_NAME} + PRIVATE + $ + ) + target_link_libraries(${PROJECT_NAME} + PRIVATE + lmdb::lmdb + ) +endif() + if(IOS) if (CMAKE_GENERATOR MATCHES "Xcode") set_target_properties ( diff --git a/scripts/linux/psv/build_psv_no_cache.sh b/scripts/linux/psv/build_psv_no_cache.sh index f49fe7e2a..a70cfdc49 100755 --- a/scripts/linux/psv/build_psv_no_cache.sh +++ b/scripts/linux/psv/build_psv_no_cache.sh @@ -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 \ ..