[CMake] autoconf AC_REPLACE_FUNCS replacement for CMake

Thomas Klausner tk at giga.or.at
Fri Mar 2 07:46:07 EST 2007


Hi!

In autoconf there's a useful macro: AC_REPLACE_FUNCS.
It's called like:
	AC_REPLACE_FUNCS([fct1 fct2...])
It tests for the existence of the arguments, and if they
are missing, adds fct1.c (etc.) to the sources used for
building.

I wrote a replacement macro for CMake:
MACRO(REPLACE_FUNCTIONS sources)
  FOREACH(name ${ARGN})
    STRING(TOUPPER have_${name} SYMBOL_NAME)
    CHECK_FUNCTION_EXISTS(${name} ${SYMBOL_NAME})
    IF(NOT ${SYMBOL_NAME})
      SET(${sources} ${${sources}} ${name}.c)
    ENDIF(NOT ${SYMBOL_NAME})
  ENDFOREACH(name)
ENDMACRO(REPLACE_FUNCTIONS)

It's called like this:
REPLACE_FUNCTIONS(LIB_SOURCES err errx poll strlcpy warn warnx)
If the system doesn't provide err(), "err.c" is added to
LIB_SOURCES (and similarly for the other functions).

Feel free to use it for whatever you want.

Improvements are of course welcome too!

Cheers,
 Thomas


More information about the CMake mailing list