I have some legacy code (building against the mysql embedded server library) which contains a link line that looks like this:
-L/usr/local/lib -lmysqld -lm -ldl -lcrypt -lpthread
I know that I can get a list of supported cmake modules with cmake --help-module-list
, but how do know which modules contains the libraries libm.a, libdl.a, etc.?
I know that I could use link_directories(/usr/local/lib)
to specify that location, and just put -lm, -ldl, etc. into my target_link_libraries
command, but the docs seem to discourage that - that using find_library
or find_package
is desirable.
I can probably muddle through putting together something with find_library that will work with all our target platforms, but if these libraries are already defined in an existing package, I think that would be the most desirable way to do it.
So, the general question is: given some known libraries, how to I locate the relevant cmake package that contains them?
EDIT: There seems to be some confusion about what I'm asking. I understand that find_package
doesn't actually "contain" the libraries, but it serves as platform-independent way of locating the libraries for common configurations. For example, in my case above, I found in another SO question that I could deal with the pthread library by using this construction:
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
target_link_libraries(my_app Threads::Threads)
But how was I supposed to know this? Is there a way I can discover this for myself without asking SO questions and hoping someone can answer it for me? And what should I use for the other libraries (m, dl, crypt, etc.).