Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find_package(leveldb REQUIRED) in cmake project does not search for Threads and snappy #920

Open
mdorier opened this issue Jul 8, 2021 · 0 comments

Comments

@mdorier
Copy link

mdorier commented Jul 8, 2021

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) and (2) adding proper calls to find_dependency in this file (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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant