libuv: Build the library within CMake

Take logic from upstream `Makefile.am` and `configure.ac` to build libuv
sources.

Update `uv.h` to include KWSys Large File Support configuration so that
consistent stream libraries are used (on AIX with XL).

Add a `cm_uv.h` header to include the CMake-provided copy of the `uv.h`
header from CMake sources.
This commit is contained in:
Brad King 2016-08-16 16:26:39 -04:00
parent d96416fe48
commit 13b7e7587d
6 changed files with 253 additions and 0 deletions

View File

@ -463,6 +463,19 @@ macro (CMAKE_BUILD_UTILITIES)
CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty") CMAKE_SET_TARGET_FOLDER(cmjsoncpp "Utilities/3rdParty")
endif() endif()
#---------------------------------------------------------------------
# Build libuv library.
if(NOT DEFINED CMAKE_USE_LIBUV)
set(CMAKE_USE_LIBUV 1)
endif()
if(CMAKE_USE_LIBUV)
set(CMAKE_LIBUV_LIBRARIES cmlibuv)
add_subdirectory(Utilities/cmlibuv)
CMAKE_SET_TARGET_FOLDER(cmlibuv "Utilities/3rdParty")
else()
set(CMAKE_LIBUV_LIBRARIES)
endif()
#--------------------------------------------------------------------- #---------------------------------------------------------------------
# Build XMLRPC library for CMake and CTest. # Build XMLRPC library for CMake and CTest.
if(CTEST_USE_XMLRPC) if(CTEST_USE_XMLRPC)

View File

@ -582,6 +582,7 @@ target_link_libraries(CMakeLib cmsys
${CMAKE_TAR_LIBRARIES} ${CMAKE_COMPRESS_LIBRARIES} ${CMAKE_TAR_LIBRARIES} ${CMAKE_COMPRESS_LIBRARIES}
${CMAKE_CURL_LIBRARIES} ${CMAKE_CURL_LIBRARIES}
${CMAKE_JSONCPP_LIBRARIES} ${CMAKE_JSONCPP_LIBRARIES}
${CMAKE_LIBUV_LIBRARIES}
${CMake_KWIML_LIBRARIES} ${CMake_KWIML_LIBRARIES}
) )

View File

@ -28,6 +28,7 @@
#cmakedefine HAVE_UNSETENV #cmakedefine HAVE_UNSETENV
#cmakedefine CMAKE_USE_ELF_PARSER #cmakedefine CMAKE_USE_ELF_PARSER
#cmakedefine CMAKE_USE_MACH_PARSER #cmakedefine CMAKE_USE_MACH_PARSER
#cmakedefine CMAKE_USE_LIBUV
#cmakedefine CMAKE_ENCODING_UTF8 #cmakedefine CMAKE_ENCODING_UTF8
#cmakedefine CMake_HAVE_CXX_NULLPTR #cmakedefine CMake_HAVE_CXX_NULLPTR
#cmakedefine CMake_HAVE_CXX_OVERRIDE #cmakedefine CMake_HAVE_CXX_OVERRIDE

17
Utilities/cm_uv.h Normal file
View File

@ -0,0 +1,17 @@
/*============================================================================
CMake - Cross Platform Makefile Generator
Copyright 2000-2016 Kitware, Inc., Insight Software Consortium
Distributed under the OSI-approved BSD License (the "License");
see accompanying file Copyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the License for more information.
============================================================================*/
#ifndef cm_uv_h
#define cm_uv_h
#include <cmlibuv/include/uv.h>
#endif

View File

@ -0,0 +1,217 @@
project(libuv C)
find_package(Threads)
set(uv_libraries ${CMAKE_THREAD_LIBS_INIT})
set(uv_includes include src)
set(uv_headers
include/uv.h
include/uv-errno.h
include/uv-threadpool.h
include/uv-version.h
)
set(uv_sources
src/fs-poll.c
src/heap-inl.h
src/inet.c
src/queue.h
src/threadpool.c
src/uv-common.c
src/uv-common.h
src/version.c
)
if(WIN32)
list(APPEND uv_libraries
ws2_32
psapi
iphlpapi
shell32
userenv
)
list(APPEND uv_includes
src/win
)
list(APPEND uv_defines
WIN32_LEAN_AND_MEAN
_WIN32_WINNT=0x0600
)
list(APPEND uv_headers
include/uv-win.h
include/tree.h
)
list(APPEND uv_sources
src/win/async.c
src/win/atomicops-inl.h
src/win/core.c
src/win/detect-wakeup.c
src/win/dl.c
src/win/error.c
src/win/fs-event.c
src/win/fs.c
src/win/getaddrinfo.c
src/win/getnameinfo.c
src/win/handle.c
src/win/handle-inl.h
src/win/internal.h
src/win/loop-watcher.c
src/win/pipe.c
src/win/poll.c
src/win/process-stdio.c
src/win/process.c
src/win/req.c
src/win/req-inl.h
src/win/signal.c
src/win/snprintf.c
src/win/stream.c
src/win/stream-inl.h
src/win/tcp.c
src/win/thread.c
src/win/timer.c
src/win/tty.c
src/win/udp.c
src/win/util.c
src/win/winapi.c
src/win/winapi.h
src/win/winsock.c
src/win/winsock.h
)
else()
list(APPEND uv_includes
src/unix
)
list(APPEND uv_headers
include/uv-unix.h
)
list(APPEND uv_sources
src/unix/async.c
src/unix/atomic-ops.h
src/unix/core.c
src/unix/dl.c
src/unix/fs.c
src/unix/getaddrinfo.c
src/unix/getnameinfo.c
src/unix/internal.h
src/unix/loop-watcher.c
src/unix/loop.c
src/unix/pipe.c
src/unix/poll.c
src/unix/process.c
src/unix/signal.c
src/unix/spinlock.h
src/unix/stream.c
src/unix/tcp.c
src/unix/thread.c
src/unix/timer.c
src/unix/tty.c
src/unix/udp.c
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "AIX")
list(APPEND uv_libraries
perfstat
)
list(APPEND uv_headers
include/uv-aix.h
)
list(APPEND uv_defines
_ALL_SOURCE
_XOPEN_SOURCE=500
_LINUX_SOURCE_COMPAT
_THREAD_SAFE
)
list(APPEND uv_sources
src/unix/aix.c
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
list(APPEND uv_headers
include/uv-darwin.h
include/pthread-barrier.h
)
list(APPEND uv_defines
_DARWIN_USE_64_BIT_INODE=1
_DARWIN_UNLIMITED_SELECT=1
)
list(APPEND uv_sources
src/unix/darwin.c
src/unix/darwin-proctitle.c
src/unix/fsevents.c
src/unix/kqueue.c
src/unix/proctitle.c
src/unix/pthread-barrier.c
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
list(APPEND uv_libraries dl rt)
list(APPEND uv_headers
include/uv-linux.h
)
list(APPEND uv_defines _GNU_SOURCE)
list(APPEND uv_sources
src/unix/linux-core.c
src/unix/linux-inotify.c
src/unix/linux-syscalls.c
src/unix/linux-syscalls.h
src/unix/proctitle.c
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
list(APPEND uv_headers
include/uv-bsd.h
)
list(APPEND uv_sources
src/unix/freebsd.c
src/unix/kqueue.c
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "NetBSD")
list(APPEND uv_headers
include/uv-bsd.h
)
list(APPEND uv_sources
src/unix/netbsd.c
src/unix/kqueue.c
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "OpenBSD")
list(APPEND uv_headers
include/uv-bsd.h
)
list(APPEND uv_sources
src/unix/openbsd.c
src/unix/kqueue.c
)
endif()
if(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
list(APPEND uv_libraries
kstat
nsl
sendfile
socket
)
list(APPEND uv_headers
include/uv-sunos.h
)
list(APPEND uv_defines
__EXTENSIONS__
_XOPEN_SOURCE=500
)
list(APPEND uv_sources
src/unix/sunos.c
)
endif()
include_directories(
${uv_includes}
${KWSYS_HEADER_ROOT}
)
add_library(cmlibuv STATIC ${uv_sources})
target_link_libraries(cmlibuv ${uv_libraries})
set_property(TARGET cmlibuv PROPERTY COMPILE_DEFINITIONS ${uv_defines})

View File

@ -23,6 +23,10 @@
#ifndef UV_H #ifndef UV_H
#define UV_H #define UV_H
/* Include KWSys Large File Support configuration. */
#include <cmsys/Configure.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif