Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add cmake build script #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ ucat
ucat-static
tags
*~
build/
102 changes: 102 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
project(utp)
cmake_minimum_required(VERSION 2.8)

if (WIN32)
set(PLATFORM_SOURCES libutp_inet_ntop.cpp)
add_definitions(-D_WIN32_WINNT=0x501)
# disable crt security warnings for now -- ideally the code should be fixed
# to use the "safe" versions of the CRT functions on Windows.
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
set(PLATFORM_LIBS ws2_32)
elseif(ANDROID)
add_definitions(-DPOSIX)
elseif(UNIX)
find_package(Threads)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -g -fno-exceptions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -fno-rtti")
add_definitions(-DPOSIX)
set(PLATFORM_LIBS ${CMAKE_THREAD_LIBRARY_INIT})
if (NOT APPLE)
set(PLATFORM_LIBS ${PLATFORM_LIBS} rt)
endif()
else()
message(FATAL_ERROR "platform is not supported yet")
endif()

string(TOLOWER "${CMAKE_BUILD_TYPE}" BUILD_TYPE)
if ("${BUILD_TYPE}" STREQUAL "debug")
add_definitions(-D_DEBUG)
endif()

if (UTP_DEBUG_LOGGING)
add_definitions(-D_UTP_DEBUG_LOGGING)
endif()

add_library(utp-objs OBJECT
utp_api.cpp
utp_callbacks.cpp
utp_hash.cpp
utp_internal.cpp
utp_packedsockaddr.cpp
utp_utils.cpp
${PLATFORM_SOURCES}
)

############################################
# static lib
############################################
add_library(utp-static STATIC $<TARGET_OBJECTS:utp-objs>)
target_link_libraries(utp-static ${PLATFORM_LIBS})
set_target_properties(utp-static PROPERTIES OUTPUT_NAME "utp")
set_target_properties(utp-static PROPERTIES PREFIX "lib")

############################################
# shared lib
############################################
if (WIN32)
add_library(utp SHARED $<TARGET_OBJECTS:utp-objs> utp.def)
else()
add_library(utp SHARED $<TARGET_OBJECTS:utp-objs>)
endif()
target_link_libraries(utp ${PLATFORM_LIBS})

if (NOT ANDROID)
############################################
# installation
############################################
foreach(PLATFORM_LIB ${PLATFORM_LIBS})
set(PLATFORM_LIBS_LINK ${PLATFORM_LIBS_LINK} -l${PLATFORM_LIB})
endforeach()
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/utp.pc.in
${CMAKE_CURRENT_BINARY_DIR}/utp.pc
@ONLY)
INSTALL(FILES utp.h utp_types.h DESTINATION include)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/utp.pc DESTINATION lib/pkgconfig)
INSTALL(TARGETS utp-static utp
RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)

############################################
# ucat (non-windows platforms only)
############################################
if (NOT WIN32)
add_library(ucat-objs OBJECT ucat.c)

add_executable(ucat-static $<TARGET_OBJECTS:ucat-objs>)
target_link_libraries(ucat-static utp-static)

add_executable(ucat $<TARGET_OBJECTS:ucat-objs>)
target_link_libraries(ucat utp)

INSTALL(TARGETS ucat ucat-static
RUNTIME DESTINATION bin LIBRARY DESTINATION lib ARCHIVE DESTINATION lib)
endif(NOT WIN32)

############################################
# Ctags
############################################

add_custom_target(tags
ctags *.cpp *.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

endif(NOT ANDROID)
29 changes: 29 additions & 0 deletions utp.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
LIBRARY utp
EXPORTS
utp_init
utp_destroy
utp_set_callback
utp_context_set_userdata
utp_context_get_userdata
utp_context_set_option
utp_context_get_option
utp_process_udp
utp_process_icmp_error
utp_process_icmp_fragmentation
utp_check_timeouts
utp_issue_deferred_acks
utp_get_context_stats
utp_create_socket
utp_set_userdata
utp_get_userdata
utp_setsockopt
utp_getsockopt
utp_connect
utp_write
utp_writev
utp_getpeername
utp_read_drained
utp_get_delays
utp_get_stats
utp_get_context
utp_close
12 changes: 12 additions & 0 deletions utp.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=@CMAKE_INSTALL_PREFIX@
libdir=@CMAKE_INSTALL_PREFIX@/lib
includedir=@CMAKE_INSTALL_PREFIX@/include

Name: utp
Description: a TCP-like implementation of LEDBAT
Version:
Requires:
Libs: -L${libdir} -lutp
Libs.private: @PLATFORM_LIBS_LINK@
Cflags: -I${includedir}