Subject: [PATCH] Multiple changes in the build process

* Default CMAKE_BUILD_TYPE to Release
* Use CMAKE_BUILD_TYPE to define _DEBUG (NDEBUG is more standard though,
  but cmake defines it)
* Drop LWS_WITHOUT_DEBUG (use CMAKE_BUILD_TYPE for that)
* Drop LWS_NO_EXTERNAL_POLL (was not used)
* Drop CMAKE_BUILD (CMake is the only build system now)
* Add LWS_WITH_STATIC and LWS_WITH_SHARED to choose what version(s) to
  build
* Add LWS_XXX_LIBRARIES and LWS_XXX_INCLUDE_DIRS for each library
  dependency (zlib, openssl, libev, cyassl)
* Support setting of XXX_LIBRARIES, XXX_LIBRARIES and XXX_INCLUDE_DIRS
  by parent project (when included with add_subdirectory())
* Rename LWS_USE_EXTERNAL_ZLIB to LWS_USE_BUNDLED_ZLIB and default it to
  NO (since it's Windows only)
* Default LWS_WITHOUT_DAEMONIZE to NO (since network lib shouldn't know
  how to do it anyway)
* Rename config.h.cmake to lws_config.h.in
* Rename shared library to websockets_shared so linker will not be
  confused
* Fix inline keyword detection in clang
* Explicitly set MACOSX_RPATH to YES on MacOS
This commit is contained in:
wonder-mice 2015-04-22 10:52:13 -07:00 committed by Andy Green
parent 644fea11c5
commit f1b125442b
3 changed files with 224 additions and 186 deletions

View file

@ -1,5 +1,9 @@
cmake_minimum_required(VERSION 2.8) cmake_minimum_required(VERSION 2.8)
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Build type")
endif()
project(libwebsockets C) project(libwebsockets C)
set(PACKAGE "libwebsockets") set(PACKAGE "libwebsockets")
@ -33,10 +37,19 @@ if(GIT_EXECUTABLE)
message("Git commit hash: ${LWS_BUILD_HASH}") message("Git commit hash: ${LWS_BUILD_HASH}")
endif() endif()
set(LWS_USE_BUNDLED_ZLIB_DEFAULT OFF)
if(WIN32)
set(LWS_USE_BUNDLED_ZLIB_DEFAULT ON)
endif()
option(LWS_WITH_STATIC "Build the static version of the library" ON)
option(LWS_WITH_SHARED "Build the shared version of the library" ON)
option(LWS_WITH_SSL "Include SSL support (default OpenSSL, CyaSSL if LWS_USE_CYASSL is set)" ON) option(LWS_WITH_SSL "Include SSL support (default OpenSSL, CyaSSL if LWS_USE_CYASSL is set)" ON)
option(LWS_USE_CYASSL "Use CyaSSL replacement for OpenSSL. When settings this, you also need to specify LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS" OFF)
option(LWS_WITH_ZLIB "Include zlib support (required for extensions)" ON)
option(LWS_WITH_LIBEV "Compile with support for libev" OFF)
option(LWS_USE_BUNDLED_ZLIB "Use bundled zlib version (Windows only)" ${LWS_USE_BUNDLED_ZLIB_DEFAULT})
option(LWS_SSL_CLIENT_USE_OS_CA_CERTS "SSL support should make use of OS installed CA root certs" ON) option(LWS_SSL_CLIENT_USE_OS_CA_CERTS "SSL support should make use of OS installed CA root certs" ON)
option(LWS_USE_EXTERNAL_ZLIB "Search the system for ZLib instead of using the included one (on Windows)" OFF)
option(LWS_USE_CYASSL "Use CyaSSL replacement for OpenSSL. When settings this, you also need to specify LWS_CYASSL_LIB and LWS_CYASSL_INCLUDE_DIRS" OFF)
option(LWS_WITHOUT_BUILTIN_GETIFADDRS "Don't use BSD getifaddrs implementation from libwebsockets if it is missing (this will result in a compilation error) ... Default is your libc provides it. On some systems such as uclibc it doesn't exist." OFF) option(LWS_WITHOUT_BUILTIN_GETIFADDRS "Don't use BSD getifaddrs implementation from libwebsockets if it is missing (this will result in a compilation error) ... Default is your libc provides it. On some systems such as uclibc it doesn't exist." OFF)
option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF) option(LWS_WITHOUT_CLIENT "Don't build the client part of the library" OFF)
option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF) option(LWS_WITHOUT_SERVER "Don't build the server part of the library" OFF)
@ -47,11 +60,9 @@ option(LWS_WITHOUT_TEST_SERVER_EXTPOLL "Don't build the test server version that
option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF) option(LWS_WITHOUT_TEST_PING "Don't build the ping test application" OFF)
option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF) option(LWS_WITHOUT_TEST_CLIENT "Don't build the client test application" OFF)
option(LWS_WITHOUT_TEST_FRAGGLE "Don't build the ping test application" OFF) option(LWS_WITHOUT_TEST_FRAGGLE "Don't build the ping test application" OFF)
option(LWS_WITHOUT_DEBUG "Don't compile debug related code" OFF)
option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" OFF) option(LWS_WITHOUT_EXTENSIONS "Don't compile with extensions" OFF)
option(LWS_WITH_LATENCY "Build latency measuring code into the library" OFF) option(LWS_WITH_LATENCY "Build latency measuring code into the library" OFF)
option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" OFF) option(LWS_WITHOUT_DAEMONIZE "Don't build the daemonization api" ON)
option(LWS_WITH_LIBEV "Compile with support for libev" OFF)
option(LWS_IPV6 "Compile with support for ipv6" OFF) option(LWS_IPV6 "Compile with support for ipv6" OFF)
option(LWS_WITH_HTTP2 "Compile with support for http2" OFF) option(LWS_WITH_HTTP2 "Compile with support for http2" OFF)
@ -65,6 +76,66 @@ if (LWS_WITHOUT_CLIENT AND LWS_WITHOUT_SERVER)
message(FATAL_ERROR "Makes no sense to compile without both client or server.") message(FATAL_ERROR "Makes no sense to compile without both client or server.")
endif() endif()
if (NOT (LWS_WITH_STATIC OR LWS_WITH_SHARED))
message(FATAL_ERROR "Makes no sense to compile without both static or shared libraries.")
endif()
if (NOT LWS_WITHOUT_EXTENSIONS)
if (NOT LWS_WITH_ZLIB)
message(FATAL_ERROR "zlib is required for extensions.")
endif()
endif()
set(LWS_ZLIB_LIBRARIES CACHE PATH "Path to the zlib library")
set(LWS_ZLIB_INCLUDE_DIRS CACHE PATH "Path to the zlib include directory")
set(LWS_OPENSSL_LIBRARIES CACHE PATH "Path to the OpenSSL library")
set(LWS_OPENSSL_INCLUDE_DIRS CACHE PATH "Path to the OpenSSL include directory")
set(LWS_CYASSL_LIBRARIES CACHE PATH "Path to the CyaSSL library")
set(LWS_CYASSL_INCLUDE_DIRS CACHE PATH "Path to the CyaSSL include directory")
set(LWS_LIBEV_LIBRARIES CACHE PATH "Path to the libev library")
set(LWS_LIBEV_INCLUDE_DIRS CACHE PATH "Path to the libev include directory")
if (LWS_WITH_SSL AND NOT LWS_USE_CYASSL)
if ("${LWS_OPENSSL_LIBRARIES}" STREQUAL "" OR "${LWS_OPENSSL_INCLUDE_DIRS}" STREQUAL "")
else()
set(OPENSSL_LIBRARIES ${LWS_OPENSSL_LIBRARIES})
set(OPENSSL_INCLUDE_DIRS ${LWS_OPENSSL_INCLUDE_DIRS})
set(OPENSSL_FOUND 1)
endif()
endif()
if (LWS_WITH_SSL AND LWS_USE_CYASSL)
if ("${LWS_CYASSL_LIBRARIES}" STREQUAL "" OR "${LWS_CYASSL_INCLUDE_DIRS}" STREQUAL "")
if (NOT CYASSL_FOUND)
message(FATAL_ERROR "You must set LWS_CYASSL_LIBRARIES and LWS_CYASSL_INCLUDE_DIRS when LWS_USE_CYASSL is turned on.")
endif()
else()
set(CYASSL_LIBRARIES ${LWS_CYASSL_LIBRARIES})
set(CYASSL_INCLUDE_DIRS ${LWS_CYASSL_INCLUDE_DIRS})
set(CYASSL_FOUND 1)
endif()
set(USE_CYASSL 1)
endif()
if (LWS_WITH_ZLIB AND NOT LWS_USE_BUNDLED_ZLIB)
if ("${LWS_ZLIB_LIBRARIES}" STREQUAL "" OR "${LWS_ZLIB_INCLUDE_DIRS}" STREQUAL "")
else()
set(ZLIB_LIBRARIES ${LWS_ZLIB_LIBRARIES})
set(ZLIB_INCLUDE_DIRS ${LWS_ZLIB_INCLUDE_DIRS})
set(ZLIB_FOUND 1)
endif()
endif()
if (LWS_WITH_LIBEV)
if ("${LWS_LIBEV_LIBRARIES}" STREQUAL "" OR "${LWS_LIBEV_INCLUDE_DIRS}" STREQUAL "")
else()
set(LIBEV_LIBRARIES ${LWS_LIBEV_LIBRARIES})
set(LIBEV_INCLUDE_DIRS ${LWS_LIBEV_INCLUDE_DIRS})
set(LIBEV_FOUND 1)
endif()
endif()
# FIXME: This must be runtime-only option.
# The base dir where the test-apps look for the SSL certs. # The base dir where the test-apps look for the SSL certs.
set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory") set(LWS_OPENSSL_CLIENT_CERTS ../share CACHE PATH "Server SSL certificate directory")
if (WIN32) if (WIN32)
@ -78,16 +149,6 @@ else()
set(LWS_OPENSSL_CLIENT_CERTS /etc/pki/tls/certs/ CACHE PATH "Client SSL certificate directory") set(LWS_OPENSSL_CLIENT_CERTS /etc/pki/tls/certs/ CACHE PATH "Client SSL certificate directory")
endif() endif()
set(LWS_CYASSL_LIB CACHE PATH "Path to the CyaSSL library")
set(LWS_CYASSL_INCLUDE_DIRS CACHE PATH "Path to the CyaSSL include directory")
if (LWS_USE_CYASSL)
if ("${LWS_CYASSL_LIB}" STREQUAL "" OR "${LWS_CYASSL_INCLUDE_DIRS}" STREQUAL "")
message(FATAL_ERROR "You must set LWS_CYASSL_LIB and LWS_CYASSL_INCLUDE_DIRS when LWS_USE_CYASSL is turned on")
endif()
set(USE_CYASSL 1)
endif()
if (LWS_WITHOUT_EXTENSIONS) if (LWS_WITHOUT_EXTENSIONS)
set(LWS_NO_EXTENSIONS 1) set(LWS_NO_EXTENSIONS 1)
endif() endif()
@ -116,15 +177,8 @@ if (LWS_WITHOUT_CLIENT)
set(LWS_NO_CLIENT 1) set(LWS_NO_CLIENT 1)
endif() endif()
if (LWS_WITHOUT_DEBUG)
set(_DEBUG 0)
else()
set(_DEBUG 1)
endif()
if (LWS_WITH_LIBEV) if (LWS_WITH_LIBEV)
set(LWS_USE_LIBEV 1) set(LWS_USE_LIBEV 1)
set(LWS_NO_EXTERNAL_POLL 1)
endif() endif()
if (LWS_IPV6) if (LWS_IPV6)
@ -149,7 +203,7 @@ foreach(KEYWORD "inline" "__inline__" "__inline")
CHECK_C_SOURCE_COMPILES( CHECK_C_SOURCE_COMPILES(
" "
#include <stdio.h> #include <stdio.h>
KEYWORD void a() {} static KEYWORD void a() {}
int main(int argc, char **argv) { a(); return 0; } int main(int argc, char **argv) { a(); return 0; }
" HAVE_${KEYWORD}) " HAVE_${KEYWORD})
endforeach() endforeach()
@ -172,10 +226,6 @@ SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/lib")
# architectures, notably Mac OS X, need this. # architectures, notably Mac OS X, need this.
SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}") SET(CMAKE_INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}")
# So we can include the CMake generated config file only when
# building with CMAKE.
add_definitions(-DCMAKE_BUILD)
include(CheckFunctionExists) include(CheckFunctionExists)
include(CheckIncludeFile) include(CheckIncludeFile)
include(CheckIncludeFiles) include(CheckIncludeFiles)
@ -197,7 +247,6 @@ if (NOT HAVE_GETIFADDRS)
if (LWS_WITHOUT_BUILTIN_GETIFADDRS) if (LWS_WITHOUT_BUILTIN_GETIFADDRS)
message(FATAL_ERROR "No getifaddrs was found on the system. Turn off the LWS_WITHOUT_BUILTIN_GETIFADDRS compile option to use the supplied BSD version.") message(FATAL_ERROR "No getifaddrs was found on the system. Turn off the LWS_WITHOUT_BUILTIN_GETIFADDRS compile option to use the supplied BSD version.")
endif() endif()
set(LWS_BUILTIN_GETIFADDRS 1) set(LWS_BUILTIN_GETIFADDRS 1)
endif() endif()
@ -244,9 +293,9 @@ if (NOT HAVE_REALLOC)
set(realloc rpl_realloc) set(realloc rpl_realloc)
endif() endif()
# Generate the config.h that includes all the compilation settings. # Generate the lws_config.h that includes all the compilation settings.
configure_file( configure_file(
"${PROJECT_SOURCE_DIR}/config.h.cmake" "${PROJECT_SOURCE_DIR}/lws_config.h.in"
"${PROJECT_BINARY_DIR}/lws_config.h") "${PROJECT_BINARY_DIR}/lws_config.h")
if (MSVC) if (MSVC)
@ -259,13 +308,11 @@ include_directories("${PROJECT_SOURCE_DIR}/lib")
# Group headers and sources. # Group headers and sources.
# Some IDEs use this for nicer file structure. # Some IDEs use this for nicer file structure.
set(HDR_PRIVATE set(HDR_PRIVATE
lib/private-libwebsockets.h lib/private-libwebsockets.h)
)
set(HDR_PUBLIC set(HDR_PUBLIC
"${PROJECT_SOURCE_DIR}/lib/libwebsockets.h" "${PROJECT_SOURCE_DIR}/lib/libwebsockets.h"
"${PROJECT_BINARY_DIR}/lws_config.h" "${PROJECT_BINARY_DIR}/lws_config.h")
)
set(SOURCES set(SOURCES
lib/base64-decode.c lib/base64-decode.c
@ -284,81 +331,69 @@ if (NOT LWS_WITHOUT_CLIENT)
list(APPEND SOURCES list(APPEND SOURCES
lib/client.c lib/client.c
lib/client-handshake.c lib/client-handshake.c
lib/client-parser.c lib/client-parser.c)
)
endif() endif()
if (LWS_WITH_SSL) if (LWS_WITH_SSL)
list(APPEND SOURCES list(APPEND SOURCES
lib/ssl.c lib/ssl.c)
)
endif() endif()
if (LWS_WITH_HTTP2) if (LWS_WITH_HTTP2)
list(APPEND SOURCES list(APPEND SOURCES
lib/http2.c lib/http2.c
lib/hpack.c lib/hpack.c
lib/ssl-http2.c lib/ssl-http2.c)
)
endif() endif()
# select the active platform files # select the active platform files
if (WIN32) if (WIN32)
list(APPEND SOURCES list(APPEND SOURCES
lib/lws-plat-win.c lib/lws-plat-win.c)
)
else() else()
list(APPEND SOURCES list(APPEND SOURCES
lib/lws-plat-unix.c lib/lws-plat-unix.c)
)
endif() endif()
if (NOT LWS_WITHOUT_SERVER) if (NOT LWS_WITHOUT_SERVER)
list(APPEND SOURCES list(APPEND SOURCES
lib/server.c lib/server.c
lib/server-handshake.c lib/server-handshake.c)
)
endif() endif()
if (NOT LWS_WITHOUT_EXTENSIONS) if (NOT LWS_WITHOUT_EXTENSIONS)
list(APPEND HDR_PRIVATE list(APPEND HDR_PRIVATE
lib/extension-deflate-frame.h lib/extension-deflate-frame.h
lib/extension-deflate-stream.h lib/extension-deflate-stream.h)
)
list(APPEND SOURCES list(APPEND SOURCES
lib/extension.c lib/extension.c
lib/extension-deflate-frame.c lib/extension-deflate-frame.c
lib/extension-deflate-stream.c lib/extension-deflate-stream.c)
)
endif() endif()
if (LWS_WITH_LIBEV) if (LWS_WITH_LIBEV)
list(APPEND SOURCES list(APPEND SOURCES
lib/libev.c lib/libev.c)
)
endif(LWS_WITH_LIBEV) endif(LWS_WITH_LIBEV)
# Add helper files for Windows. # Add helper files for Windows.
if (WIN32) if (WIN32)
set(WIN32_HELPERS_PATH win32port/win32helpers) set(WIN32_HELPERS_PATH win32port/win32helpers)
include_directories(${WIN32_HELPERS_PATH}) include_directories(${WIN32_HELPERS_PATH})
else(WIN32) else()
# Unix. # Unix.
if (NOT LWS_WITHOUT_DAEMONIZE) if (NOT LWS_WITHOUT_DAEMONIZE)
list(APPEND SOURCES list(APPEND SOURCES
lib/daemonize.c lib/daemonize.c)
)
endif() endif()
endif(WIN32) endif()
if (UNIX) if (UNIX)
if (NOT HAVE_GETIFADDRS) if (NOT HAVE_GETIFADDRS)
list(APPEND HDR_PRIVATE lib/getifaddrs.h) list(APPEND HDR_PRIVATE lib/getifaddrs.h)
list(APPEND SOURCES lib/getifaddrs.c) list(APPEND SOURCES lib/getifaddrs.c)
endif() endif()
endif(UNIX) endif()
if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
include (CheckCCompilerFlag) include (CheckCCompilerFlag)
@ -367,9 +402,9 @@ if (CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
set(VISIBILITY_FLAG -fvisibility=hidden) set(VISIBILITY_FLAG -fvisibility=hidden)
endif() endif()
if (UNIX) if (UNIX)
set( CMAKE_C_FLAGS "-Wall -Werror -O3 ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" ) set(CMAKE_C_FLAGS "-Wall -Werror -O3 ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" )
else(UNIX) else(UNIX)
set( CMAKE_C_FLAGS "-Wall -O3 ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" ) set(CMAKE_C_FLAGS "-Wall -O3 ${VISIBILITY_FLAG} ${CMAKE_C_FLAGS}" )
endif(UNIX) endif(UNIX)
endif () endif ()
@ -380,42 +415,41 @@ source_group("Sources" FILES ${SOURCES})
# #
# Create the lib. # Create the lib.
# #
add_library(websockets STATIC set(LWS_LIBRARIES)
if (LWS_WITH_STATIC)
add_library(websockets STATIC
${HDR_PRIVATE} ${HDR_PRIVATE}
${HDR_PUBLIC} ${HDR_PUBLIC}
${SOURCES}) ${SOURCES})
add_library(websockets_shared SHARED list(APPEND LWS_LIBRARIES websockets)
endif()
if (LWS_WITH_SHARED)
add_library(websockets_shared SHARED
${HDR_PRIVATE} ${HDR_PRIVATE}
${HDR_PUBLIC} ${HDR_PUBLIC}
${SOURCES}) ${SOURCES})
list(APPEND LWS_LIBRARIES websockets_shared)
endif()
if (WIN32) if (WIN32)
# On Windows libs have the same file ending (.lib) if (LWS_WITH_SHARED)
# for both static and shared libraries, so we
# need a unique name for the static one.
set_target_properties(websockets
PROPERTIES
OUTPUT_NAME websockets_static)
# Compile as DLL (export function declarations) # Compile as DLL (export function declarations)
set_property( set_property(
TARGET websockets_shared TARGET websockets_shared
PROPERTY COMPILE_DEFINITIONS PROPERTY COMPILE_DEFINITIONS
LWS_DLL LWS_DLL
LWS_INTERNAL LWS_INTERNAL)
) endif()
endif(WIN32) elseif(APPLE)
if (LWS_WITH_SHARED)
# We want the shared lib to be named "libwebsockets" set_property(TARGET websockets_shared PROPERTY MACOSX_RPATH YES)
# not "libwebsocket_shared". endif()
set_target_properties(websockets_shared endif()
PROPERTIES
OUTPUT_NAME websockets)
# Set the so version of the lib. # Set the so version of the lib.
# Equivalent to LDFLAGS=-version-info x:x:x # Equivalent to LDFLAGS=-version-info x:x:x
if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
foreach(lib websockets websockets_shared) foreach(lib ${LWS_LIBRARIES})
set_target_properties(${lib} set_target_properties(${lib}
PROPERTIES PROPERTIES
SOVERSION ${SOVERSION}) SOVERSION ${SOVERSION})
@ -431,11 +465,9 @@ set(LIB_LIST)
# #
# ZLIB (Only needed for deflate extensions). # ZLIB (Only needed for deflate extensions).
# #
if (NOT LWS_WITHOUT_EXTENSIONS) if (LWS_WITH_ZLIB)
if (WIN32 AND NOT LWS_USE_EXTERNAL_ZLIB) if (LWS_USE_BUNDLED_ZLIB)
message("Using included Zlib version") if (WIN32)
# Compile ZLib if needed.
set(WIN32_ZLIB_PATH "win32port/zlib") set(WIN32_ZLIB_PATH "win32port/zlib")
set(ZLIB_SRCS set(ZLIB_SRCS
${WIN32_ZLIB_PATH}/adler32.c ${WIN32_ZLIB_PATH}/adler32.c
@ -453,30 +485,26 @@ if (NOT LWS_WITHOUT_EXTENSIONS)
${WIN32_ZLIB_PATH}/inftrees.c ${WIN32_ZLIB_PATH}/inftrees.c
${WIN32_ZLIB_PATH}/trees.c ${WIN32_ZLIB_PATH}/trees.c
${WIN32_ZLIB_PATH}/uncompr.c ${WIN32_ZLIB_PATH}/uncompr.c
${WIN32_ZLIB_PATH}/zutil.c ${WIN32_ZLIB_PATH}/zutil.c)
) add_library(zlib_internal STATIC ${ZLIB_SRCS})
# Create the library.
add_library(ZLIB STATIC ${ZLIB_SRCS})
# Set the same variables as find_package would.
set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH}) set(ZLIB_INCLUDE_DIRS ${WIN32_ZLIB_PATH})
get_property(ZLIB_LIBRARIES TARGET ZLIB PROPERTY LOCATION) get_property(ZLIB_LIBRARIES TARGET zlib_internal PROPERTY LOCATION)
set(ZLIB_FOUND 1) set(ZLIB_FOUND 1)
# Make sure zlib_internal is compiled before the libs.
foreach (lib ${LWS_LIBRARIES})
add_dependencies(${lib} zlib_internal)
endforeach()
else() else()
message(FATAL_ERROR "Don't have bundled zlib for that platform")
endif()
elseif (NOT ZLIB_FOUND)
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)
endif() endif()
message("zlib include dirs: ${ZLIB_INCLUDE_DIRS}")
# Make sure ZLib is compiled before the libs. message("zlib libraries: ${ZLIB_LIBRARIES}")
foreach (lib websockets websockets_shared)
add_dependencies(${lib} ZLIB)
endforeach()
message("ZLib include dirs: ${ZLIB_INCLUDE_DIRS}")
message("ZLib libraries: ${ZLIB_LIBRARIES}")
include_directories(${ZLIB_INCLUDE_DIRS}) include_directories(${ZLIB_INCLUDE_DIRS})
list(APPEND LIB_LIST ${ZLIB_LIBRARIES}) list(APPEND LIB_LIST ${ZLIB_LIBRARIES})
endif(NOT LWS_WITHOUT_EXTENSIONS) endif()
# #
# OpenSSL # OpenSSL
@ -487,41 +515,44 @@ if (LWS_WITH_SSL)
if (LWS_USE_CYASSL) if (LWS_USE_CYASSL)
# Use CyaSSL as OpenSSL replacement. # Use CyaSSL as OpenSSL replacement.
# TODO: Add a find_package command for this also. # TODO: Add a find_package command for this also.
message("CyaSSL include dir: ${LWS_CYASSL_INCLUDE_DIRS}") message("CyaSSL include dir: ${CYASSL_INCLUDE_DIRS}")
message("CyaSSL libraries: ${LWS_CYASSL_LIB}") message("CyaSSL libraries: ${CYASSL_LIBRARIES}")
# Additional to the root directory we need to include # Additional to the root directory we need to include
# the cyassl/ subdirectory which contains the OpenSSL # the cyassl/ subdirectory which contains the OpenSSL
# compatability layer headers. # compatability layer headers.
foreach(inc ${LWS_CYASSL_INCLUDE_DIRS}) foreach(inc ${CYASSL_LIBRARIES})
include_directories("${inc}" "${inc}/cyassl") include_directories("${inc}" "${inc}/cyassl")
endforeach() endforeach()
list(APPEND LIB_LIST "${LWS_CYASSL_LIB}") list(APPEND LIB_LIST "${CYASSL_LIBRARIES}")
else() else()
if (OPENSSL_ROOT_DIR) if (NOT OPENSSL_FOUND)
set(OPENSSL_INCLUDE_DIR "${OPENSSL_ROOT_DIR}/include")
set(OPENSSL_LIBRARIES "${OPENSSL_ROOT_DIR}/lib/libssl.so" "${OPENSSL_ROOT_DIR}/lib/libcrypto.so")
else(OPENSSL_ROOT_DIR)
# TODO: Add support for STATIC also. # TODO: Add support for STATIC also.
find_package(OpenSSL REQUIRED) find_package(OpenSSL REQUIRED)
endif(OPENSSL_ROOT_DIR) set(OPENSSL_INCLUDE_DIRS "${OPENSSL_INCLUDE_DIR}")
endif()
message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIR}") message("OpenSSL include dir: ${OPENSSL_INCLUDE_DIRS}")
message("OpenSSL libraries: ${OPENSSL_LIBRARIES}") message("OpenSSL libraries: ${OPENSSL_LIBRARIES}")
include_directories("${OPENSSL_INCLUDE_DIR}") include_directories("${OPENSSL_INCLUDE_DIRS}")
list(APPEND LIB_LIST ${OPENSSL_LIBRARIES}) list(APPEND LIB_LIST ${OPENSSL_LIBRARIES})
# Link against dynamic linking functions.
# (Don't link directly to libdl since it is not needed on all platforms, it's now a part of libc).
list(APPEND LIB_LIST ${CMAKE_DL_LIBS})
endif() endif()
endif(LWS_WITH_SSL) endif(LWS_WITH_SSL)
if (LWS_WITH_LIBEV) if (LWS_WITH_LIBEV)
list(APPEND LIB_LIST "ev") if (NOT LIBEV_FOUND)
find_path(LIBEV_INCLUDE_DIRS NAMES ev.h)
find_library(LIBEV_LIBRARIES NAMES ev)
if(LIBEV_INCLUDE_DIRS AND LIBEV_LIBRARIES)
set(LIBEV_FOUND 1)
endif()
endif()
message("libev include dir: ${LIBEV_INCLUDE_DIRS}")
message("libev libraries: ${LIBEV_LIBRARIES}")
include_directories("${LIBEV_INCLUDE_DIRS}")
list(APPEND LIB_LIST ${LIBEV_LIBRARIES})
endif(LWS_WITH_LIBEV) endif(LWS_WITH_LIBEV)
# #
@ -538,7 +569,7 @@ if (UNIX)
endif() endif()
# Setup the linking for all libs. # Setup the linking for all libs.
foreach (lib websockets websockets_shared) foreach (lib ${LWS_LIBRARIES})
target_link_libraries(${lib} ${LIB_LIST}) target_link_libraries(${lib} ${LIB_LIST})
endforeach() endforeach()
@ -573,12 +604,18 @@ if (NOT LWS_WITHOUT_TESTAPPS)
add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR}) add_executable(${TEST_NAME} ${TEST_SRCS} ${TEST_HDR})
if (LWS_LINK_TESTAPPS_DYNAMIC) if (LWS_LINK_TESTAPPS_DYNAMIC)
if (NOT LWS_WITH_SHARED)
message(FATAL_ERROR "Build of shared library is disabled. LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_SHARED.")
endif()
target_link_libraries(${TEST_NAME} websockets_shared) target_link_libraries(${TEST_NAME} websockets_shared)
add_dependencies(${TEST_NAME} websockets_shared) add_dependencies(${TEST_NAME} websockets_shared)
else(LWS_LINK_TESTAPPS_DYNAMIC) else()
if (NOT LWS_WITH_STATIC)
message(FATAL_ERROR "Build of static library is disabled. Disabled LWS_LINK_TESTAPPS_DYNAMIC must be combined with LWS_WITH_STATIC.")
endif()
target_link_libraries(${TEST_NAME} websockets) target_link_libraries(${TEST_NAME} websockets)
add_dependencies(${TEST_NAME} websockets) add_dependencies(${TEST_NAME} websockets)
endif(LWS_LINK_TESTAPPS_DYNAMIC) endif()
# Set test app specific defines. # Set test app specific defines.
set_property(TARGET ${TEST_NAME} set_property(TARGET ${TEST_NAME}
@ -750,7 +787,6 @@ if (NOT LWS_WITHOUT_TESTAPPS)
add_custom_command(TARGET ${TARGET_BIN} add_custom_command(TARGET ${TARGET_BIN}
POST_BUILD POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM) COMMAND "${CMAKE_COMMAND}" -E copy "${LIBEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
add_custom_command(TARGET ${TARGET_BIN} add_custom_command(TARGET ${TARGET_BIN}
POST_BUILD POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM) COMMAND "${CMAKE_COMMAND}" -E copy "${SSLEAY_BIN}" "$<TARGET_FILE_DIR:${TARGET_BIN}>" VERBATIM)
@ -809,7 +845,7 @@ endif()
set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files") set(LWS_INSTALL_CMAKE_DIR ${DEF_INSTALL_CMAKE_DIR} CACHE PATH "Installation directory for CMake files")
# Export targets (This is used for other CMake projects to easily find the libraries and include files). # Export targets (This is used for other CMake projects to easily find the libraries and include files).
export(TARGETS websockets websockets_shared export(TARGETS ${LWS_LIBRARIES}
FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake") FILE "${PROJECT_BINARY_DIR}/LibwebsocketsTargets.cmake")
export(PACKAGE libwebsockets) export(PACKAGE libwebsockets)
@ -845,7 +881,7 @@ configure_file(${PROJECT_SOURCE_DIR}/cmake/LibwebsocketsConfigVersion.cmake.in
${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake ${PROJECT_BINARY_DIR}/LibwebsocketsConfigVersion.cmake
@ONLY) @ONLY)
set_target_properties(websockets websockets_shared set_target_properties(${LWS_LIBRARIES}
PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}") PROPERTIES PUBLIC_HEADER "${HDR_PUBLIC}")
# #
@ -853,7 +889,7 @@ set_target_properties(websockets websockets_shared
# #
# Install libs and headers. # Install libs and headers.
install(TARGETS websockets websockets_shared install(TARGETS ${LWS_LIBRARIES}
EXPORT LibwebsocketsTargets EXPORT LibwebsocketsTargets
LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries LIBRARY DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries ARCHIVE DESTINATION "${LWS_INSTALL_LIB_DIR}${LIB_SUFFIX}" COMPONENT libraries
@ -893,13 +929,13 @@ if (RPMTools_FOUND)
endif() endif()
message("---------------------------------------------------------------------") message("---------------------------------------------------------------------")
message(" Settings: (For more help do cmake -LH <srcpath>") message(" Settings: (For more help do cmake -LH <srcpath>)")
message("---------------------------------------------------------------------") message("---------------------------------------------------------------------")
message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)") message(" LWS_WITH_SSL = ${LWS_WITH_SSL} (SSL Support)")
message(" LWS_SSL_CLIENT_USE_OS_CA_CERTS = ${LWS_SSL_CLIENT_USE_OS_CA_CERTS}") message(" LWS_SSL_CLIENT_USE_OS_CA_CERTS = ${LWS_SSL_CLIENT_USE_OS_CA_CERTS}")
message(" LWS_USE_CYASSL = ${LWS_USE_CYASSL} (CyaSSL replacement for OpenSSL)") message(" LWS_USE_CYASSL = ${LWS_USE_CYASSL} (CyaSSL replacement for OpenSSL)")
if (LWS_USE_CYASSL) if (LWS_USE_CYASSL)
message(" LWS_CYASSL_LIB = ${LWS_CYASSL_LIB}") message(" LWS_CYASSL_LIBRARIES = ${LWS_CYASSL_LIBRARIES}")
message(" LWS_CYASSL_INCLUDE_DIRS = ${LWS_CYASSL_INCLUDE_DIRS}") message(" LWS_CYASSL_INCLUDE_DIRS = ${LWS_CYASSL_INCLUDE_DIRS}")
endif() endif()
message(" LWS_WITHOUT_BUILTIN_GETIFADDRS = ${LWS_WITHOUT_BUILTIN_GETIFADDRS}") message(" LWS_WITHOUT_BUILTIN_GETIFADDRS = ${LWS_WITHOUT_BUILTIN_GETIFADDRS}")
@ -912,7 +948,6 @@ message(" LWS_WITHOUT_TEST_SERVER_EXTPOLL = ${LWS_WITHOUT_TEST_SERVER_EXTPOLL}")
message(" LWS_WITHOUT_TEST_PING = ${LWS_WITHOUT_TEST_PING}") message(" LWS_WITHOUT_TEST_PING = ${LWS_WITHOUT_TEST_PING}")
message(" LWS_WITHOUT_TEST_CLIENT = ${LWS_WITHOUT_TEST_CLIENT}") message(" LWS_WITHOUT_TEST_CLIENT = ${LWS_WITHOUT_TEST_CLIENT}")
message(" LWS_WITHOUT_TEST_FRAGGLE = ${LWS_WITHOUT_TEST_FRAGGLE}") message(" LWS_WITHOUT_TEST_FRAGGLE = ${LWS_WITHOUT_TEST_FRAGGLE}")
message(" LWS_WITHOUT_DEBUG = ${LWS_WITHOUT_DEBUG}")
message(" LWS_WITHOUT_EXTENSIONS = ${LWS_WITHOUT_EXTENSIONS}") message(" LWS_WITHOUT_EXTENSIONS = ${LWS_WITHOUT_EXTENSIONS}")
message(" LWS_WITH_LATENCY = ${LWS_WITH_LATENCY}") message(" LWS_WITH_LATENCY = ${LWS_WITH_LATENCY}")
message(" LWS_WITHOUT_DAEMONIZE = ${LWS_WITHOUT_DAEMONIZE}") message(" LWS_WITHOUT_DAEMONIZE = ${LWS_WITHOUT_DAEMONIZE}")
@ -922,9 +957,13 @@ message(" LWS_WITH_HTTP2 = ${LWS_WITH_HTTP2}")
message("---------------------------------------------------------------------") message("---------------------------------------------------------------------")
# These will be available to parent projects including libwebsockets using add_subdirectory() # These will be available to parent projects including libwebsockets using add_subdirectory()
set(LIBWEBSOCKETS_LIBRARIES websocket websockets_shared CACHE STRING "Libwebsocket libraries") set(LIBWEBSOCKETS_LIBRARIES ${LWS_LIBRARIES} CACHE STRING "Libwebsocket libraries")
set(LIBWEBSOCKETS_LIBRARIES_STATIC websocket CACHE STRING "Libwebsocket static library") if (LWS_WITH_STATIC)
set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library") set(LIBWEBSOCKETS_LIBRARIES_STATIC websocket CACHE STRING "Libwebsocket static library")
endif()
if (LWS_WITH_SHARED)
set(LIBWEBSOCKETS_LIBRARIES_SHARED websockets_shared CACHE STRING "Libwebsocket shared library")
endif()
# This must always be last! # This must always be last!
include(CPack) include(CPack)

View file

@ -1,7 +1,9 @@
/* config.h.in. Generated from configure.ac by autoheader. */ /* config.h.in. Generated from configure.ac by autoheader. */
#ifndef WIN32 #ifndef NDEBUG
#cmakedefine _DEBUG #ifndef _DEBUG
#define _DEBUG
#endif
#endif #endif
/* Define to 1 to use CyaSSL as a replacement for OpenSSL. /* Define to 1 to use CyaSSL as a replacement for OpenSSL.
@ -146,9 +148,6 @@
*/ */
#undef LT_OBJDIR // We're not using libtool #undef LT_OBJDIR // We're not using libtool
/* Define to 1 if you have the ANSI C header files. */
#cmakedefine STDC_HEADERS
/* Version number of package */ /* Version number of package */
#cmakedefine VERSION #cmakedefine VERSION
@ -171,4 +170,4 @@
//#cmakedefine vfork //#cmakedefine vfork
/* Define if the inline keyword doesn't exist. */ /* Define if the inline keyword doesn't exist. */
#cmakedefine inline #cmakedefine inline ${inline}

View file

@ -45,7 +45,7 @@ Section "Files" SecInstall
File "..\build\bin\Release\libwebsockets-test-ping.exe" File "..\build\bin\Release\libwebsockets-test-ping.exe"
File /nonfatal "..\build\bin\Release\libwebsockets-test-server.exe" File /nonfatal "..\build\bin\Release\libwebsockets-test-server.exe"
File /nonfatal "..\build\bin\Release\libwebsockets-test-server-extpoll.exe" File /nonfatal "..\build\bin\Release\libwebsockets-test-server-extpoll.exe"
File "..\build\bin\Release\websockets.dll" File "..\build\bin\Release\websockets_shared.dll"
SetOutPath "$INSTDIR\libwebsockets-test-server" SetOutPath "$INSTDIR\libwebsockets-test-server"
File /nonfatal "..\build\bin\share\libwebsockets-test-server\favicon.ico" File /nonfatal "..\build\bin\share\libwebsockets-test-server\favicon.ico"
@ -56,8 +56,8 @@ Section "Files" SecInstall
File /nonfatal "..\build\bin\share\libwebsockets-test-server\test.html" File /nonfatal "..\build\bin\share\libwebsockets-test-server\test.html"
SetOutPath "$INSTDIR\lib" SetOutPath "$INSTDIR\lib"
File "..\build\lib\Release\websockets_shared.lib"
File "..\build\lib\Release\websockets.lib" File "..\build\lib\Release\websockets.lib"
File "..\build\lib\Release\websockets_static.lib"
SetOutPath "$INSTDIR\include" SetOutPath "$INSTDIR\include"
File "..\lib\libwebsockets.h" File "..\lib\libwebsockets.h"
@ -86,7 +86,7 @@ Section "Uninstall"
Delete "$INSTDIR\libwebsockets-test-ping.exe" Delete "$INSTDIR\libwebsockets-test-ping.exe"
Delete "$INSTDIR\libwebsockets-test-server.exe" Delete "$INSTDIR\libwebsockets-test-server.exe"
Delete "$INSTDIR\libwebsockets-test-server-extpoll.exe" Delete "$INSTDIR\libwebsockets-test-server-extpoll.exe"
Delete "$INSTDIR\websockets.dll" Delete "$INSTDIR\websockets_shared.dll"
Delete "$INSTDIR\libwebsockets-test-server\favicon.ico" Delete "$INSTDIR\libwebsockets-test-server\favicon.ico"
Delete "$INSTDIR\libwebsockets-test-server\leaf.jpg" Delete "$INSTDIR\libwebsockets-test-server\leaf.jpg"
@ -96,8 +96,8 @@ Section "Uninstall"
Delete "$INSTDIR\libwebsockets-test-server\test.html" Delete "$INSTDIR\libwebsockets-test-server\test.html"
RMDir "$INSTDIR\libwebsockets-test-server" RMDir "$INSTDIR\libwebsockets-test-server"
Delete "$INSTDIR\lib\websockets_shared.lib"
Delete "$INSTDIR\lib\websockets.lib" Delete "$INSTDIR\lib\websockets.lib"
Delete "$INSTDIR\lib\websockets_static.lib"
RMDir "$INSTDIR\lib" RMDir "$INSTDIR\lib"
Delete "$INSTDIR\include\libwebsockets.h" Delete "$INSTDIR\include\libwebsockets.h"