This repository has been archived by the owner on Apr 22, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
CMakeLists.txt
239 lines (180 loc) · 6.34 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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#
# Copyright (c) 2016 - 2019 Oleh Kulykov <[email protected]>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
cmake_minimum_required(VERSION 2.8)
project(libnhr C)
set(PACKAGE "libnhr")
set(CPACK_PACKAGE_NAME "${PACKAGE}")
set(CPACK_PACKAGE_VERSION_MAJOR "0")
set(CPACK_PACKAGE_VERSION_MINOR "5")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
set(CPACK_PACKAGE_VENDOR "[email protected]")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${PACKAGE} ${PACKAGE_VERSION}")
set(SOVERSION "0.5.3")
set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")
set(VERSION "${CPACK_PACKAGE_VERSION}")
include(CheckLibraryExists)
include(CheckFunctionExists)
include(CheckIncludeFile)
include(CheckTypeSize)
include(CheckSymbolExists)
include(CheckCCompilerFlag)
# COMMAND LINE OPTIONS
option(NHR_OPT_SHARED "Build shared lib" ON)
option(NHR_OPT_STATIC "Build static lib" ON)
option(NHR_OPT_NO_GET "Build without GET method support" OFF)
option(NHR_OPT_NO_POST "Build without POST method support" OFF)
option(NHR_OPT_NO_POST_DATA "Build without POSTing data support" OFF)
option(NHR_OPT_NO_RECV_CHUNKS "Build without processing response with chunked transfer encoding" OFF)
option(NHR_OPT_NO_SEND_CHUNKS "Build without sending big request body as chunks" OFF)
option(NHR_OPT_NO_GZIP "Build without gzip encoding/decoding support" OFF)
option(NHR_OPT_TESTS "Build libnhr tests" ON)
option(NHR_OPT_APPVEYOR_CI "Build with appveyor CI" OFF)
# C with -fPIC
check_c_compiler_flag("-fPIC" WITH_FPIC_C)
if(WITH_FPIC_C)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC")
endif(WITH_FPIC_C)
if(WIN32)
add_definitions(-DWIN32)
add_definitions(-D_WIN32)
set(NHR_OS_WINDOWS 1)
endif()
if(MINGW)
set(NHR_COMPILER_MINGW 1)
endif()
add_definitions(-DCMAKE_BUILD)
if(NHR_OPT_APPVEYOR_CI)
add_definitions(-DNHR_APPVEYOR_CI)
endif()
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
message("Looking for zlib...")
find_package(ZLIB)
if(ZLIB_FOUND)
include_directories(${ZLIB_INCLUDE_DIRS})
list(APPEND CMAKE_REQUIRED_INCLUDES ${ZLIB_INCLUDE_DIRS})
message("zlib found")
message("zlib include dirs: ${ZLIB_INCLUDE_DIRS}")
message("zlib libraries: ${ZLIB_LIBRARIES}")
else()
message("zlib not found")
endif()
# Check include files
message(CMAKE_REQUIRED_INCLUDES ": " ${CMAKE_REQUIRED_INCLUDES})
message(CMAKE_EXTRA_INCLUDE_FILES ": " ${CMAKE_EXTRA_INCLUDE_FILES})
check_include_file("sys/socket.h" NHR_HAVE_SYS_SOCKET_H)
check_include_file("sys/types.h" NHR_HAVE_SYS_TYPES_H)
check_include_file("netinet/tcp.h" NHR_HAVE_NETINET_TCP_H)
check_include_file("netdb.h" NHR_HAVE_NETDB_H)
check_include_file("fcntl.h" NHR_HAVE_FCNTL_H)
check_include_file("pthread.h" NHR_HAVE_PTHREAD_H)
check_include_file("unistd.h" NHR_HAVE_UNISTD_H)
check_include_file("zlib.h" NHR_HAVE_ZLIB_H)
# To check the size of a primitive type:
check_type_size("void*" NHR_SIZEOF_VOIDP_T)
if((NOT NHR_HAVE_PTHREAD_H) AND (NOT WIN32))
message(FATAL_ERROR "Can't build libnhr without any threading support")
endif()
if(NOT DEFINED CMAKE_INSTALL_LIBDIR)
set(CMAKE_INSTALL_LIBDIR lib)
endif()
# Now make sure that you the the build directory on your "Include" path when compiling
include_directories(${PROJECT_BINARY_DIR})
set(LIBNHR_SOURCES src/nhr_common.c
src/nhr_map.c
src/nhr_memory.c
src/nhr_request_private.c
src/nhr_request_public.c
src/nhr_response.c
src/nhr_string.c
src/nhr_thread.c)
set(NHR_HAVE_ANY_METHOD FALSE)
set(NHR_LINK_ZLIB FALSE)
if(NHR_OPT_NO_GET)
add_definitions(-DNHR_NO_GET)
else()
set(NHR_HAVE_ANY_METHOD TRUE)
list(APPEND LIBNHR_SOURCES src/nhr_request_method_get.c)
endif()
if(NHR_OPT_NO_POST)
add_definitions(-DNHR_NO_POST)
else()
set(NHR_HAVE_ANY_METHOD TRUE)
list(APPEND LIBNHR_SOURCES src/nhr_request_method_post.c)
endif()
if(NHR_OPT_NO_POST_DATA)
add_definitions(-DNHR_NO_POST_DATA)
endif()
if(NHR_HAVE_ANY_METHOD)
list(APPEND LIBNHR_SOURCES src/nhr_request_method_common.c)
endif()
if(NHR_OPT_NO_RECV_CHUNKS)
add_definitions(-DNHR_NO_RECV_CHUNKS)
endif()
if(NHR_OPT_NO_SEND_CHUNKS)
add_definitions(-DNHR_NO_SEND_CHUNKS)
endif()
if(NHR_OPT_NO_GZIP)
add_definitions(-DNHR_NO_GZIP)
elseif(NHR_HAVE_ZLIB_H)
set(NHR_LINK_ZLIB TRUE)
add_definitions(-DNHR_HAVE_ZLIB_H)
list(APPEND LIBNHR_SOURCES src/nhr_gz.c)
endif()
set(LIBNHR_HEADERS libnhr.h)
add_definitions(-DNHR_BUILD)
if(NHR_OPT_SHARED)
add_library(nhr SHARED ${LIBNHR_SOURCES} ${LIBNHR_HEADERS})
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_property(TARGET nhr PROPERTY PREFIX "lib")
set_property(TARGET nhr PROPERTY IMPORT_PREFIX "lib")
endif()
endif()
if(NHR_OPT_STATIC)
add_library(nhr_static STATIC ${LIBNHR_SOURCES} ${LIBNHR_HEADERS})
set_property(TARGET nhr_static APPEND PROPERTY COMPILE_FLAGS -DLIBNHR_STATIC)
if(MSVC)
# msvc does not append 'lib' - do it here to have consistent name
set_target_properties(nhr_static PROPERTIES PREFIX "lib")
endif()
endif()
if(NHR_HAVE_PTHREAD_H)
target_link_libraries(nhr pthread)
endif()
if(NHR_LINK_ZLIB)
target_link_libraries(nhr ${ZLIB_LIBRARIES})
endif()
if(WIN32)
target_link_libraries(nhr ws2_32)
endif()
install(TARGETS nhr
DESTINATION lib)
install(TARGETS nhr_static
DESTINATION lib)
install(FILES libnhr.h
DESTINATION include)
if(NHR_OPT_TESTS)
enable_testing()
add_subdirectory(tests)
# This must always be last!
include(CPack)
endif()