[CMake] [RFC] cmake analog to AC_SEARCH_LIBS

Игорь Пашев pashev.igor at gmail.com
Mon Sep 9 08:43:48 EDT 2013


Having two variables is an advantage over autoconf:

HAVE_FOO is true if the function is found at all
FOO_LIB is a library where foo is found.

HAVE_FOO may be true, but FOO_LIB is empty, if the function foo is in libc

I can add ${FOO_LIB} to targets where I need foo; with autotools the
library containing foo
is added to all targets.


Here is how I use it:

CMAKE_SEARCH_LIBS (HAVE_DLADDR LIB_DLADDR dladdr dl)
if (NOT HAVE_DLADDR)
    message (FATAL_ERROR "Cannot find library providing dladdr()")
endif()

CMAKE_SEARCH_LIBS (HAVE_PTHREAD_JOIN LIB_PTHREAD pthread_join pthread)
if (NOT HAVE_PTHREAD_JOIN)
    message (FATAL_ERROR "Cannot find library providing pthread_join()")
endif()

MY_LINK_LIBRARIES (aaa
    ${LIB_DLADDR}
    ${LIB_PTHREAD}
    dwarf
    lzma
    )

2013/9/9 Stewart, Robert <Robert.Stewart at sig.com>:
> Игорь Пашев wrote:
>>
>> Hi, all. I'm using this macro to get AC_SEARCH_LIBS (from GNU
>> autoconf) functionality with CMake.
>>
>> First of all, this macro searhes the function on libc, then,
>> if not found, in the given libraries. It sets two variables:
>> 1) boolean if function  found
>> 2) string - in which library (may be empty).
>>
>> I'd like this macro to be in standard cmake set.
>
> Regardless of anything else in your proposal, why the two result
> variables?  It seems to me that setting the string when found,
> and clearing it when not, serves both purposes.  When the string
> is empty, the function wasn't found.
>
>> MACRO (CMAKE_SEARCH_LIBS v_func v_lib func)
>
> (I don't know what the "v_" prefix means, but I presume that those
> arguments are the outputs, so perhaps "v_" means "supply the name
> of a variable to set.")  With my variation, the interface would
> work like the following:
>
> CMAKE_SEARCH_LIBS(library my_function)
> IF(library)
>    # found my_function's library
> ENDIF()
>
>
> _____
> Rob Stewart
> Software Engineer
> Dev Tools & Components
> Susquehanna International Group, LLP
>
> ________________________________
>
> IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.


More information about the CMake mailing list