summaryrefslogtreecommitdiff
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorcmumford <cmumford@google.com>2019-03-01 13:12:01 -0800
committerVictor Costan <pwnall@chromium.org>2019-03-01 18:00:35 -0800
commitc69d33b0ec3dad2a8063ad66da9d51a1d6309f4e (patch)
treeb3ef286b0a30952d87aebd111e161cda94b52563 /CMakeLists.txt
parentfe4494804f5e3a2e25485d32aeb0eb7d2f25732e (diff)
downloadleveldb-c69d33b0ec3dad2a8063ad66da9d51a1d6309f4e.tar.gz
Added native support for Windows.
This change adds a native Windows port (port_windows.h) and a Windows Env (WindowsEnv). Note1: "small" is defined when including <Windows.h> so some parameters were renamed to avoid conflict. Note2: leveldb::Env defines the method: "DeleteFile" which is also a constant defined when including <Windows.h>. The solution was to ensure this macro is defined in env.h which forces the function, when compiled, to be either DeleteFileA or DeleteFileW when building for MBCS or UNICODE respectively. This resolves #519 on GitHub. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=236364778
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt31
1 files changed, 25 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f6a7c0a..1eaf48e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -15,6 +15,14 @@ set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
+if (WIN32)
+ set(LEVELDB_PLATFORM_NAME LEVELDB_PLATFORM_WINDOWS)
+ # TODO(cmumford): Make UNICODE configurable for Windows.
+ add_definitions(-D_UNICODE -DUNICODE)
+else (WIN32)
+ set(LEVELDB_PLATFORM_NAME LEVELDB_PLATFORM_POSIX)
+endif (WIN32)
+
option(LEVELDB_BUILD_TESTS "Build LevelDB's unit tests" ON)
option(LEVELDB_BUILD_BENCHMARKS "Build LevelDB's benchmarks" ON)
option(LEVELDB_INSTALL "Install LevelDB's header and library" ON)
@@ -179,12 +187,19 @@ target_sources(leveldb
"${LEVELDB_PUBLIC_INCLUDE_DIR}/write_batch.h"
)
-# POSIX code is specified separately so we can leave it out in the future.
+if (WIN32)
+target_sources(leveldb
+ PRIVATE
+ "${PROJECT_SOURCE_DIR}/util/env_windows.cc"
+ "${PROJECT_SOURCE_DIR}/util/windows_logger.h"
+)
+else (WIN32)
target_sources(leveldb
PRIVATE
"${PROJECT_SOURCE_DIR}/util/env_posix.cc"
"${PROJECT_SOURCE_DIR}/util/posix_logger.h"
)
+endif (WIN32)
# MemEnv is not part of the interface and could be pulled to a separate library.
target_sources(leveldb
@@ -203,7 +218,7 @@ target_compile_definitions(leveldb
# Used by include/export.h when building shared libraries.
LEVELDB_COMPILE_LIBRARY
# Used by port/port.h.
- LEVELDB_PLATFORM_POSIX=1
+ ${LEVELDB_PLATFORM_NAME}=1
)
if (NOT HAVE_CXX17_HAS_INCLUDE)
target_compile_definitions(leveldb
@@ -265,7 +280,7 @@ if(LEVELDB_BUILD_TESTS)
target_link_libraries("${test_target_name}" leveldb)
target_compile_definitions("${test_target_name}"
PRIVATE
- LEVELDB_PLATFORM_POSIX=1
+ ${LEVELDB_PLATFORM_NAME}=1
)
if (NOT HAVE_CXX17_HAS_INCLUDE)
target_compile_definitions("${test_target_name}"
@@ -314,8 +329,12 @@ if(LEVELDB_BUILD_TESTS)
leveldb_test("${PROJECT_SOURCE_DIR}/util/logging_test.cc")
# TODO(costan): This test also uses
- # "${PROJECT_SOURCE_DIR}/util/env_posix_test_helper.h"
- leveldb_test("${PROJECT_SOURCE_DIR}/util/env_posix_test.cc")
+ # "${PROJECT_SOURCE_DIR}/util/env_{posix|windows}_test_helper.h"
+ if (WIN32)
+ leveldb_test("${PROJECT_SOURCE_DIR}/util/env_windows_test.cc")
+ else (WIN32)
+ leveldb_test("${PROJECT_SOURCE_DIR}/util/env_posix_test.cc")
+ endif (WIN32)
endif(NOT BUILD_SHARED_LIBS)
endif(LEVELDB_BUILD_TESTS)
@@ -339,7 +358,7 @@ if(LEVELDB_BUILD_BENCHMARKS)
target_link_libraries("${bench_target_name}" leveldb)
target_compile_definitions("${bench_target_name}"
PRIVATE
- LEVELDB_PLATFORM_POSIX=1
+ ${LEVELDB_PLATFORM_NAME}=1
)
if (NOT HAVE_CXX17_HAS_INCLUDE)
target_compile_definitions("${bench_target_name}"