[patches] [PATCH] Fix FreeBSD build
Konstantin Belyavskiy
k.belyavskiy at tarantool.org
Fri Mar 16 11:49:43 MSK 2018
Under FreeBSD getline prototype is not provided by
default due to compatibility problems.
So first check in CMake with check_function_exists to
make sure that getline provided by the system.
Then try to compile small code to test if declaration
is also available. If not declare function in code.
Closes #3217.
---
branch: gh-3217-enable-getline-prototype-freebsd
CMakeLists.txt | 18 ++++++++++++++++++
src/trivia/config.h.cmake | 6 ++++++
2 files changed, 24 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index d0cae0f01..86f5bd0d3 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -127,6 +127,24 @@ check_library_exists("" __libc_stack_end "" HAVE_LIBC_STACK_END)
check_function_exists(setproctitle HAVE_SETPROCTITLE)
check_function_exists(setprogname HAVE_SETPROGNAME)
check_function_exists(getprogname HAVE_GETPROGNAME)
+check_function_exists(getline HAVE_GETLINE)
+if (HAVE_GETLINE)
+ set(CMAKE_REQUIRED_FLAGS "-Werror")
+ check_c_source_compiles("
+ #include <stdio.h>
+ int main(void)
+ {
+ FILE *fp = NULL;
+ char *line = NULL;
+ size_t len = 0;
+ getline(&line, &len, fp);
+ return 0;
+ }
+ " HAVE_GETLINE_DECL)
+ set(CMAKE_REQUIRED_FLAGS "")
+else ()
+ message(FATAL_ERROR "getline is not provided by libraries on the system")
+endif ()
#
# Enable 'make tags' target.
diff --git a/src/trivia/config.h.cmake b/src/trivia/config.h.cmake
index 66ddba994..63c8856a9 100644
--- a/src/trivia/config.h.cmake
+++ b/src/trivia/config.h.cmake
@@ -42,6 +42,12 @@
#define TARANTOOL_LIBEXT "so"
#endif
+#cmakedefine HAVE_GETLINE_DECL
+#ifndef HAVE_GETLINE_DECL
+#include <stdio.h>
+extern ssize_t getline(char **lineptr, size_t *n, FILE *stream);;
+#endif
+
/**
* Defined if cpuid() instruction is available.
*/
--
2.14.3 (Apple Git-98)
More information about the Tarantool-patches
mailing list