Skip to content
This repository was archived by the owner on Oct 28, 2021. It is now read-only.

Commit efcef82

Browse files
committed
CMake: Add option to link leveldb statically
Use -DLEVELDB_USE_STATIC_LIBS=ON to request this.
1 parent 082f126 commit efcef82

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

circle.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ jobs:
132132
- GENERATOR: Ninja
133133
- BUILD_PARALLEL_JOBS: 8
134134
- TEST_PARALLEL_JOBS: 8
135-
- CMAKE_OPTIONS: -DALETH_INTERPRETER_SHARED=ON -DSTATIC_LIBSTDCPP=ON
135+
- CMAKE_OPTIONS: -DALETH_INTERPRETER_SHARED=ON -DSTATIC_LIBSTDCPP=ON -DLEVELDB_USE_STATIC_LIBS=ON
136136
docker:
137137
- image: ethereum/cpp-build-env:2
138138
steps:

cmake/FindLevelDB.cmake

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,25 @@ find_path(
1616
DOC "leveldb include dir"
1717
)
1818

19+
if(LEVELDB_USE_STATIC_LIBS)
20+
set(names ${CMAKE_STATIC_LIBRARY_PREFIX}leveldb${CMAKE_STATIC_LIBRARY_SUFFIX})
21+
else()
22+
set(names leveldb)
23+
endif()
24+
1925
find_library(
2026
LEVELDB_LIBRARY
21-
NAMES leveldb
27+
NAMES ${names}
2228
DOC "leveldb library"
2329
)
2430

2531
set(LEVELDB_INCLUDE_DIRS ${LEVELDB_INCLUDE_DIR})
2632
set(LEVELDB_LIBRARIES ${LEVELDB_LIBRARY})
2733

28-
# When we're static linking (at least on OS X), leveldb also drags in snappy.
29-
# This might be due to some dependency within leveldb which would be dead-code
30-
# stripped if we were using a static lib for leveldb. We aren't (yet), because
31-
# we only have partial static-linkage on OS X so far.
32-
if (NOT BUILD_SHARED_LIBS AND APPLE)
34+
# When linking statically we should include also the snappy static lib.
35+
if(LEVELDB_LIBRARY MATCHES ${CMAKE_STATIC_LIBRARY_SUFFIX})
3336
find_path(SNAPPY_INCLUDE_DIR snappy.h PATH_SUFFIXES snappy)
34-
find_library(SNAPPY_LIBRARY snappy)
37+
find_library(SNAPPY_LIBRARY ${CMAKE_STATIC_LIBRARY_PREFIX}snappy${CMAKE_STATIC_LIBRARY_SUFFIX})
3538
set(LEVELDB_INCLUDE_DIRS ${LEVELDB_INCLUDE_DIR} ${SNAPPY_INCLUDE_DIR})
3639
set(LEVELDB_LIBRARIES ${LEVELDB_LIBRARY} ${SNAPPY_LIBRARY})
3740
endif()
@@ -58,4 +61,3 @@ include(FindPackageHandleStandardArgs)
5861
find_package_handle_standard_args(leveldb DEFAULT_MSG
5962
LEVELDB_LIBRARY LEVELDB_INCLUDE_DIR)
6063
mark_as_advanced (LEVELDB_INCLUDE_DIR LEVELDB_LIBRARY)
61-

0 commit comments

Comments
 (0)