Skip to content

Commit

Permalink
Merge pull request #2506 from comex/enet-build-fixes
Browse files Browse the repository at this point in the history
ENet fixes (build fixes, upgrade)
  • Loading branch information
Sonicadvance1 committed Jun 8, 2015
2 parents 9521bc1 + eb234da commit 49a0adb
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 223 deletions.
65 changes: 42 additions & 23 deletions CMakeLists.txt
Expand Up @@ -6,6 +6,7 @@ project(dolphin-emu)

option(USE_EGL "Enables EGL OpenGL Interface" OFF)
option(TRY_X11 "Enables X11 Support" ON)
option(USE_SHARED_ENET "Use shared libenet if found rather than Dolphin's soon-to-compatibly-diverge version" OFF)
option(USE_UPNP "Enables UPnP port mapping support" ON)
option(DISABLE_WX "Disable wxWidgets (use Qt or CLI interface)" OFF)
option(ENABLE_QT "Enable Qt (use the experimental Qt interface)" OFF)
Expand Down Expand Up @@ -246,12 +247,6 @@ if(APPLE)
set(CMAKE_PREFIX_PATH "${CMAKE_PREFIX_PATH};/usr")
endif()

# Some of our code contains Objective C constructs.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -x objective-c -stdlib=libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++ -stdlib=libc++")
# Avoid mistaking an object file for a source file on the link command line.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -x none")

# Identify the target system:
# Ask for 64-bit binary.
set(TARGET_FLAGS "-arch x86_64")
Expand Down Expand Up @@ -395,7 +390,7 @@ if(NOT ANDROID)
message("ALSA NOT found, disabling ALSA sound backend")
endif(ALSA_FOUND)

check_lib(AO ao QUIET)
check_lib(AO ao ao QUIET)
if(AO_FOUND)
add_definitions(-DHAVE_AO=1)
message("ao found, enabling ao sound backend")
Expand All @@ -404,7 +399,7 @@ if(NOT ANDROID)
message("ao NOT found, disabling ao sound backend")
endif(AO_FOUND)

check_lib(BLUEZ bluez QUIET)
check_lib(BLUEZ bluez bluez QUIET)
if(BLUEZ_FOUND)
add_definitions(-DHAVE_BLUEZ=1)
message("bluez found, enabling bluetooth support")
Expand All @@ -413,7 +408,7 @@ if(NOT ANDROID)
message("bluez NOT found, disabling bluetooth support")
endif(BLUEZ_FOUND)

check_lib(PULSEAUDIO libpulse QUIET)
check_lib(PULSEAUDIO libpulse pulse QUIET)
if(PULSEAUDIO_FOUND)
add_definitions(-DHAVE_PULSEAUDIO=1)
message("PulseAudio found, enabling PulseAudio sound backend")
Expand Down Expand Up @@ -467,7 +462,7 @@ if(NOT ANDROID)
endif()

if(USE_X11)
check_lib(XRANDR Xrandr)
check_lib(XRANDR xrandr Xrandr)
if(XRANDR_FOUND)
add_definitions(-DHAVE_XRANDR=1)
else()
Expand Down Expand Up @@ -507,8 +502,8 @@ if(NOT ANDROID)
endif(PORTAUDIO)

if(OPROFILING)
check_lib(OPROFILE opagent opagent.h)
check_lib(BFD bfd bfd.h)
check_lib(OPROFILE "(no .pc for opagent)" opagent opagent.h)
check_lib(BFD "(no .pc for bfd)" bfd bfd.h)
if(OPROFILE_FOUND AND BFD_FOUND)
message("oprofile found, enabling profiling support")
add_definitions(-DUSE_OPROFILE=1)
Expand Down Expand Up @@ -541,11 +536,27 @@ include_directories(Source/Core)
add_subdirectory(Externals/Bochs_disasm)
include_directories(Externals/Bochs_disasm)

if(NOT APPLE AND NOT ANDROID)
check_lib(ENET enet enet/enet.h QUIET)
if(NOT ANDROID AND USE_SHARED_ENET)
check_lib(ENET libenet enet enet/enet.h QUIET)
include(CheckSymbolExists)
if (ENET_FOUND)
set(CMAKE_REQUIRED_INCLUDES ${ENET_INCLUDE_DIRS})
# hack: LDFLAGS already contains -lenet but all flags but the first are
# dropped; ugh, cmake
set(CMAKE_REQUIRED_FLAGS ${ENET_LDFLAGS})
set(CMAKE_REQUIRED_LIBRARIES ${ENET_LIBRARIES})
CHECK_SYMBOL_EXISTS(enet_socket_get_address enet/enet.h ENET_HAVE_SGA)
set(CMAKE_REQUIRED_INCLUDES)
set(CMAKE_REQUIRED_FLAGS)
set(CMAKE_REQUIRED_LIBRARIES)
if (NOT ENET_HAVE_SGA)
# enet is too old
set(ENET_FOUND FALSE)
endif()
endif()
endif()
if (ENET_FOUND)
message("Using shared enet")
message("Using shared enet")
else()
message("Using static enet from Externals")
include_directories(Externals/enet/include)
Expand Down Expand Up @@ -576,7 +587,7 @@ else(ZLIB_FOUND)
endif(ZLIB_FOUND)

if(NOT APPLE AND NOT ANDROID)
check_lib(LZO lzo2 lzo/lzo1x.h QUIET)
check_lib(LZO "(no .pc for lzo2)" lzo2 lzo/lzo1x.h QUIET)
endif()
if(LZO_FOUND)
message("Using shared lzo")
Expand All @@ -589,7 +600,7 @@ endif()
list(APPEND LIBS ${LZO})

if(NOT APPLE AND NOT ANDROID)
check_lib(PNG png png.h QUIET)
check_lib(PNG libpng png png.h QUIET)
endif()
if (PNG_FOUND)
message("Using shared libpng")
Expand All @@ -602,7 +613,7 @@ endif()

if(OPENAL_FOUND)
if(NOT APPLE)
check_lib(SOUNDTOUCH SoundTouch soundtouch/SoundTouch.h QUIET)
check_lib(SOUNDTOUCH soundtouch SoundTouch soundtouch/SoundTouch.h QUIET)
endif()
if (SOUNDTOUCH_FOUND)
message("Using shared soundtouch")
Expand Down Expand Up @@ -687,7 +698,7 @@ else()
endif()

if(NOT APPLE AND NOT ANDROID)
check_lib(SOIL SOIL SOIL/SOIL.h QUIET)
check_lib(SOIL "(no .pc for SOIL)" SOIL SOIL/SOIL.h QUIET)
endif()
if(SOIL_FOUND)
message("Using shared SOIL")
Expand Down Expand Up @@ -746,7 +757,7 @@ if(NOT DISABLE_WX AND NOT ANDROID)
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}
VERSION_EQUAL 2.8.2 OR "${DIST_NAME}" STREQUAL "natty")
check_lib(GTK2 gtk+-2.0 gtk.h REQUIRED)
check_lib(GTK2 gtk+-2.0 gtk+-2.0 gtk.h REQUIRED)
else()
include(FindGTK2)
if(GTK2_FOUND)
Expand All @@ -772,8 +783,8 @@ if(NOT DISABLE_WX AND NOT ANDROID)
add_definitions(-D__WXGTK__)

# Check for required libs
check_lib(GTHREAD2 gthread-2.0 glib/gthread.h REQUIRED)
check_lib(PANGOCAIRO pangocairo pango/pangocairo.h REQUIRED)
check_lib(GTHREAD2 gthread-2.0 gthread-2.0 glib/gthread.h REQUIRED)
check_lib(PANGOCAIRO pangocairo pangocairo pango/pangocairo.h REQUIRED)
elseif(WIN32)
add_definitions(-D__WXMSW__)
else()
Expand Down Expand Up @@ -844,6 +855,15 @@ add_definitions(-std=gnu++0x)
# but some dependencies require them (LLVM, libav).
add_definitions(-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS)

# Do this at the last minute because try_compile ignores linker flags. Yay...
if(APPLE)
# Some of our code contains Objective C constructs.
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -x objective-c -stdlib=libc++")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++ -stdlib=libc++")
# Avoid mistaking an object file for a source file on the link command line.
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -x none")
endif()

add_subdirectory(Source)


Expand Down Expand Up @@ -889,4 +909,3 @@ list(APPEND CPACK_SOURCE_IGNORE_FILES "${CMAKE_BINARY_DIR}")
# CPack must be included after the CPACK_* variables are set in order for those
# variables to take effect.
Include(CPack)

5 changes: 2 additions & 3 deletions CMakeTests/CheckLib.cmake
Expand Up @@ -6,7 +6,7 @@ macro(_internal_message msg)
endif()
endmacro()

macro(check_lib var lib)
macro(check_lib var pc lib)
set(_is_required 0)
set(_is_quiet 0)
set(_arg_list ${ARGN})
Expand All @@ -22,8 +22,7 @@ macro(check_lib var lib)
endforeach()

if(PKG_CONFIG_FOUND AND NOT ${var}_FOUND)
string(TOLOWER ${lib} lower_lib)
pkg_search_module(${var} QUIET ${lower_lib})
pkg_search_module(${var} QUIET ${pc})
endif()

if(${var}_FOUND)
Expand Down
14 changes: 11 additions & 3 deletions Externals/enet/CMakeLists.txt
Expand Up @@ -8,6 +8,8 @@ include(CheckStructHasMember)
include(CheckTypeSize)
check_function_exists("fcntl" HAS_FCNTL)
check_function_exists("poll" HAS_POLL)
check_function_exists("getaddrinfo" HAS_GETADDRINFO)
check_function_exists("getnameinfo" HAS_GETNAMEINFO)
check_function_exists("gethostbyname_r" HAS_GETHOSTBYNAME_R)
check_function_exists("gethostbyaddr_r" HAS_GETHOSTBYADDR_R)
check_function_exists("inet_pton" HAS_INET_PTON)
Expand All @@ -16,13 +18,19 @@ check_struct_has_member("struct msghdr" "msg_flags" "sys/types.h;sys/socket.h" H
set(CMAKE_EXTRA_INCLUDE_FILES "sys/types.h" "sys/socket.h")
check_type_size("socklen_t" HAS_SOCKLEN_T BUILTIN_TYPES_ONLY)
unset(CMAKE_EXTRA_INCLUDE_FILES)

if(HAS_FCNTL)
add_definitions(-DHAS_FCNTL=1)
endif()
if(HAS_POLL)
add_definitions(-DHAS_POLL=1)
endif()
if(HAS_GETNAMEINFO)
add_definitions(-DHAS_GETNAMEINFO=1)
endif()
if(HAS_GETADDRINFO)
add_definitions(-DHAS_GETADDRINFO=1)
endif()
if(HAS_GETHOSTBYNAME_R)
add_definitions(-DHAS_GETHOSTBYNAME_R=1)
endif()
Expand All @@ -41,9 +49,9 @@ endif()
if(HAS_SOCKLEN_T)
add_definitions(-DHAS_SOCKLEN_T=1)
endif()

include_directories(${PROJECT_SOURCE_DIR}/include)

add_library(enet STATIC
callbacks.c
compress.c
Expand Down
8 changes: 8 additions & 0 deletions Externals/enet/ChangeLog
@@ -1,3 +1,11 @@
* use getaddrinfo and getnameinfo where available

ENet 1.3.13 (April 30, 2015):

* miscellaneous bug fixes
* added premake and cmake support
* miscellaneous documentation cleanups

ENet 1.3.12 (April 24, 2014):

* added maximumPacketSize and maximumWaitingData fields to ENetHost to limit the amount of
Expand Down
2 changes: 1 addition & 1 deletion Externals/enet/Doxyfile
Expand Up @@ -38,7 +38,7 @@ PROJECT_NAME = "ENet"
# could be handy for archiving the generated documentation or if some version
# control system is used.

PROJECT_NUMBER = v1.3.12
PROJECT_NUMBER = v1.3.13

# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer a
Expand Down
2 changes: 1 addition & 1 deletion Externals/enet/Makefile.am
Expand Up @@ -16,7 +16,7 @@ enetinclude_HEADERS = \
lib_LTLIBRARIES = libenet.la
libenet_la_SOURCES = callbacks.c compress.c host.c list.c packet.c peer.c protocol.c unix.c win32.c
# see info '(libtool) Updating version info' before making a release
libenet_la_LDFLAGS = $(AM_LDFLAGS) -version-info 7:0:0
libenet_la_LDFLAGS = $(AM_LDFLAGS) -version-info 7:1:0
AM_CPPFLAGS = -I$(top_srcdir)/include

ACLOCAL_AMFLAGS = -Im4
4 changes: 3 additions & 1 deletion Externals/enet/configure.ac
@@ -1,4 +1,4 @@
AC_INIT([libenet], [1.3.12])
AC_INIT([libenet], [1.3.13])
AC_CONFIG_SRCDIR([include/enet/enet.h])
AM_INIT_AUTOMAKE([foreign])

Expand All @@ -7,6 +7,8 @@ AC_CONFIG_MACRO_DIR([m4])
AC_PROG_CC
AC_PROG_LIBTOOL

AC_CHECK_FUNC(getaddrinfo, [AC_DEFINE(HAS_GETADDRINFO)])
AC_CHECK_FUNC(getnameinfo, [AC_DEFINE(HAS_GETNAMEINFO)])
AC_CHECK_FUNC(gethostbyaddr_r, [AC_DEFINE(HAS_GETHOSTBYADDR_R)])
AC_CHECK_FUNC(gethostbyname_r, [AC_DEFINE(HAS_GETHOSTBYNAME_R)])
AC_CHECK_FUNC(poll, [AC_DEFINE(HAS_POLL)])
Expand Down
2 changes: 1 addition & 1 deletion Externals/enet/docs/mainpage.dox
Expand Up @@ -36,7 +36,7 @@ portable, and easily embeddable.
You can retrieve the source to ENet by downloading it in either .tar.gz form
or accessing the github distribution directly.

The most recent stable release (1.3.12) can be downloaded <a class="el" href="download/enet-1.3.12.tar.gz">here</a>.
The most recent stable release (1.3.13) can be downloaded <a class="el" href="download/enet-1.3.13.tar.gz">here</a>.
The last release that is protocol compatible with the 1.2 series or earlier (1.2.5) can be downloaded <a class="el" href="download/enet-1.2.5.tar.gz">here</a>.

You can find the most recent ENet source at <a class="el" href="https://github.com/lsalzman/enet">the github repository</a>.
Expand Down

0 comments on commit 49a0adb

Please sign in to comment.