Commit 31af9f99 authored by Artem Shinkarov's avatar Artem Shinkarov
Browse files

Improved LIB_NEEDED by excluding c compiler builtin functions.

    This fixes a bug of not noticing the necessity to have -lm
    when compiling sacprelude.  The reason for this is that

    $ cat a.c
      #include <math.h>
        int main(void) {
        return log2(1.4);
      }
    $ gcc -Wall -Wextra -Werror -std=c99 a.c
    $ echo $?
    $ 0
    $ # success
    $ # whereas if we compile the same file like this:
    $ gcc -Wall -Wextra -Werror -std=c99 -fno-builtin -fno-builtin-function a.c
    $
    $/tmp/ccaHuGXn.o: In function `main':
    $a.c:(.text+0x1c): undefined reference to `log2'
    $collect2: error: ld returned 1 exit status
    $ echo $?
    $ 1
    $ # fail

    Therefore we want to include -fno-builtin whenever it is supported
    by the compiler.
Showing with 8 additions and 0 deletions
+8 -0
......@@ -38,6 +38,13 @@ ENDMACRO ()
# this function updates both the CMAKE_REQUIRED_LIBRARIES
# macro *and* the SAC2CRC_LIBS macro.
MACRO (LIB_NEEDED LIBNAME FUNCNAME SOURCE)
# Make sure that we exclude builtin function definitions in the GCC compiler
# by providing corresponding flags.
SET (OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
SET (NOBUILTIN_FLAGS "")
CHECK_CC_FLAG ("-fno-builtin" NOBUILTIN_FLAGS)
CHECK_CC_FLAG ("-fno-builtin-function" NOBUILTIN_FLAGS)
SET (CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror ${NOBUILTIN_FLAGS}")
CHECK_C_SOURCE_COMPILES ("${SOURCE}" ${LIBNAME}_COMPILE_TEST)
IF (NOT ${LIBNAME}_COMPILE_TEST)
CHECK_LIBRARY_EXISTS ("${LIBNAME}" "${FUNCNAME}" "" LIB_FOUND)
......@@ -55,6 +62,7 @@ MACRO (LIB_NEEDED LIBNAME FUNCNAME SOURCE)
ENDIF ()
ENDIF ()
UNSET (${LIBNAME}_COMPILE_TEST CACHE)
SET (CMAKE_REQUIRED_FLAGS "${OLD_CMAKE_REQUIRED_FLAGS}")
ENDMACRO ()
# Check if compiler `flag' is supported, and if so append it to the `var' string.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment