diff --git a/.gitignore b/.gitignore index a082f5a..3fa948b 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,18 @@ Debug Benchmark vs2010.* leveldbutil + +# Auto-generated by CMake +ALL_BUILD.vcxproj +ALL_BUILD.vcxproj.filters +CMakeCache.txt +CMakeFiles/ +ZERO_CHECK.vcxproj +ZERO_CHECK.vcxproj.filters +cmake_install.cmake +leveldb.opensdf +leveldb.sdf +leveldb.sln +leveldb.v12.suo +leveldb.vcxproj +leveldb.vcxproj.filters diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..3b0488e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,76 @@ +# +# Set CMake minimum version +cmake_minimum_required(VERSION 2.8) + +# +# Name the project +project(leveldb) + +add_definitions( + # Required for Windows port + -DLEVELDB_PLATFORM_WINDOWS + # Required for Windows port + -DOS_WIN + # Disable secure CRT warnings + -D_CRT_SECURE_NO_WARNINGS + # Disable "signed/unsigned mismatch" warning + -wd4018 + # Disable "conversion from 'uint64_t' to 'size_t'" warning + -wd4244 + # Disable "forcing value to bool 'true' or 'false'" warning + -wd4800 + # Disable "POSIX name for this item is deprecated" warning + -wd4996 + ) + +# +# Add include directories +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${CMAKE_CURRENT_SOURCE_DIR}/port/win +) + +# +# Add static library +add_library( + leveldb + db/builder.cc + db/c.cc + db/dbformat.cc + db/db_impl.cc + db/db_iter.cc + db/filename.cc + db/log_reader.cc + db/log_writer.cc + db/memtable.cc + db/repair.cc + db/table_cache.cc + db/version_edit.cc + db/version_set.cc + db/write_batch.cc + helpers/memenv/memenv.cc + port/port_win.cc + table/block.cc + table/block_builder.cc + table/filter_block.cc + table/format.cc + table/iterator.cc + table/merger.cc + table/table.cc + table/table_builder.cc + table/two_level_iterator.cc + util/arena.cc + util/bloom.cc + util/cache.cc + util/coding.cc + util/comparator.cc + util/crc32c.cc + util/env.cc + util/env_win.cc + util/filter_policy.cc + util/hash.cc + util/logging.cc + util/options.cc + util/status.cc + ) diff --git a/port/port_win.cc b/port/port_win.cc index 7cf9537..9d3628f 100755 --- a/port/port_win.cc +++ b/port/port_win.cc @@ -123,15 +123,6 @@ AtomicPointer::AtomicPointer(void* v) { Release_Store(v); } -BOOL CALLBACK InitHandleFunction (PINIT_ONCE InitOnce, PVOID func, PVOID *lpContext) { - ((void (*)())func)(); - return true; -} - -void InitOnce(OnceType* once, void (*initializer)()) { - InitOnceExecuteOnce((PINIT_ONCE)once, InitHandleFunction, initializer, NULL); -} - void* AtomicPointer::Acquire_Load() const { void * p = nullptr; InterlockedExchangePointer(&p, rep_); diff --git a/port/port_win.h b/port/port_win.h index c9e1cda..5a55172 100755 --- a/port/port_win.h +++ b/port/port_win.h @@ -93,10 +93,6 @@ class CondVar { }; -typedef void* OnceType; -#define LEVELDB_ONCE_INIT 0 -extern void InitOnce(port::OnceType*, void (*initializer)()); - // Storage for a lock-free pointer class AtomicPointer { private: diff --git a/port/win/stdint.h b/port/win/stdint.h index 39edd0d..f59e29e 100644 --- a/port/win/stdint.h +++ b/port/win/stdint.h @@ -21,4 +21,12 @@ typedef unsigned short uint16_t; typedef unsigned int uint32_t; typedef unsigned long long uint64_t; +#if defined(_WIN32) +typedef int32_t ssize_t; +#elif defined(_WIN64) +typedef int64_t ssize_t; +#else +#error "Unknown architecture" +#endif + #endif // STORAGE_LEVELDB_PORT_WIN_STDINT_H_ diff --git a/util/comparator.cc b/util/comparator.cc index 4b7b572..29fe6f4 100644 --- a/util/comparator.cc +++ b/util/comparator.cc @@ -66,15 +66,15 @@ class BytewiseComparatorImpl : public Comparator { }; } // namespace -static port::OnceType once = LEVELDB_ONCE_INIT; -static const Comparator* bytewise; - -static void InitModule() { - bytewise = new BytewiseComparatorImpl; +Comparator* GetSingleModule() +{ + static Comparator* bytewise = new BytewiseComparatorImpl(); + return bytewise; } +static const Comparator* bytewise = GetSingleModule(); + const Comparator* BytewiseComparator() { - port::InitOnce(&once, InitModule); return bytewise; } diff --git a/util/env_win.cc b/util/env_win.cc index 83d4363..219d3c3 100755 --- a/util/env_win.cc +++ b/util/env_win.cc @@ -1003,12 +1003,15 @@ Win32Env::~Win32Env() } // Win32 namespace -static port::OnceType once = LEVELDB_ONCE_INIT; -static Env* default_env; -static void InitDefaultEnv() { default_env = new Win32::Win32Env(); } +Env* GetSingleModule() +{ + static Env* default_env = new Win32::Win32Env(); + return default_env; +} + +static Env* default_env = GetSingleModule(); Env* Env::Default() { - port::InitOnce(&once, InitDefaultEnv); return default_env; } diff --git a/vs2010.vcxproj b/vs2010.vcxproj deleted file mode 100755 index 94c4cd9..0000000 --- a/vs2010.vcxproj +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - Debug - Win32 - - - Release - Win32 - - - Benchmark - Win32 - - - Debug - x64 - - - Release - x64 - - - Benchmark - x64 - - - - leveldb - leveldb - - - - StaticLibrary - - - Application - - - false - - - true - - - - - - - - - - - - LEVELDB_PLATFORM_WINDOWS;OS_WIN;_LIB;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) - .;.\include;.\port\win - - - - - NDEBUG;%(PreprocessorDefinitions) - MaxSpeed - true - Speed - Sync - true - false - Level3 - - - - - _DEBUG;%(PreprocessorDefinitions) - MultiThreadedDebugDLL - Level3 - ProgramDatabase - Disabled - - - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - $(Snappy);%(AdditionalIncludeDirectories) - SNAPPY;%(PreprocessorDefinitions) - - - - - - - - - - - - - - - - - - - shlwapi.lib;%(AdditionalDependencies) - - - - - - - \ No newline at end of file