Skip to content

Commit

Permalink
[port] windows build
Browse files Browse the repository at this point in the history
  • Loading branch information
olegator77 committed May 13, 2018
1 parent 1868398 commit 58f82ed
Show file tree
Hide file tree
Showing 4 changed files with 816 additions and 11 deletions.
34 changes: 24 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,19 @@ target_sources(leveldb
)

# POSIX code is specified separately so we can leave it out in the future.

if (NOT WIN32)
target_sources(leveldb
PRIVATE
"${PROJECT_SOURCE_DIR}/util/env_posix.cc"
"${PROJECT_SOURCE_DIR}/util/posix_logger.h"
)
else ()
target_sources(leveldb
PRIVATE
"${PROJECT_SOURCE_DIR}/util/env_win.cc"
)
endif ()

# MemEnv is not part of the interface and could be pulled to a separate library.
target_sources(leveldb
Expand All @@ -195,9 +203,16 @@ target_compile_definitions(leveldb
PRIVATE
# Used by include/export.h when building shared libraries.
LEVELDB_COMPILE_LIBRARY
# Used by port/port.h.
LEVELDB_PLATFORM_POSIX=1
)

if (NOT WIN32)
set(PLATFORM_DEFINITIONS LEVELDB_PLATFORM_POSIX=1)
else (NOT WIN32)
set(PLATFORM_DEFINITIONS LEVELDB_PLATFORM_WINDOWS=1 OS_WIN=1 _CRT_SECURE_NO_WARNINGS=1)
endif (NOT WIN32)

target_compile_definitions(leveldb PRIVATE ${PLATFORM_DEFINITIONS})

if (NOT HAVE_CXX17_HAS_INCLUDE)
target_compile_definitions(leveldb
PRIVATE
Expand Down Expand Up @@ -228,6 +243,9 @@ endif(HAVE_SNAPPY)
if(HAVE_TCMALLOC)
target_link_libraries(leveldb tcmalloc)
endif(HAVE_TCMALLOC)
if(WIN32)
target_link_libraries(leveldb shlwapi dbghelp)
endif()

# Needed by port_stdcxx.h
find_package(Threads REQUIRED)
Expand Down Expand Up @@ -256,10 +274,7 @@ if(LEVELDB_BUILD_TESTS)
"${test_file}"
)
target_link_libraries("${test_target_name}" leveldb)
target_compile_definitions("${test_target_name}"
PRIVATE
LEVELDB_PLATFORM_POSIX=1
)
target_compile_definitions("${test_target_name}" PRIVATE ${PLATFORM_DEFINITIONS})
if (NOT HAVE_CXX17_HAS_INCLUDE)
target_compile_definitions("${test_target_name}"
PRIVATE
Expand Down Expand Up @@ -307,7 +322,9 @@ if(LEVELDB_BUILD_TESTS)

# TODO(costan): This test also uses
# "${PROJECT_SOURCE_DIR}/util/env_posix_test_helper.h"
if (NOT WIN32)
leveldb_test("${PROJECT_SOURCE_DIR}/util/env_posix_test.cc")
endif (NOT WIN32)
endif(NOT BUILD_SHARED_LIBS)
endif(LEVELDB_BUILD_TESTS)

Expand All @@ -329,10 +346,7 @@ if(LEVELDB_BUILD_BENCHMARKS)
"${bench_file}"
)
target_link_libraries("${bench_target_name}" leveldb)
target_compile_definitions("${bench_target_name}"
PRIVATE
LEVELDB_PLATFORM_POSIX=1
)
target_compile_definitions("${bench_target_name}" PRIVATE ${PLATFORM_DEFINITIONS})
if (NOT HAVE_CXX17_HAS_INCLUDE)
target_compile_definitions("${bench_target_name}"
PRIVATE
Expand Down
11 changes: 11 additions & 0 deletions port/atomic_pointer.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@
#include <atomic>

#ifdef OS_WIN
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <windows.h>

#ifdef _MSC_VER
namespace leveldb {
typedef intptr_t ssize_t;
}
#endif
#undef DeleteFile
#undef small
#endif

#if defined(_M_X64) || defined(__x86_64__)
Expand Down
2 changes: 1 addition & 1 deletion port/port.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// Include the appropriate platform specific file below. If you are
// porting to a new platform, see "port_example.h" for documentation
// of what the new port_<platform>.h file must provide.
#if defined(LEVELDB_PLATFORM_POSIX)
#if defined(LEVELDB_PLATFORM_POSIX) || defined(LEVELDB_PLATFORM_WINDOWS)
# include "port/port_stdcxx.h"
#elif defined(LEVELDB_PLATFORM_CHROMIUM)
# include "port/port_chromium.h"
Expand Down
Loading

0 comments on commit 58f82ed

Please sign in to comment.