forked from sprinfall/webcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCMakeLists.txt
152 lines (124 loc) · 4.4 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
cmake_minimum_required(VERSION 3.1.0)
if(POLICY CMP0074)
# find_package() uses <PackageName>_ROOT variables.
# This policy was introduced in CMake version 3.12.
cmake_policy(SET CMP0074 NEW)
endif()
project(webcc)
option(WEBCC_ENABLE_AUTOTEST "Build automation test?" OFF)
option(WEBCC_ENABLE_UNITTEST "Build unit test?" OFF)
option(WEBCC_ENABLE_EXAMPLES "Build examples?" OFF)
if(WIN32)
option(WEBCC_ENABLE_VLD "Enable VLD (Visual Leak Detector)?" OFF)
if(WEBCC_ENABLE_VLD)
add_definitions(-DWEBCC_ENABLE_VLD)
endif()
endif()
set(WEBCC_ENABLE_LOG 1 CACHE STRING "Enable logging? (1:Yes, 0:No)")
set(WEBCC_LOG_LEVEL 2 CACHE STRING "Log level (0:VERB, 1:INFO, 2:USER, 3:WARN or 4:ERRO)")
set(WEBCC_ENABLE_SSL 0 CACHE STRING "Enable SSL/HTTPS (need OpenSSL)? (1:Yes, 0:No)")
set(WEBCC_ENABLE_GZIP 0 CACHE STRING "Enable gzip compression (need Zlib)? (1:Yes, 0:No)")
if(WEBCC_ENABLE_UNITTEST)
enable_testing()
endif()
# Automatically detect _WIN32_WINNT for Asio.
# See: https://stackoverflow.com/a/40217291
if(WIN32)
macro(get_WIN32_WINNT version)
if(CMAKE_SYSTEM_VERSION)
set(ver ${CMAKE_SYSTEM_VERSION})
string(REGEX MATCH "^([0-9]+).([0-9])" ver ${ver})
string(REGEX MATCH "^([0-9]+)" verMajor ${ver})
# Check for Windows 10, b/c we'll need to convert to hex 'A'.
if("${verMajor}" MATCHES "10")
set(verMajor "A")
string(REGEX REPLACE "^([0-9]+)" ${verMajor} ver ${ver})
endif("${verMajor}" MATCHES "10")
# Remove all remaining '.' characters.
string(REPLACE "." "" ver ${ver})
# Prepend each digit with a zero.
string(REGEX REPLACE "([0-9A-Z])" "0\\1" ver ${ver})
set(${version} "0x${ver}")
endif(CMAKE_SYSTEM_VERSION)
endmacro(get_WIN32_WINNT)
get_WIN32_WINNT(ver)
# E.g., 0x0601 for Win7.
message(STATUS "_WIN32_WINNT=${ver}")
# Asio needs this!
add_definitions(-D_WIN32_WINNT=${ver})
endif()
if(WIN32)
# Disable warning on boost string algorithms.
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
endif()
# C++ standard requirements.
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)
# CMake 3.1.0+ required.
# See: https://stackoverflow.com/a/29871891
set(THREADS_PREFER_PTHREAD_FLAG ON)
find_package(Threads REQUIRED)
# Boost 1.66+ required.
set(Boost_USE_STATIC_LIBS ON)
set(Boost_USE_MULTITHREADED ON)
find_package(Boost 1.66.0 REQUIRED COMPONENTS system filesystem date_time)
if(Boost_FOUND)
include_directories(${Boost_INCLUDE_DIRS})
link_directories(${Boost_LIBRARY_DIRS})
endif()
if(WEBCC_ENABLE_SSL)
# Commented on 20190529.
# The static libs have linkage issues with VS2015 on Win10.
# set(OPENSSL_USE_STATIC_LIBS ON)
# set(OPENSSL_MSVC_STATIC_RT ON)
find_package(OpenSSL)
if(OPENSSL_FOUND)
include_directories(${OPENSSL_INCLUDE_DIR})
message(STATUS "OpenSSL libs: " ${OPENSSL_LIBRARIES})
endif()
endif()
include_directories(
# For including its own headers as "webcc/client.h".
${PROJECT_SOURCE_DIR}
# For including config.h as "webcc/config.h".
${PROJECT_BINARY_DIR}
)
set(THIRD_PARTY_DIR ${PROJECT_SOURCE_DIR}/third_party)
if(WIN32)
include_directories(${THIRD_PARTY_DIR}/win32/include)
link_directories(${THIRD_PARTY_DIR}/win32/lib)
endif()
include_directories(${THIRD_PARTY_DIR}/src)
if(WEBCC_ENABLE_GZIP)
# For using zlib on Windows.
if(WIN32)
add_subdirectory(${THIRD_PARTY_DIR}/src/zlib)
include_directories(${THIRD_PARTY_DIR}/src/zlib)
# For including CMake generated zconf.h.
include_directories(${PROJECT_BINARY_DIR}/third_party/src/zlib)
else()
find_package(ZLIB REQUIRED)
if(ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS})
endif()
endif()
endif()
add_subdirectory(webcc)
if(WEBCC_ENABLE_AUTOTEST OR WEBCC_ENABLE_EXAMPLES)
# For including jsoncpp as "json/json.h".
include_directories(${THIRD_PARTY_DIR}/src/jsoncpp)
add_subdirectory(${THIRD_PARTY_DIR}/src/jsoncpp)
endif()
if(WEBCC_ENABLE_AUTOTEST OR WEBCC_ENABLE_UNITTEST)
add_subdirectory(${THIRD_PARTY_DIR}/src/gtest)
endif()
if(WEBCC_ENABLE_AUTOTEST)
add_subdirectory(autotest)
endif()
if(WEBCC_ENABLE_EXAMPLES)
add_subdirectory(examples)
endif()
if(WEBCC_ENABLE_UNITTEST)
add_subdirectory(unittest)
endif()