[CMake] [RFC] cmake analog to AC_SEARCH_LIBS

Игорь Пашев pashev.igor at gmail.com
Fri Sep 6 16:22:08 EDT 2013


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.

CMakeLists.txt:

INCLUDE (CheckFunctionExists)
INCLUDE (CheckLibraryExists)

MACRO (CMAKE_SEARCH_LIBS v_func v_lib func)
    CHECK_FUNCTION_EXISTS (${func} ${v_func})
    IF (NOT ${v_func})
        FOREACH (lib ${ARGN})
            CHECK_LIBRARY_EXISTS (${lib} ${func} "" "HAVE_${func}_IN_${lib}")
            IF ("HAVE_${func}_IN_${lib}")
                SET (${v_func} TRUE)
                SET (${v_lib} "${lib}" CACHE INTERNAL "Library
providing ${func}")
                BREAK()
            ENDIF ("HAVE_${func}_IN_${lib}")
        ENDFOREACH (lib)
    ENDIF (NOT ${v_func})
ENDMACRO (CMAKE_SEARCH_LIBS)


CMAKE_SEARCH_LIBS (HAVE_FORKPTY FORKPTY_LIB forkpty aaa util bbb)
CMAKE_SEARCH_LIBS (HAVE_SENDFILE SENDFILE_LIB sendfile sendfile)


# cmake .
-- The C compiler identification is GNU 4.7.3
-- The CXX compiler identification is GNU 4.7.3
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Looking for forkpty
-- Looking for forkpty - not found
-- Looking for forkpty in aaa
-- Looking for forkpty in aaa - not found
-- Looking for forkpty in util
-- Looking for forkpty in util - found
-- Looking for sendfile
-- Looking for sendfile - found
-- Configuring done
-- Generating done
-- Build files have been written to: /home/pashev/tmp


More information about the CMake mailing list