Skip to content

Commit

Permalink
Merge pull request sctplab#13 from weinrank/cmake
Browse files Browse the repository at this point in the history
CMake support
  • Loading branch information
tuexen committed Sep 3, 2015
2 parents 0c39017 + 12bbb41 commit 71a8887
Show file tree
Hide file tree
Showing 6 changed files with 508 additions and 2 deletions.
35 changes: 35 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#
# Copyright (C) 2015-2015 Oleg Alexeenkov
# Copyright (C) 2015-2015 Felix Weinrank
#
# 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.
# 3. Neither the name of the project nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 PROJECT 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.
#

cmake_minimum_required(VERSION 2.6)
message(">> WARNINING: CMAKE SUPPORT IS EXPERIMENTAL <<")
add_subdirectory(usrsctplib)
add_subdirectory(programs)
7 changes: 7 additions & 0 deletions Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ On Windows you need a compiler like Microsoft Visual Studio. You can build the l

in the directory `usrsctp`.

#### CMake (experimental)
Create a directory outside the `usrsctp` directory, enter it and generate files by typing

$ cmake <path-to-usrsctp-sources>

By using the `-g`flag you can specify the target buildsystem e.g. `cmake -G Xcode ../usrsctp` will generate project files for Xcode.

### Running the Test Programs

Several test programs are included, including a discard server and a client. You can run both to send data from the client to the server. The client reads data from stdin and sends them to the server, which prints the message in the terminal and discards it. The sources of the server are also provided [here](https://github.com/sctplab/usrsctp/blob/master/programs/discard_server.c) and those of the client [here](https://github.com/sctplab/usrsctp/blob/master/programs/client.c).
Expand Down
188 changes: 188 additions & 0 deletions programs/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
#
# Copyright (C) 2015-2015 Oleg Alexeenkov
# Copyright (C) 2015-2015 Felix Weinrank
#
# 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.
# 3. Neither the name of the project nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE PROJECT 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 PROJECT 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.
#
message(">> WARNINING: CMAKE SUPPORT IS EXPERIMENTAL <<")

cmake_minimum_required(VERSION 2.6)
include_directories(../usrsctplib)


#################################################
# INCLUDE MODULES
#################################################

include(CheckFunctionExists)
include(CheckStructHasMember)
include(CheckIncludeFile)
include(CMakePushCheckState)
include(CheckTypeSize)


#################################################
# CHECK FOR TYPES AND FUNCTIONS
#################################################

# xxx warum machen wir die checks?
check_type_size("size_t" HAVE_SIZE_T)
check_type_size("ssize_t" HAVE_SSIZE_T)

check_function_exists("socket" HAVE_SOCKET)
check_function_exists("inet_addr" HAVE_INET_ADDR)


#################################################
# CHECK INCLUDES
#################################################

check_include_file(sys/socket.h HAVE_SYS_SOCKET_H)
check_include_file(sys/types.h HAVE_SYS_TYPES_H)
check_include_file(sys/queue.h HAVE_SYS_QUEUE_H)
check_include_file(linux/if_addr.h HAVE_LINUX_IF_ADDR_H)
check_include_file(linux/rtnetlink.h HAVE_LINUX_RTNETLINK_H)
check_include_file(netinet/ip_icmp.h HAVE_NETINET_IP_ICMP_H)
check_include_file(usrsctp.h HAVE_USRSCTP_H)


#################################################
# CHECK STRUCT MEMBERS
#################################################

check_struct_has_member("struct sockaddr" "sa_len" "sys/types.h;sys/socket.h" HAVE_SA_LEN)
if(HAVE_SA_LEN)
add_definitions(-DHAVE_SA_LEN)
endif()

check_struct_has_member("struct sockaddr_in" "sin_len" "sys/types.h;netinet/in.h" HAVE_SIN_LEN)
if(HAVE_SIN_LEN)
add_definitions(-DHAVE_SIN_LEN)
endif()

check_struct_has_member("struct sockaddr_in6" "sin6_len" "sys/types.h;netinet/in.h" HAVE_SIN6_LEN)
if(HAVE_SIN6_LEN)
add_definitions(-DHAVE_SIN6_LEN)
endif()


#################################################
# CHECK OPTIONS
#################################################

option(SCTP_DEBUG "Provide debug information" 0)
if (SCTP_DEBUG)
add_definitions(-DSCTP_DEBUG)
endif()

option(INET "Support IPv4 " 1)
if (INET)
add_definitions(-DINET)
endif()

option(INET6 "Support IPv6 " 1)
if (INET6)
add_definitions(-DINET6)
endif()

option(LINK_STATIC "Link static" 1)
if (LINK_STATIC)
set(LINK_STATIC "usrsctp-static")
else()
set(LINK_STATIC "usrsctp")
endif()


#################################################
# OS DEPENDENT
#################################################

if (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
add_definitions(-DHAVE_SCONN_LEN)
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
add_definitions(-DHAVE_SCONN_LEN)
add_definitions(-D__APPLE_USE_RFC_2292)
endif()

if (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
add_definitions(-DHAVE_SCONN_LEN)
endif()


#################################################
# MISC
#################################################

FIND_PACKAGE(Threads)


#################################################
# PROGRAMS
#################################################

SET (check_PROGRAMS
client.c
datachan_serv.c
daytime_server.c
discard_server.c
echo_server.c
ekr_client.c
ekr_loop.c
ekr_peer.c
ekr_server.c
rtcweb.c
tsctp.c
)

FOREACH (source_file ${check_PROGRAMS})
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
ADD_EXECUTABLE (
${source_file_we}
${source_file}
)

TARGET_LINK_LIBRARIES (${source_file_we}
${LINK_STATIC}
${CMAKE_THREAD_LIBS_INIT}
)

ADD_TEST (${source_file_we} ${source_file_we})

IF ("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xClang" OR "x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xGNU")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-g -pedantic -Wall -Werror -std=c99")
ENDIF ()

IF ("x${CMAKE_CXX_COMPILER_ID}" STREQUAL "xMSVC")
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ELSE ()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
ENDIF ()
ENDIF ()
ENDFOREACH ()
9 changes: 8 additions & 1 deletion programs/Makefile.nmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ all: \
rtcweb \
ekr_client \
ekr_server \
ekr_peer
ekr_peer \
ekr_loop

client:
$(CC) $(CFLAGS) $(CVARSDLL) -c client.c
Expand Down Expand Up @@ -84,6 +85,10 @@ ekr_peer:
$(CC) $(CFLAGS) $(CVARSDLL) -c ekr_peer.c
link -out:ekr_peer.exe ekr_peer.obj $(LINKFLAGS)

ekr_loop:
$(CC) $(CFLAGS) $(CVARSDLL) -c ekr_loop.c
link -out:ekr_loop.exe ekr_loop.obj $(LINKFLAGS)

clean:
del /F client.exe
del /F client.obj
Expand All @@ -103,3 +108,5 @@ clean:
del /F ekr_server.obj
del /F ekr_peer.exe
del /F ekr_peer.obj
del /F ekr_loop.exe
del /F ekr_loop.obj
6 changes: 5 additions & 1 deletion programs/ekr_loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ main(void)
int cur_buf_size, snd_buf_size, rcv_buf_size;
socklen_t opt_len;
struct sctp_sndinfo sndinfo;
char line[LINE_LENGTH];
char *line;

usrsctp_init(0, conn_output, debug_printf);
/* set up a connected UDP socket */
Expand Down Expand Up @@ -460,6 +460,9 @@ main(void)
exit(EXIT_FAILURE);
}
usrsctp_close(s_l);
if ((line = malloc(LINE_LENGTH)) == NULL) {
exit(EXIT_FAILURE);
}
memset(line, 'A', LINE_LENGTH);
sndinfo.snd_sid = 1;
sndinfo.snd_flags = 0;
Expand All @@ -472,6 +475,7 @@ main(void)
perror("usrsctp_sendv");
exit(EXIT_FAILURE);
}
free(line);
usrsctp_shutdown(s_c, SHUT_WR);

while (usrsctp_finish() != 0) {
Expand Down
Loading

0 comments on commit 71a8887

Please sign in to comment.