Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@ only the RocksDB library:
```

With CMake, `find_package(RocksDB CONFIG)` resolves the **enabled** library, because the archive
ships one CMake package and it describes `lib/`. To take the other one, override the imported
target's location after importing it:
ships one CMake package and it describes `lib/`. The package resolves its own zlib, including the
`zs.lib` that vcpkg installs on Windows, so no `ZLIB_USE_STATIC_LIBS` or other preparation is needed
on any target. To take the other library, override the imported target's location after importing
it:

```cmake
find_package(RocksDB CONFIG REQUIRED)
Expand Down
24 changes: 24 additions & 0 deletions vcpkg-overlays/rocksdb/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,30 @@ vcpkg_cmake_install()

vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/rocksdb)

# vcpkg installs the static zlib under a name FindZLIB does not search by default (zs.lib on
# Windows), so the shipped package could not resolve its own dependency. Naming the files is what
# vcpkg's own zlib wrapper does. MODULE because RocksDBTargets links ZLIB::ZLIB, which only
# FindZLIB defines; the zlib package installed beside it exports ZLIB::ZLIBSTATIC.
set(rocksdb_config "${CURRENT_PACKAGES_DIR}/share/rocksdb/RocksDBConfig.cmake")
file(READ "${rocksdb_config}" rocksdb_config_text)
set(zlib_anchor "find_dependency(ZLIB)")
string(FIND "${rocksdb_config_text}" "${zlib_anchor}" zlib_anchor_at)
if(zlib_anchor_at EQUAL -1)
message(FATAL_ERROR "No ${zlib_anchor} in ${rocksdb_config}; the archived zlib would be unresolvable")
endif()
# The prefix comes from the config's own location: PACKAGE_PREFIX_DIR holds one of the dependency
# prefixes by this point on CMake 3.29 and older. The header is pinned alongside the library so the
# two cannot come from different installations; a miss leaves FindZLIB its own search, as before.
string(REPLACE "${zlib_anchor}" "if(NOT ZLIB_LIBRARY)
get_filename_component(_rocksdb_prefix \"\${CMAKE_CURRENT_LIST_DIR}/../..\" ABSOLUTE)
find_path(ZLIB_INCLUDE_DIR NAMES zlib.h PATHS \"\${_rocksdb_prefix}/include\" NO_DEFAULT_PATH)
find_library(ZLIB_LIBRARY_RELEASE NAMES zs z PATHS \"\${_rocksdb_prefix}/lib\" NO_DEFAULT_PATH)
find_library(ZLIB_LIBRARY_DEBUG NAMES zsd zd z PATHS \"\${_rocksdb_prefix}/debug/lib\" NO_DEFAULT_PATH)
unset(_rocksdb_prefix)
endif()
find_dependency(ZLIB MODULE)" rocksdb_config_text "${rocksdb_config_text}")
Comment thread
cb1kenobi marked this conversation as resolved.
file(WRITE "${rocksdb_config}" "${rocksdb_config_text}")

vcpkg_copy_pdbs()

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/include")
Expand Down
Loading