Skip to content

Commit e132523

Browse files
Add a new option OLP_SDK_ENABLE_DEFAULT_CACHE (#1181)
The new options is enabled by default. In case it is disabled explicitly by the user, it's users responsibility to provide cache implementation that implements the olp::cache::KayValueCache interface. Relates-To: OLPEDGE-2373 Signed-off-by: Mykhailo Kuchma <[email protected]>
1 parent 0c8a1a0 commit e132523

File tree

10 files changed

+126
-16
lines changed

10 files changed

+126
-16
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,16 @@ jobs:
3434
run: ./scripts/linux/psv/test_psv.sh
3535
shell: bash
3636

37+
linux-gcc-psv-build-no-cache:
38+
name: Linux Build using gcc & tests & code coverage
39+
runs-on: ubuntu-18.04
40+
steps:
41+
42+
- name: Check out repository
43+
uses: actions/checkout@v2
44+
- name: Install Ubuntu dependencies
45+
run: sudo apt-get install -y libboost-all-dev ccache libssl-dev libcurl4-openssl-dev --no-install-recommends
46+
shell: bash
47+
- name: Compile project without cache
48+
run: ./scripts/linux/psv/build_psv_no_cache.sh
49+
shell: bash

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ option(OLP_SDK_BUILD_EXTERNAL_DEPS "Download and build external dependencies" ON
4242
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)
45+
option(OLP_SDK_ENABLE_DEFAULT_CACHE "Enable default cache implementation" ON)
4546

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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ cmake --build . --target docs
185185
| `OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL` | Defaults to `OFF`. When `OLP_SDK_NO_EXCEPTION` is `ON`, `boost` requires `boost::throw_exception()` to be defined. If enabled, the external definition of `boost::throw_exception()` is used. Otherwise, the library uses own definition. |
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 will not be printed. |
188+
| `OLP_SDK_ENABLE_DEFAULT_CACHE `| Defaults to `ON`. If enabled, The default cache implementation based on leveldb backend is enabled. |
188189

189190
## Use the SDK
190191

external/CMakeLists.txt

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,14 @@ if(NOT TARGET RapidJSON AND NOT RapidJSON_FOUND)
6565
add_subdirectory(rapidjson)
6666
endif()
6767

68-
find_package(leveldb QUIET)
69-
if(NOT TARGET leveldb AND NOT leveldb_FOUND)
70-
add_subdirectory(leveldb)
71-
set(leveldb_DIR ${EXTERNAL_leveldb_DIR} PARENT_SCOPE)
72-
set(leveldb_INCLUDE_DIR ${EXTERNAL_leveldb_INCLUDE_DIR} PARENT_SCOPE)
73-
set(Snappy_DIR ${EXTERNAL_Snappy_DIR} PARENT_SCOPE)
68+
if(OLP_SDK_ENABLE_DEFAULT_CACHE)
69+
find_package(leveldb QUIET)
70+
if(NOT TARGET leveldb AND NOT leveldb_FOUND)
71+
add_subdirectory(leveldb)
72+
set(leveldb_DIR ${EXTERNAL_leveldb_DIR} PARENT_SCOPE)
73+
set(leveldb_INCLUDE_DIR ${EXTERNAL_leveldb_INCLUDE_DIR} PARENT_SCOPE)
74+
set(Snappy_DIR ${EXTERNAL_Snappy_DIR} PARENT_SCOPE)
75+
endif()
7476
endif()
7577

7678
find_package(Boost QUIET)

olp-cpp-sdk-core/CMakeLists.txt

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ set(DESCRIPTION "Core network and utility library for the HERE OLP SDK C++")
2121

2222
find_package(RapidJSON 1.1.0 REQUIRED CMAKE_FIND_ROOT_PATH_BOTH)
2323
find_package(Boost REQUIRED)
24-
find_package(leveldb REQUIRED)
25-
find_package(Snappy REQUIRED)
2624
find_package(Threads REQUIRED)
2725

26+
if(OLP_SDK_ENABLE_DEFAULT_CACHE)
27+
find_package(Snappy REQUIRED)
28+
find_package(leveldb REQUIRED)
29+
endif()
30+
31+
configure_file(./include/olp/core/Config.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/olp/core/Config.h)
32+
2833
include(configs/ConfigNetwork.cmake)
2934
include(cmake/CompileChecks.cmake)
3035

@@ -180,6 +185,10 @@ set(OLP_SDK_GEOTYPE_HEADER
180185
./include/olp/core/geo/Types.h
181186
)
182187

188+
set(OLP_SDK_CONFIG_HEADER
189+
${CMAKE_CURRENT_BINARY_DIR}/include/olp/core/Config.h
190+
)
191+
183192
set(OLP_SDK_MATH_HEADERS
184193
./include/olp/core/math/AlignedBox.h
185194
./include/olp/core/math/Math.h
@@ -343,10 +352,10 @@ set(OLP_SDK_CORE_HEADERS
343352
${OLP_SDK_GEOTILING_HEADERS}
344353
${OLP_SDK_COREAPI_HEADERS}
345354
${OLP_SDK_GEOTYPE_HEADER}
355+
${OLP_SDK_CONFIG_HEADER}
346356
)
347357

348358
set(OLP_SDK_CORE_SOURCES
349-
${OLP_SDK_CACHE_SOURCES}
350359
${OLP_SDK_CLIENT_SOURCES}
351360
${OLP_SDK_HTTP_SOURCES}
352361
${OLP_SDK_PLATFORM_SOURCES}
@@ -356,12 +365,12 @@ set(OLP_SDK_CORE_SOURCES
356365
${OLP_SDK_GEO_SOURCES}
357366
)
358367

359-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
360-
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
368+
if(OLP_SDK_ENABLE_DEFAULT_CACHE)
369+
set(OLP_SDK_CORE_SOURCES ${OLP_SDK_CORE_SOURCES} ${OLP_SDK_CACHE_SOURCES})
370+
endif()
361371

362372
add_library(${PROJECT_NAME} ${OLP_SDK_CORE_SOURCES} ${OLP_SDK_CORE_HEADERS})
363373

364-
365374
if (OLP_SDK_DISABLE_DEBUG_LOGGING)
366375
target_compile_definitions(${PROJECT_NAME}
367376
PUBLIC LOGGING_DISABLE_DEBUG_LEVEL)
@@ -385,7 +394,6 @@ target_include_directories(${PROJECT_NAME} PUBLIC
385394
$<BUILD_INTERFACE:${RapidJSON_INCLUDE_DIRS}>
386395
$<BUILD_INTERFACE:${RAPIDJSON_INCLUDE_DIRS}>
387396

388-
$<BUILD_INTERFACE:${leveldb_INCLUDE_DIR}>
389397
$<INSTALL_INTERFACE:include>)
390398

391399
if (ANDROID)
@@ -404,10 +412,19 @@ target_link_libraries(${PROJECT_NAME}
404412
${OLP_SDK_NETWORK_CURL_LIBRARIES}
405413
${NETWORK_WINHTTP_LIBRARIES}
406414
${CMAKE_THREAD_LIBS_INIT}
407-
PRIVATE
408-
leveldb::leveldb
409415
)
410416

417+
if(OLP_SDK_ENABLE_DEFAULT_CACHE)
418+
target_include_directories(${PROJECT_NAME}
419+
PUBLIC
420+
$<BUILD_INTERFACE:${leveldb_INCLUDE_DIR}>
421+
)
422+
target_link_libraries(${PROJECT_NAME}
423+
PRIVATE
424+
leveldb::leveldb
425+
)
426+
endif()
427+
411428
if(IOS)
412429
if (CMAKE_GENERATOR MATCHES "Xcode")
413430
set_target_properties (
@@ -475,8 +492,9 @@ install (FILES ${OLP_SDK_GEOCOORDINATES_HEADERS} DESTINATION ${INCLUDE_DIRECTORY
475492
install (FILES ${OLP_SDP_GEOPROJECTION_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/olp/core/geo/projection)
476493
install (FILES ${OLP_SDK_GEOTILING_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/olp/core/geo/tiling)
477494
install (FILES ${OLP_SDK_LOGGING_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/olp/core/logging)
478-
install (FILES ${OLP_SDK_COREAPI_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/olp/core/)
495+
install (FILES ${OLP_SDK_COREAPI_HEADERS} DESTINATION ${INCLUDE_DIRECTORY}/olp/core)
479496
install (FILES ${OLP_SDK_GEOTYPE_HEADER} DESTINATION ${INCLUDE_DIRECTORY}/olp/core/geo)
497+
install (FILES ${OLP_SDK_CONFIG_HEADER} DESTINATION ${INCLUDE_DIRECTORY}/olp/core)
480498

481499
export_config()
482500

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

olp-cpp-sdk-core/include/olp/core/cache/CacheSettings.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,18 @@
2121

2222
#include <string>
2323

24+
#include <olp/core/Config.h>
25+
2426
#include <olp/core/CoreApi.h>
27+
2528
#include <olp/core/porting/deprecated.h>
2629
#include <boost/optional.hpp>
2730

2831
namespace olp {
2932
namespace cache {
3033

34+
#ifdef OLP_SDK_ENABLE_DEFAULT_CACHE
35+
3136
/**
3237
* @brief Options for opening a disk cache.
3338
*/
@@ -152,5 +157,14 @@ struct CORE_API CacheSettings {
152157
boost::optional<std::string> disk_path_protected = boost::none;
153158
};
154159

160+
#else
161+
162+
/**
163+
* @brief Dummy settings for default cache factory.
164+
*/
165+
struct CORE_API CacheSettings {};
166+
167+
#endif // OLP_SDK_ENABLE_DEFAULT_CACHE
168+
155169
} // namespace cache
156170
} // namespace olp

olp-cpp-sdk-core/include/olp/core/cache/DefaultCache.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,12 @@
2323
#include <mutex>
2424
#include <string>
2525

26+
#include <olp/core/Config.h>
2627
#include "CacheSettings.h"
2728
#include "KeyValueCache.h"
2829

30+
#ifdef OLP_SDK_ENABLE_DEFAULT_CACHE
31+
2932
namespace olp {
3033
namespace cache {
3134

@@ -273,3 +276,5 @@ class CORE_API DefaultCache : public KeyValueCache {
273276

274277
} // namespace cache
275278
} // namespace olp
279+
280+
#endif // OLP_SDK_ENABLE_DEFAULT_CACHE

olp-cpp-sdk-core/src/client/OlpClientSettingsFactory.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "olp/core/client/OlpClientSettingsFactory.h"
2121

22+
#include "olp/core/Config.h"
2223
#include "olp/core/cache/CacheSettings.h"
2324
#include "olp/core/cache/DefaultCache.h"
2425
#include "olp/core/client/OlpClientSettings.h"
@@ -47,6 +48,7 @@ OlpClientSettingsFactory::CreateDefaultNetworkRequestHandler(
4748

4849
std::unique_ptr<cache::KeyValueCache>
4950
OlpClientSettingsFactory::CreateDefaultCache(cache::CacheSettings settings) {
51+
#ifdef OLP_SDK_ENABLE_DEFAULT_CACHE
5052
auto cache = std::make_unique<cache::DefaultCache>(std::move(settings));
5153
auto error = cache->Open();
5254
if (error == cache::DefaultCache::StorageOpenResult::OpenDiskPathFailure) {
@@ -59,6 +61,11 @@ OlpClientSettingsFactory::CreateDefaultCache(cache::CacheSettings settings) {
5961
return nullptr;
6062
}
6163
return cache;
64+
#else
65+
OLP_SDK_CORE_UNUSED(settings);
66+
OLP_SDK_LOG_FATAL(kLogTag, "Default cache implementation is disabled.");
67+
return nullptr;
68+
#endif // OLP_SDK_ENABLE_DEFAULT_CACHE
6269
}
6370

6471
void OlpClientSettingsFactory::PrewarmConnection(
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash -ex
2+
#
3+
# Copyright (C) 2021 HERE Europe B.V.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# SPDX-License-Identifier: Apache-2.0
18+
# License-Filename: LICENSE
19+
20+
mkdir -p build
21+
cd build
22+
23+
cmake \
24+
-DOLP_SDK_ENABLE_TESTING=OFF \
25+
-DOLP_SDK_ENABLE_DEFAULT_CACHE=OFF \
26+
-DBUILD_SHARED_LIBS=ON \
27+
..
28+
29+
cmake --build . -- -j$(nproc)

0 commit comments

Comments
 (0)