Skip to content

Commit 6c08481

Browse files
committed
Add LMDB to external libraries.
lmdb is added to external libraries. CMakeLists.txt.lmdb.in and lmdbConfig.cmake.in was created for lmdb. Changes in olp-cpp-sdk-core and external CMakeLists.txt was made. Added OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB option to be able to enable/disable build of lmdb. README.md was changed with description of a new flag. Resolves: OLPEDGE-2645 Signed-off-by: Yevhen Krasilnyk <ext-yevhen.krasilnyk@here.com>
1 parent 25c48da commit 6c08481

File tree

8 files changed

+197
-1
lines changed

8 files changed

+197
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ option(OLP_SDK_BUILD_EXAMPLES "Enable examples targets" OFF)
4343
option(OLP_SDK_MSVC_PARALLEL_BUILD_ENABLE "Enable parallel build on MSVC" ON)
4444
option(OLP_SDK_DISABLE_DEBUG_LOGGING "Disable debug and trace level logging" OFF)
4545
option(OLP_SDK_ENABLE_DEFAULT_CACHE "Enable default cache implementation" ON)
46+
option(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB "Enable default cache implementation based on LMDB" OFF)
4647

4748
# C++ standard version. Minimum supported version is 11.
4849
set(CMAKE_CXX_STANDARD 11)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ cmake --build . --target docs
186186
| `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. |
187187
| `OLP_SDK_DISABLE_DEBUG_LOGGING`| Defaults to `OFF`. If enabled, the debug and trace level log messages are not printed. |
188188
| `OLP_SDK_ENABLE_DEFAULT_CACHE `| Defaults to `ON`. If enabled, the default cache implementation based on the LevelDB backend is enabled. |
189+
| `OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB `| Defaults to `OFF`. If enabled, the default cache implementation based on the LMDB backend is enabled. |
189190

190191
## Use the SDK
191192

external/CMakeLists.txt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2019-2020 HERE Europe B.V.
1+
# Copyright (C) 2019-2021 HERE Europe B.V.
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -54,6 +54,9 @@ set(OLP_SDK_CPP_RAPIDJSON_TAG "master")
5454
set(OLP_SDK_CPP_BOOST_URL "https://github.com/boostorg/boost.git")
5555
set(OLP_SDK_CPP_BOOST_TAG "boost-1.72.0")
5656

57+
set(OLP_SDK_CPP_LMDB_URL "https://github.com/LMDB/lmdb.git")
58+
set(OLP_SDK_CPP_LMDB_TAG "LMDB_0.9.29")
59+
5760
# Add external projects
5861
find_package(GTest QUIET)
5962
if(NOT TARGET GTest AND NOT GTest_FOUND)
@@ -75,6 +78,14 @@ if(OLP_SDK_ENABLE_DEFAULT_CACHE)
7578
endif()
7679
endif()
7780

81+
if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB)
82+
find_package(lmdb QUIET)
83+
if(NOT TARGET lmdb AND NOT lmdb_FOUND)
84+
add_subdirectory(lmdb)
85+
set(lmdb_INCLUDE_DIR ${EXTERNAL_lmdb_INCLUDE_DIR} PARENT_SCOPE)
86+
endif()
87+
endif()
88+
7889
find_package(Boost QUIET)
7990
if(NOT TARGET Boost AND NOT Boost_FOUND)
8091
add_subdirectory(boost)

external/lmdb/CMakeLists-lmdb.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright (C) 2021 HERE Europe B.V.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# License-Filename: LICENSE
17+
18+
cmake_minimum_required(VERSION 3.9)
19+
20+
project(lmdb VERSION 0.9.29 LANGUAGES C)
21+
22+
set(CMAKE_C_STANDARD 11)
23+
set(CMAKE_C_STANDARD_REQUIRED ON)
24+
set(CMAKE_C_EXTENSIONS OFF)
25+
26+
set(LMDB_SOURCE_DIR "libraries/liblmdb")
27+
28+
add_library(lmdb "")
29+
30+
target_sources(lmdb
31+
PRIVATE
32+
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/lmdb.h"
33+
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/mdb.c"
34+
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/midl.c"
35+
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/midl.h"
36+
)
37+
38+
target_include_directories(lmdb
39+
PUBLIC
40+
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
41+
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
42+
)
43+
44+
include(GNUInstallDirs)
45+
install(TARGETS lmdb
46+
EXPORT lmdbTargets
47+
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
48+
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
49+
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
50+
)
51+
install(
52+
FILES
53+
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/lmdb.h"
54+
"${PROJECT_SOURCE_DIR}/${LMDB_SOURCE_DIR}/midl.h"
55+
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/lmdb
56+
)
57+
install(
58+
EXPORT lmdbTargets
59+
NAMESPACE lmdb::
60+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/lmdb"
61+
)
62+
install(
63+
FILES
64+
"${PROJECT_SOURCE_DIR}/cmake/lmdbConfig.cmake"
65+
DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/lmdb"
66+
)

external/lmdb/CMakeLists.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Copyright (C) 2021 HERE Europe B.V.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# License-Filename: LICENSE
17+
18+
# Download and unpack lmdb at configure time
19+
configure_file(CMakeLists.txt.lmdb.in download/CMakeLists.txt)
20+
21+
execute_process(COMMAND ${CMAKE_COMMAND} -G "${CMAKE_GENERATOR}" . ${COMMON_GENERATE_FLAGS}
22+
RESULT_VARIABLE result
23+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/download)
24+
if(result)
25+
message(FATAL_ERROR "CMake step for lmdb failed: ${result}")
26+
endif()
27+
28+
# Copy CMakeLists
29+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists-lmdb.txt
30+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/config/lmdb)
31+
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/config/lmdb/CMakeLists-lmdb.txt
32+
${CMAKE_CURRENT_BINARY_DIR}/config/lmdb/CMakeLists.txt)
33+
34+
# Copy lmdbConfig.cmake
35+
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/lmdbConfig.cmake.in
36+
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/config/lmdb/cmake)
37+
file(RENAME ${CMAKE_CURRENT_BINARY_DIR}/config/lmdb/cmake/lmdbConfig.cmake.in
38+
${CMAKE_CURRENT_BINARY_DIR}/config/lmdb/cmake/lmdbConfig.cmake)
39+
40+
execute_process(COMMAND ${CMAKE_COMMAND} --build . --config ${CMAKE_BUILD_TYPE}
41+
RESULT_VARIABLE result
42+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/download)
43+
if(result)
44+
message(FATAL_ERROR "Build step for lmdb failed: ${result}")
45+
endif()
46+
47+
# Provide the dir to the lmdb cmake configuration files
48+
set(EXTERNAL_lmdb_INCLUDE_DIR ${EXTERNAL_BINARY_INSTALL_DIR}/include PARENT_SCOPE)

external/lmdb/CMakeLists.txt.lmdb.in

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (C) 2021 HERE Europe B.V.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# License-Filename: LICENSE
17+
18+
cmake_minimum_required(VERSION 3.9)
19+
20+
project(lmdb-download NONE)
21+
22+
include(ExternalProject)
23+
24+
ExternalProject_Add(lmdb
25+
GIT_REPOSITORY @OLP_SDK_CPP_LMDB_URL@
26+
GIT_TAG @OLP_SDK_CPP_LMDB_TAG@
27+
GIT_SHALLOW 1
28+
INSTALL_DIR "@EXTERNAL_BINARY_INSTALL_DIR@"
29+
PATCH_COMMAND "${CMAKE_COMMAND}" -E copy_directory "${CMAKE_CURRENT_BINARY_DIR}/config/lmdb" "${CMAKE_CURRENT_BINARY_DIR}/download/lmdb-prefix/src/lmdb/."
30+
CMAKE_ARGS @COMMON_PLATFORM_FLAGS@
31+
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
32+
-DCMAKE_BUILD_TYPE=@CMAKE_BUILD_TYPE@
33+
-DCMAKE_SYSTEM_PREFIX_PATH=<INSTALL_DIR>
34+
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
35+
TEST_COMMAND ""
36+
)

external/lmdb/lmdbConfig.cmake.in

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (C) 2021 HERE Europe B.V.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
#
15+
# SPDX-License-Identifier: Apache-2.0
16+
# License-Filename: LICENSE
17+
18+
include("${CMAKE_CURRENT_LIST_DIR}/lmdbTargets.cmake")

olp-cpp-sdk-core/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ if(OLP_SDK_ENABLE_DEFAULT_CACHE)
2828
find_package(leveldb REQUIRED)
2929
endif()
3030

31+
if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB)
32+
find_package(lmdb REQUIRED)
33+
endif()
34+
3135
configure_file(./include/olp/core/Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/olp/core/Config.h)
3236

3337
include(configs/ConfigNetwork.cmake)
@@ -428,6 +432,17 @@ if(OLP_SDK_ENABLE_DEFAULT_CACHE)
428432
)
429433
endif()
430434

435+
if(OLP_SDK_ENABLE_DEFAULT_CACHE_LMDB)
436+
target_include_directories(${PROJECT_NAME}
437+
PRIVATE
438+
$<BUILD_INTERFACE:${lmdb_INCLUDE_DIR}>
439+
)
440+
target_link_libraries(${PROJECT_NAME}
441+
PRIVATE
442+
lmdb::lmdb
443+
)
444+
endif()
445+
431446
if(IOS)
432447
if (CMAKE_GENERATOR MATCHES "Xcode")
433448
set_target_properties (

0 commit comments

Comments
 (0)