find_package(leveldb REQUIRED) in cmake project does not search for Threads and snappy
- Dominant language
- C++
- Stars
- 39.4k
- Forks
- 8.2k
- PR merge metrics
- No merged PRs in 30d
Description
I have a cmake project that depends on leveldb. In my CMakeLists.txt I have this:
```
find_package(leveldb REQUIRED)
...
add_executable(myexe ${MYEXE_SOURCE})
target_link_libraries(myexe leveldb::leveldb)
```
which leads to the following link errors:
```
/usr/bin/ld: cannot find -lsnappy
/usr/bin/ld: cannot find -lThreads::Threads
```
I can get rid of the second error by adding `find_package(Threads REQUIRED)`, though this is not the correct way for cmake to handle dependencies: leveldb's cmake config should pull the libraries it needs by itself. For snappy, leveldb should not be asking me to link against it since it did not find when it was built.
I'm not a cmake expert but I think this problem should be solved by (1) having a proper `find_package` for snappy (as indicated [in this issue](https://github.com/google/leveldb/issues/685)) and (2) adding proper calls to `find_dependency` in [this file](https://github.com/google/leveldb/blob/master/cmake/leveldbConfig.cmake.in) (`find_dependency` will look at whether `find_package` was called with `REQUIRED` and whether the dependency was wound, and add the dependency if needed).
For now I had to resort to using cmake's PkgConfig module to find leveldb, as follows:
```
find_package (PkgConfig REQUIRED)
pkg_check_modules (leveldb REQUIRED IMPORTED_TARGET leveldb)
...
target_link_libraries(myexe PkgConfig::leveldb)
```
Contributor guide
Assessment
This issue has not been assessed yet.