-
Notifications
You must be signed in to change notification settings - Fork 2
/
CMakeLists.txt
71 lines (65 loc) · 1.52 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
CMAKE_MINIMUM_REQUIRED(VERSION 3.2)
project(uWS)
set(VERSION 0.1)
option(USE_LIBUV "use libuv" OFF)
option(BUILD_DEMO "build demo" OFF)
find_package(OpenSSL REQUIRED)
find_package(ZLIB REQUIRED)
if (USE_LIBUV)
find_package(PkgConfig REQUIRED)
pkg_check_modules(libuv REQUIRED IMPORTED_TARGET libuv)
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUWS_THREADSAFE")
endif()
find_package(Threads REQUIRED)
set(CMAKE_CXX_STANDARD 11)
if (CROSS_COMPILE_CXXFLAGS)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CROSS_COMPILE_CXXFLAGS}")
endif()
file(GLOB_RECURSE UWS_SOURCES
src/*.h
src/*.cpp
)
add_library(uWS
${UWS_SOURCES}
)
target_include_directories(uWS INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:include/uWS>
)
target_link_libraries(uWS PRIVATE
OpenSSL::Crypto
OpenSSL::SSL
ZLIB::ZLIB
Threads::Threads
)
if (USE_LIBUV)
target_link_libraries(uWS PUBLIC PkgConfig::libuv)
endif()
if (NOT BUILD_SHARED_LIBS)
set_target_properties(uWS PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
if (NOT USE_LIBUV)
target_compile_options(uWS PUBLIC -DUWS_THREADSAFE)
endif()
file(GLOB UWS_HEADERS
src/*.h
)
set_target_properties(uWS PROPERTIES PUBLIC_HEADER "${UWS_HEADERS}")
install(TARGETS uWS
EXPORT uWS-config
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
PUBLIC_HEADER DESTINATION include/uWS
)
install(EXPORT uWS-config
DESTINATION lib/cmake/uWS
NAMESPACE uWS::
)
# demo: echo server
if (BUILD_DEMO)
add_executable(echo examples/echo.cpp)
target_link_libraries(echo
uWS
)
endif(BUILD_DEMO)