From b6ae5627aa6d5321fb35e1db1197ac2a243ee5d1 Mon Sep 17 00:00:00 2001 From: HungMingWu Date: Thu, 17 May 2018 05:23:53 +0000 Subject: [PATCH] [leveldb] Fix build on linux --- ports/leveldb/CMakeLists.txt | 48 +++++++++++++++++++++++------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/ports/leveldb/CMakeLists.txt b/ports/leveldb/CMakeLists.txt index 73b082c4a..af2a4d09a 100644 --- a/ports/leveldb/CMakeLists.txt +++ b/ports/leveldb/CMakeLists.txt @@ -3,18 +3,24 @@ project(leveldb C CXX) option(INSTALL_HEADERS "Install header files" ON) +IF (MSVC) add_definitions( - -DWIN32 - -D_CRT_NONSTDC_NO_DEPRECATE - -D_SCL_SECURE_NO_WARNINGS - -D_CRT_SECURE_NO_WARNINGS - -DNOMINMAX - -DLEVELDB_ATOMIC_PRESENT - -DLEVELDB_PLATFORM_WINDOWS + -DWIN32 + -D_CRT_NONSTDC_NO_DEPRECATE + -D_SCL_SECURE_NO_WARNINGS + -D_CRT_SECURE_NO_WARNINGS + -DNOMINMAX + -DLEVELDB_PLATFORM_WINDOWS + -DLEVELDB_ATOMIC_PRESENT ) - -add_library(libleveldb - db/builder.cc +else () +add_definitions( + -DLEVELDB_PLATFORM_POSIX + -DLEVELDB_ATOMIC_PRESENT +) +endif() +set(SRCS + db/builder.cc db/c.cc db/dbformat.cc db/db_impl.cc @@ -31,7 +37,6 @@ add_library(libleveldb db/write_batch.cc helpers/memenv/memenv.cc port/port_posix_sse.cc - port/port_win.cc table/block.cc table/block_builder.cc table/filter_block.cc @@ -48,8 +53,6 @@ add_library(libleveldb util/comparator.cc util/crc32c.cc util/env.cc - util/env_posix.cc - util/env_win.cc util/filter_policy.cc util/hash.cc util/histogram.cc @@ -58,11 +61,22 @@ add_library(libleveldb util/status.cc ) -include_directories(${CMAKE_CURRENT_SOURCE_DIR} include) +if (MSVC) +set(SRCS ${SRCS} port/port_win.cc util/env_win.cc) +else () +set(SRCS ${SRCS} port/port_posix.cc util/env_posix.cc) +ENDIF() -target_link_libraries(libleveldb PUBLIC Iphlpapi.lib Shlwapi.lib) +add_library(leveldb ${SRCS}) -install(TARGETS libleveldb +target_include_directories(leveldb + PUBLIC include + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} +) + +target_link_libraries(leveldb PUBLIC Iphlpapi.lib Shlwapi.lib) + +install(TARGETS leveldb RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib @@ -72,4 +86,4 @@ if(INSTALL_HEADERS) file(GLOB HEADERS include/leveldb/*.h) install(FILES ${HEADERS} DESTINATION include/leveldb) install(FILES helpers/memenv/memenv.h DESTINATION include) -endif() \ No newline at end of file +endif()