-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
79 lines (63 loc) · 3.1 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
cmake_minimum_required(VERSION 3.9)
project(
lwspp
VERSION 0.0.1
DESCRIPTION "lwspp - C++ wrapper for the libwebsockets library"
LANGUAGES C CXX
)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -Wpedantic -fPIC")
# Adding the CXX standard value into the CMAKE_CXX_STANDARD because Clang ignores the CXX_STANDARD
# value for a mscOS. Bug: https://gitlab.kitware.com/cmake/cmake/-/issues/15943
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")
endif()
option(OPTION_BUILD_CLIENT "Enable or disable the build of the lwspp client library." ON)
option(OPTION_BUILD_SERVER "Enable or disable the build of the lwspp server library." ON)
option(OPTION_BUILD_SHARED "Enable or disable the build of shared lwspp libraries." ON)
option(OPTION_BUILD_STATIC "Enable or disable the build of static lwspp libraries." ON)
option(OPTION_BUILD_EXAMPLES "Enable or disable the build of example applications." OFF)
option(OPTION_BUILD_INTEGRATION_TESTS "Enable or disable the build of the integration tests application." OFF)
set(INSTALL_TESTS "" CACHE PATH "Specify the directory where the tests should be installed.
If you set this option, it will add the target install-lwspp-tests.")
set(INSTALL_EXAMPLES "" CACHE PATH "Specify the path where examples should be installed after the build.
Setting this option adds the corresponding install-'project name' target for each example.")
set(WEBSOCKETS_CUSTOM_DIR "" CACHE PATH "The custom libwebsockets library location. Expected that the directories ./include and ./lib are exsist.")
if (NOT OPTION_BUILD_CLIENT AND NOT OPTION_BUILD_SERVER)
message(FATAL_ERROR "No libraries selected for building. Please specify 'client', 'server', or both.")
endif()
if (NOT OPTION_BUILD_STATIC AND NOT OPTION_BUILD_SHARED)
message(FATAL_ERROR "No library type selected for building. Please specify 'static', 'shared', or both.")
endif()
if (OPTION_BUILD_INTEGRATION_TESTS AND (NOT OPTION_BUILD_CLIENT OR NOT OPTION_BUILD_SERVER))
message(FATAL_ERROR "Integration tests require both 'client' and 'server' libraries to be built.")
endif()
if (OPTION_BUILD_EXAMPLES AND (NOT OPTION_BUILD_CLIENT OR NOT OPTION_BUILD_SERVER))
message(FATAL_ERROR "Example applications require both 'client' and 'server' libraries to be built.")
endif()
if(APPLE)
set(WEBSOCKETS_HEADERS /opt/local/include)
endif()
unset(WEBSOCKETS_LIBRARY CACHE)
if(NOT "${WEBSOCKETS_CUSTOM_DIR}" STREQUAL "")
set(WEBSOCKETS_HEADERS ${WEBSOCKETS_CUSTOM_DIR}/include)
find_library(WEBSOCKETS_LIBRARY websockets PATHS "${WEBSOCKETS_CUSTOM_DIR}/lib" REQUIRED NO_DEFAULT_PATH)
else()
find_library(WEBSOCKETS_LIBRARY websockets REQUIRED)
endif()
message(STATUS "Found libwebsockets library: " ${WEBSOCKETS_LIBRARY})
add_library(websockets INTERFACE)
target_link_libraries(websockets INTERFACE ${WEBSOCKETS_LIBRARY})
if(OPTION_BUILD_CLIENT)
add_subdirectory(client)
endif()
if(OPTION_BUILD_SERVER)
add_subdirectory(server)
endif()
if(OPTION_BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
if(OPTION_BUILD_INTEGRATION_TESTS)
add_subdirectory(tests)
endif()