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: addons:
apt: apt:
packages: packages:
- libbsd-dev
- liblua5.1-dev - liblua5.1-dev
- libtolua-dev - libtolua-dev
- libncurses5-dev - libncurses5-dev

View File

@ -11,9 +11,17 @@ if (MSVC)
include(MSVC) include(MSVC)
endif (MSVC) endif (MSVC)
INCLUDE (CheckSymbolExists) INCLUDE (CheckIncludeFile)
CHECK_SYMBOL_EXISTS(strlcat string.h HAVE_STRLCAT) CHECK_INCLUDE_FILE(bsd/string.h HAVE_LIBBSD)
CHECK_SYMBOL_EXISTS(strdup string.h HAVE_STRDUP)
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 (SQLite3)
find_package (BerkeleyDB) find_package (BerkeleyDB)

View File

@ -267,14 +267,24 @@ add_test(server test_eressea)
install(TARGETS eressea DESTINATION "bin") install(TARGETS eressea DESTINATION "bin")
if (HAVE_LIBBSD)
add_definitions(-DHAVE_LIBBSD)
endif (HAVE_LIBBSD)
if (HAVE_STRLCAT) if (HAVE_STRLCAT)
add_definitions(-DHAVE_BSDSTRING) add_definitions(-DHAVE_BSDSTRING)
endif(HAVE_STRLCAT) endif (HAVE_STRLCAT)
if (HAVE_STRDUP) if (HAVE_STRDUP)
add_definitions(-DHAVE_STRDUP) add_definitions(-DHAVE_STRDUP)
endif(HAVE_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) if (DB_FOUND)
include_directories (${DB_INCLUDE_DIR}) include_directories (${DB_INCLUDE_DIR})
target_link_libraries(convert ${DB_LIBRARIES}) 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 */ /* libc includes */
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h> #include <stdio.h>
#include <string.h>
#include <assert.h> #include <assert.h>
#include <stdlib.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) size_t str_strlcpy(char *dst, const char *src, size_t len)
{ {
#ifdef HAVE_BSDSTRING #ifdef HAVE_BSDSTRING
@ -232,10 +237,15 @@ unsigned int wang_hash(unsigned int a)
} }
char *str_strdup(const char *s) { char *str_strdup(const char *s) {
#ifdef _MSC_VER #ifdef HAVE_STRDUP
return strdup(s);
#elif defined(_MSC_VER)
return _strdup(s); return _strdup(s);
#else #else
return strdup(s); size_t len = strlen(s);
char *dup = malloc(len+1);
memcpy(dup, s, len+1);
return dup;
#endif #endif
} }