Skip to content

Commit

Permalink
BUILD: Support cmake
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Wielemaker authored and Jan Wielemaker committed Sep 21, 2018
1 parent a36c644 commit 47c905c
Show file tree
Hide file tree
Showing 22 changed files with 290 additions and 48 deletions.
99 changes: 99 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
cmake_minimum_required(VERSION 2.8.12)
project(swipl-clib)

include("../cmake/PrologPackage.cmake")
include(Sockets)
find_package(LibUUID)

check_function_exists(crypt HAVE_CRYPT)
if(NOT HAVE_CRYPT)
check_library_exists(crypt crypt "" HAVE_LIBCRYPT)
if(HAVE_LIBCRYPT)
set(CRYPT_LIBS -lcrypt)
else()
set(CRYPT_SOURCE bsd-crypt.c)
endif()
endif()

check_function_exists(syslog HAVE_SYSLOG)

AC_CHECK_HEADERS(malloc.h alloca.h unistd.h sys/time.h fcntl.h
utime.h execinfo.h sys/resource.h crypt.h syslog.h
sys/types.h sys/wait.h sys/stat.h sys/prctl.h
netinet/tcp.h crt_externs.h poll.h)

check_type_size("long" SIZEOF_LONG)
check_type_size("long long" SIZEOF_LONG_LONG)

AC_CHECK_FUNCS(setsid strerror utime getrlimit strcasestr vfork _NSGetEnviron
pipe2 prctl sysconf poll initgroups setgroups chmod
mallinfo malloc_info open_memstream)

configure_file(config.h.cmake config.h)

################
# Setup the targets

swipl_plugin(cgi C_SOURCES error.c form.c cgi.c PL_LIBS cgi.pl)
swipl_plugin(memfile C_SOURCES error.c memfile.c PL_LIBS memfile.pl)
swipl_plugin(time C_SOURCES error.c time.c PL_LIBS time.pl)
swipl_plugin(files C_SOURCES error.c files.c PL_LIBS filesex.pl)
swipl_plugin(process C_SOURCES error.c process.c PL_LIBS process.pl)
swipl_plugin(streaminfo C_SOURCES error.c streaminfo.c PL_LIBS streaminfo.pl)
if(HAVE_MALLINFO)
swipl_plugin(mallocinfo C_SOURCES error.c mallocinfo.c PL_LIBS mallocinfo.pl)
endif()

swipl_plugin(uri C_SOURCES uri.c PL_LIBS uri.pl)
swipl_plugin(readutil C_SOURCES readutil.c PL_LIBS)
swipl_plugin(prolog_stream C_SOURCES prolog_stream.c PL_LIBS prolog_stream.pl)
swipl_plugin(md54pl C_SOURCES md54pl.c md5.c PL_LIBS md5.pl)

if(UNIX)
swipl_plugin(unix C_SOURCES error.c unix.c PL_LIBS unix.pl)
swipl_plugin(uid C_SOURCES error.c uid.c PL_LIBS uid.pl)
swipl_plugin(rlimit C_SOURCES error.c rlimit.c PL_LIBS rlimit.pl)
swipl_plugin(syslog C_SOURCES syslog.c PL_LIBS syslog.pl)
endif(UNIX)

if(LIBUUID_FOUND)
swipl_plugin(uuid
C_SOURCES uuid.c
C_LIBS ${UUID_LIBRARY}
PL_LIBS uuid.pl)
target_include_directories(plugin_uuid BEFORE PRIVATE
${LIBUUID_INCLUDE_DIR})
endif()

swipl_plugin(crypt
C_SOURCES error.c crypt.c md5.c md5passwd.c ${CRYPT_SOURCE}
C_LIBS ${CRYPT_LIBS}
PL_LIBS crypt.pl)
swipl_plugin(hashstream
C_SOURCES hash_stream.c md5.c sha1/sha1.c sha1/sha2.c
PL_LIBS hash_stream.pl)
swipl_plugin(sha4pl
C_SOURCES error.c sha4pl.c sha1/sha1.c sha1/sha2.c
sha1/hmac_sha1.c sha1/hmac_sha256.c
PL_LIBS sha.pl)

if(HAVE_SOCKET)
swipl_plugin(
socket
C_SOURCES error.c socket.c nonblockio.c
C_LIBS ${SOCKET_LIBRARIES}
PL_LIBS socket.pl streampool.pl prolog_server.pl udp_broadcast.pl)
endif(HAVE_SOCKET)

################
# Tests

test_libs(cgi crypt memfile process readutil socket stream time uri)

################
# Documentation

pkg_doc(clib
SOURCES process.pl uri.pl filesex.pl uid.pl udp_broadcast.pl
uuid.pl unix.pl syslog.pl socket.pl prolog_stream.pl md5.pl
hash_stream.pl)
2 changes: 1 addition & 1 deletion bsd-crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/

/* JW: Added to make this file compile as-is for SWI-Prolog */
#define __RCSID(s) static char sccsid[] = s
#define __RCSID(s) /*static char sccsid[] = s*/
#define DES_ONLY
#define CRYPT_ONLY
static int des_setkey(const char *key);
Expand Down
34 changes: 34 additions & 0 deletions cmake/FindLibUUID.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
find_package(PkgConfig QUIET)
pkg_check_modules(PC_LIBUUID QUIET ossp-uuid)

find_path(LIBUUID_INCLUDE_DIR
NAMES uuid.h
PATH_SUFFIXES ossp
HINTS ${PC_LIBUUID_INCLUDEDIR}
${PC_LIBUUID_INCLUDE_DIRS})

# MinGW version seems very aggressive finding uuid.h from our version,
# but libuuid.a from the system directory. As ossp-uuid is not part
# of most defaults, we'll try ignoring this.

string(REPLACE "/include" "/lib" i_libuuid_libdir ${LIBUUID_INCLUDE_DIR})
find_library(UUID_LIBRARY
NAMES ossp-uuid uuid
HINTS ${i_libuuid_libdir}
${PC_LIBUUID_LIBDIR}
${PC_LIBUUID_LIBRARY_DIRS}
NO_CMAKE_SYSTEM_PATH)
if(NOT UUID_LIBRARY)
find_library(UUID_LIBRARY
NAMES ossp-uuid uuid)
endif()

include(FindPackageHandleStandardArgs)

find_package_handle_standard_args(
LibUUID
REQUIRED_VARS LIBUUID_INCLUDE_DIR UUID_LIBRARY)

mark_as_advanced(LIBUUID_INCLUDE_DIR
UUID_LIBRARY)

68 changes: 68 additions & 0 deletions config.h.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#cmakedefine CRAY_STACKSEG_END
#cmakedefine C_ALLOCA
#cmakedefine DEFINE_XOPEN_SOURCE
#cmakedefine HAVE_ALLOCA
#cmakedefine HAVE_ALLOCA_H
#cmakedefine HAVE_CHMOD
#cmakedefine HAVE_CRT_EXTERNS_H
#cmakedefine HAVE_CRYPT
#cmakedefine HAVE_CRYPT_H
#cmakedefine HAVE_EXECINFO_H
#cmakedefine HAVE_FCNTL_H
#cmakedefine HAVE_GETRLIMIT
#cmakedefine HAVE_H_ERRNO
#cmakedefine HAVE_INITGROUPS
#cmakedefine HAVE_INTTYPES_H
#cmakedefine HAVE_LIBCRYPT
#cmakedefine HAVE_LIBNSL
#cmakedefine HAVE_LIBPTHREAD
#cmakedefine HAVE_LIBPTHREADGC
#cmakedefine HAVE_LIBPTHREADGC2
#cmakedefine HAVE_LIBSOCKET
#cmakedefine HAVE_MALLINFO
#cmakedefine HAVE_MALLOC_H
#cmakedefine HAVE_MALLOC_INFO
#cmakedefine HAVE_MEMORY_H
#cmakedefine HAVE_NETINET_TCP_H
#cmakedefine HAVE_OPEN_MEMSTREAM
#cmakedefine HAVE_PIPE2
#cmakedefine HAVE_POLL
#cmakedefine HAVE_POLL_H
#cmakedefine HAVE_PRCTL
#cmakedefine HAVE_SETGROUPS
#cmakedefine HAVE_SETPGID
#cmakedefine HAVE_SETPGRP
#cmakedefine HAVE_SETSID
#cmakedefine HAVE_SOCKET
#cmakedefine HAVE_SOCKLEN_T
#cmakedefine HAVE_SSIZE_T
#cmakedefine HAVE_STDINT_H
#cmakedefine HAVE_STDLIB_H
#cmakedefine HAVE_STRCASESTR
#cmakedefine HAVE_STRERROR
#cmakedefine HAVE_STRINGS_H
#cmakedefine HAVE_STRING_H
#cmakedefine HAVE_SYSCONF
#cmakedefine HAVE_SYSLOG_H
#cmakedefine HAVE_SYS_PRCTL_H
#cmakedefine HAVE_SYS_RESOURCE_H
#cmakedefine HAVE_SYS_STAT_H
#cmakedefine HAVE_SYS_TIME_H
#cmakedefine HAVE_SYS_TYPES_H
#cmakedefine HAVE_SYS_WAIT_H
#cmakedefine HAVE_UNISTD_H
#cmakedefine HAVE_UTIME
#cmakedefine HAVE_UTIME_H
#cmakedefine HAVE_VFORK
#cmakedefine HAVE__NSGETENVIRON
#cmakedefine O_PLMT
#cmakedefine PL_ARITY_AS_SIZE
#cmakedefine SETPGRP_VOID
#cmakedefine SIZEOF_LONG
#cmakedefine SIZEOF_LONG_LONG
#cmakedefine STACK_DIRECTION
#cmakedefine STDC_HEADERS
#cmakedefine HAVE_UUID_H
#cmakedefine HAVE_OSSP_UUID_H
#cmakedefine _REENTRANT
#cmakedefine size_t
16 changes: 3 additions & 13 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,9 @@ fi
if test x"$LIBUUID" = "x"; then
AC_MSG_WARN([ Cannot find libossp-uuid or libuuid -- dropping uuid.pl])
else
if test x"$UUID_H" = "x"; then
AC_CHECK_HEADER(ossp/uuid.h,
[ UUID_H=ossp/uuid.h ],
[],
[/*first*/])
fi
if test x"$UUID_H" = "x"; then
AC_CHECK_HEADER(uuid.h,
[ UUID_H=uuid.h ],
[],
[/*first*/])
fi
if test x"$UUID_H" = "x"; then
AC_CHECK_HEADERS(ossp/uuid.h uuid.h)
if test x"$ac_cv_header_ossp_uuid_h" = "x" -a
x"$ac_cv_header_uuid_h" = "x"; then
AC_MSG_WARN([ Cannot find uuid.h -- dropping uuid.pl])
else
AC_DEFINE_UNQUOTED([UUID_H], [<$UUID_H>],
Expand Down
2 changes: 0 additions & 2 deletions crypt.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef DEFINE_XOPEN_SOURCE
#define _XOPEN_SOURCE
Expand Down
2 changes: 0 additions & 2 deletions files.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <SWI-Prolog.h>
#include "clib.h"
Expand Down
2 changes: 0 additions & 2 deletions form.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <SWI-Prolog.h>
#include <stdio.h>
Expand Down
2 changes: 0 additions & 2 deletions md54pl.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <SWI-Prolog.h>
#include "md5.h"
Expand Down
2 changes: 0 additions & 2 deletions md5passwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
static char rcsid[] = "$Header$";
#endif /* LIBC_SCCS and not lint */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
Expand Down
2 changes: 0 additions & 2 deletions nonblockio.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ In the Unix version we simply call PL_dispatch() before doing recv() and
leave the details to this function.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#if defined(__MINGW32__)
#define __try
Expand Down
3 changes: 0 additions & 3 deletions nonblockio.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@
* GET REQUIRED HEADERS *
*******************************/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <SWI-Stream.h>
#include <SWI-Prolog.h>

Expand Down
2 changes: 0 additions & 2 deletions process.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@
POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

/*#define O_DEBUG 1*/
#define _GNU_SOURCE /* get pipe2() */
Expand Down
2 changes: 0 additions & 2 deletions rlimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
POSSIBILITY OF SUCH DAMAGE.
*/

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
Expand Down
37 changes: 37 additions & 0 deletions sha1/hmac_sha1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* Part of SWI-Prolog
Author: Jan Wielemaker
E-mail: [email protected]
WWW: http://www.swi-prolog.org
Copyright (c) 2018, VU University Amsterdam
CWI, Amsterdam
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

#define USE_SHA1 1
#include "hmac.c"
Loading

0 comments on commit 47c905c

Please sign in to comment.