facebook / facebook/rocksdb

Missing dependencies for exported CMake targets in installed configuration file

Open
#6,692 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
32.1k
Forks
6.9k
Avg merge
32m
Merged PRs (30d)
1

Description

### Steps to reproduce the behavior

* Prepare an environment with required dependencies installed. (I was using Archlinux with dependencies installed using `sudo pacman -Syu bzip2 gcc-libs gflags jemalloc lz4 snappy zlib zstd`)

* Build RocksDB from current master HEAD with the following commands:
```
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX= -DWITH_BZ2=ON -DWITH_LZ4=ON -DWITH_SNAPPY=ON -DWITH_ZLIB=ON -DWITH_ZSTD=ON -DUSE_RTTI=ON -DWITH_JEMALLOC=ON -DFAIL_ON_WARNINGS=OFF -DPORTABLE=ON -DWITH_BENCHMARK_TOOLS=OFF
cmake --build . --config Release
cmake --install . --config Release
```

* Write a test project with a `CMakeLists.txt` of the following content:

```
cmake_minimum_required(VERSION 3.10 FATAL_ERROR)

cmake_policy(SET CMP0074 NEW)

project(test_proj1)

find_package(RocksDB CONFIG REQUIRED)

add_executable(test1 test1.cpp)
target_link_libraries(test1 RocksDB::rocksdb-shared)
```

* Configure the test project with the following command:

```
cmake -DRocksDB_ROOT= -DCMAKE_BUILD_TYPE=Release
```

### Expected behavior

The test project should be configured successfully without errors

### Actual behavior

CMake reports dependency missing error when configuring the test project:

```
CMake Error at CMakeLists.txt:9 (add_executable):
Target "test1" links to target "JeMalloc::JeMalloc" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?

CMake Error at CMakeLists.txt:9 (add_executable):
Target "test1" links to target "gflags::gflags" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?

CMake Error at CMakeLists.txt:9 (add_executable):
Target "test1" links to target "snappy::snappy" but the target was not
found. Perhaps a find_package() call is missing for an IMPORTED target, or
an ALIAS target is missing?

CMake Error at CMakeLists.txt:9 (add_executable):
Target "test1" links to target "ZLIB::ZLIB" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?

CMake Error at CMakeLists.txt:9 (add_executable):
Target "test1" links to target "lz4::lz4" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?

CMake Error at CMakeLists.txt:9 (add_executable):
Target "test1" links to target "zstd::zstd" but the target was not found.
Perhaps a find_package() call is missing for an IMPORTED target, or an
ALIAS target is missing?

-- Generating done
CMake Generate step failed. Build files cannot be regenerated correctly.
```

### Additional Info

The root cause seems to be those dependency targets being exported as interface link libraries of rocksdb, as shown in `lib/cmake/rocksdb/RocksDBTargets.cmake`, yet there's no steps in the configuration files to acutallly find those dependencies. I'm not sure about the original intention why the configuration files are designed like so, but I do want to mention that it is intended in CMake that package configuration file should handle dependencies on its own, if package providers want to encapsule package together with its dependencies.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.