fix cmake detection of libbsd

This commit is contained in:
Enno Rehling 2017-12-31 21:33:31 +01:00
parent a79e22984b
commit 9d8cfc422c
4 changed files with 36 additions and 7 deletions

View File

@ -7,6 +7,7 @@ script: s/travis-build
addons:
apt:
packages:
- libbsd-dev
- liblua5.1-dev
- libtolua-dev
- libncurses5-dev

View File

@ -11,9 +11,17 @@ if (MSVC)
include(MSVC)
endif (MSVC)
INCLUDE (CheckSymbolExists)
CHECK_SYMBOL_EXISTS(strlcat string.h HAVE_STRLCAT)
CHECK_SYMBOL_EXISTS(strdup string.h HAVE_STRDUP)
INCLUDE (CheckIncludeFile)
CHECK_INCLUDE_FILE(bsd/string.h HAVE_LIBBSD)
INCLUDE (CheckFunctionExists)
CHECK_FUNCTION_EXISTS(strdup HAVE_STRDUP)
IF (HAVE_LIBBSD)
INCLUDE (CheckLibraryExists)
CHECK_LIBRARY_EXISTS(bsd strlcat "bsd/string.h" HAVE_STRLCAT)
ELSE (HAVE_LIBBSD)
CHECK_FUNCTION_EXISTS(strlcat HAVE_STRLCAT)
ENDIF(HAVE_LIBBSD)
find_package (SQLite3)
find_package (BerkeleyDB)

View File

@ -267,14 +267,24 @@ add_test(server test_eressea)
install(TARGETS eressea DESTINATION "bin")
if (HAVE_LIBBSD)
add_definitions(-DHAVE_LIBBSD)
endif (HAVE_LIBBSD)
if (HAVE_STRLCAT)
add_definitions(-DHAVE_BSDSTRING)
endif(HAVE_STRLCAT)
endif (HAVE_STRLCAT)
if (HAVE_STRDUP)
add_definitions(-DHAVE_STRDUP)
endif(HAVE_STRDUP)
if (HAVE_LIBBSD)
target_link_libraries(test_eressea bsd)
target_link_libraries(eressea bsd)
target_link_libraries(convert bsd)
endif (HAVE_LIBBSD)
if (DB_FOUND)
include_directories (${DB_INCLUDE_DIR})
target_link_libraries(convert ${DB_LIBRARIES})

View File

@ -25,10 +25,15 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* libc includes */
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <stdlib.h>
#ifdef HAVE_LIBBSD
#include <bsd/string.h>
#else
#include <string.h>
#endif
size_t str_strlcpy(char *dst, const char *src, size_t len)
{
#ifdef HAVE_BSDSTRING
@ -232,10 +237,15 @@ unsigned int wang_hash(unsigned int a)
}
char *str_strdup(const char *s) {
#ifdef _MSC_VER
#ifdef HAVE_STRDUP
return strdup(s);
#elif defined(_MSC_VER)
return _strdup(s);
#else
return strdup(s);
size_t len = strlen(s);
char *dup = malloc(len+1);
memcpy(dup, s, len+1);
return dup;
#endif
}