strndup polyfill for cmake

This commit is contained in:
c9s 2014-06-18 20:47:06 +08:00
parent 8ebaac0536
commit a697301c44
4 changed files with 21 additions and 2 deletions

View file

@ -15,7 +15,9 @@ SET(CMAKE_MODULE_PATH
${CMAKE_MODULE_PATH}
)
include_directories(. "${PROJECT_SOURCE_DIR}/include" ${INCLUDE_DIRECTORIES} /opt/local/include)
include_directories(. ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/3rdparty /opt/local/include)
# include_directories(. ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/3rdparty ${PROJECT_SOURCE_DIR})
link_directories(${LINK_DIRECTORIES} /opt/local/lib)
find_package(PCRE REQUIRED)
find_package(Judy REQUIRED)

View file

@ -22,6 +22,19 @@ void str_repeat(char *s, const char *c, int len);
void print_indent(int level);
#if _GNU_SOURCE || POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700 || __DARWIN_C_LEVEL >= 200809L
#define HAVE_STRNDUP
#endif
#if _SVID_SOURCE || _BSD_SOURCE \
|| _XOPEN_SOURCE >= 500 \
|| _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED \
|| /* Since glibc 2.12: */ _POSIX_C_SOURCE >= 200809L \
|| __DARWIN_C_LEVEL >= 200809L
#define HAVE_STRDUP
#endif
#ifndef HAVE_STRDUP
char *strdup(const char *s);
#endif

View file

@ -1,4 +1,4 @@
include_directories("${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/3rdparty ${PROJECT_SOURCE_DIR}")
# install(TARGETS swiftnav-static DESTINATION lib${LIB_SUFFIX})
set(libr3_SRCS node.c edge.c list.c slug.c str.c token.c)

View file

@ -207,6 +207,8 @@ void print_indent(int level) {
}
}
#ifndef HAVE_STRDUP
char *zstrdup(const char *s) {
char *out;
@ -222,6 +224,8 @@ char *zstrdup(const char *s) {
}
#endif
#ifndef HAVE_STRNDUP
char *zstrndup(const char *s, int n) {
char *out;