forked from mongodb/mongo-c-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
274 lines (239 loc) · 9.63 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
cmake_minimum_required(VERSION 2.8)
project (libmongoc)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/build/cmake)
include(InstallRequiredSystemLibraries)
include(FindOpenSSL)
include(FindBSON REQUIRED)
set (SOURCE_DIR "${PROJECT_SOURCE_DIR}/")
set (MONGOC_MAJOR_VERSION 1)
set (MONGOC_MINOR_VERSION 0)
set (MONGOC_MICRO_VERSION 1)
set (MONGOC_API_VERSION 1.0)
set (MONGOC_VERSION 1.0.1)
set (CPACK_RESOURCE_FILE_LICENSE "${SOURCE_DIR}/COPYING")
set (CPACK_PACKAGE_VERSION_MAJOR ${MONGOC_MAJOR_VERSION})
set (CPACK_PACKAGE_VERSION_MINOR ${MONGOC_MINOR_VERSION})
include (CPack)
if (OPENSSL_FOUND)
set (MONGOC_ENABLE_SSL 1)
else()
set (MONGOC_ENABLE_SSL 0)
endif ()
set (MONGOC_ENABLE_SASL 0)
configure_file (
"${SOURCE_DIR}/src/mongoc/mongoc-config.h.in"
"${PROJECT_BINARY_DIR}/src/mongoc/mongoc-config.h"
)
configure_file (
"${SOURCE_DIR}/src/mongoc/mongoc-version.h.in"
"${PROJECT_BINARY_DIR}/src/mongoc/mongoc-version.h"
)
include_directories("${PROJECT_BINARY_DIR}/src/mongoc")
include_directories("${SOURCE_DIR}/src/mongoc")
include_directories(${BSON_INCLUDE_DIR})
set(LIBS ${LIBS} ${BSON_LIBRARIES})
if (UNIX AND NOT APPLE)
set(LIBS ${LIBS} rt)
endif()
add_definitions(-D_GNU_SOURCE)
add_definitions(-D_BSD_SOURCE)
add_definitions("-DBINARY_DIR=\"${SOURCE_DIR}/tests/binary\"")
set (SOURCES
${SOURCE_DIR}/src/mongoc/mongoc-array.c
${SOURCE_DIR}/src/mongoc/mongoc-bulk-operation.c
${SOURCE_DIR}/src/mongoc/mongoc-buffer.c
${SOURCE_DIR}/src/mongoc/mongoc-client.c
${SOURCE_DIR}/src/mongoc/mongoc-client-pool.c
${SOURCE_DIR}/src/mongoc/mongoc-cluster.c
${SOURCE_DIR}/src/mongoc/mongoc-collection.c
${SOURCE_DIR}/src/mongoc/mongoc-counters.c
${SOURCE_DIR}/src/mongoc/mongoc-cursor.c
${SOURCE_DIR}/src/mongoc/mongoc-cursor-array.c
${SOURCE_DIR}/src/mongoc/mongoc-cursor-cursorid.c
${SOURCE_DIR}/src/mongoc/mongoc-database.c
${SOURCE_DIR}/src/mongoc/mongoc-init.c
${SOURCE_DIR}/src/mongoc/mongoc-gridfs.c
${SOURCE_DIR}/src/mongoc/mongoc-gridfs-file.c
${SOURCE_DIR}/src/mongoc/mongoc-gridfs-file-page.c
${SOURCE_DIR}/src/mongoc/mongoc-gridfs-file-list.c
${SOURCE_DIR}/src/mongoc/mongoc-index.c
${SOURCE_DIR}/src/mongoc/mongoc-list.c
${SOURCE_DIR}/src/mongoc/mongoc-log.c
${SOURCE_DIR}/src/mongoc/mongoc-matcher.c
${SOURCE_DIR}/src/mongoc/mongoc-matcher-op.c
${SOURCE_DIR}/src/mongoc/mongoc-queue.c
${SOURCE_DIR}/src/mongoc/mongoc-read-prefs.c
${SOURCE_DIR}/src/mongoc/mongoc-rpc.c
${SOURCE_DIR}/src/mongoc/mongoc-socket.c
${SOURCE_DIR}/src/mongoc/mongoc-stream.c
${SOURCE_DIR}/src/mongoc/mongoc-stream-buffered.c
${SOURCE_DIR}/src/mongoc/mongoc-stream-file.c
${SOURCE_DIR}/src/mongoc/mongoc-stream-gridfs.c
${SOURCE_DIR}/src/mongoc/mongoc-stream-socket.c
${SOURCE_DIR}/src/mongoc/mongoc-uri.c
${SOURCE_DIR}/src/mongoc/mongoc-util.c
${SOURCE_DIR}/src/mongoc/mongoc-write-command.c
${SOURCE_DIR}/src/mongoc/mongoc-write-concern.c
)
set (HEADERS
${PROJECT_BINARY_DIR}/src/mongoc/mongoc-config.h
${PROJECT_BINARY_DIR}/src/mongoc/mongoc-version.h
${SOURCE_DIR}/src/mongoc/mongoc.h
${SOURCE_DIR}/src/mongoc/mongoc-bulk-operation.h
${SOURCE_DIR}/src/mongoc/mongoc-client.h
${SOURCE_DIR}/src/mongoc/mongoc-client-pool.h
${SOURCE_DIR}/src/mongoc/mongoc-collection.h
${SOURCE_DIR}/src/mongoc/mongoc-cursor.h
${SOURCE_DIR}/src/mongoc/mongoc-database.h
${SOURCE_DIR}/src/mongoc/mongoc-error.h
${SOURCE_DIR}/src/mongoc/mongoc-flags.h
${SOURCE_DIR}/src/mongoc/mongoc-gridfs.h
${SOURCE_DIR}/src/mongoc/mongoc-gridfs-file.h
${SOURCE_DIR}/src/mongoc/mongoc-gridfs-file-page.h
${SOURCE_DIR}/src/mongoc/mongoc-gridfs-file-list.h
${SOURCE_DIR}/src/mongoc/mongoc-host-list.h
${SOURCE_DIR}/src/mongoc/mongoc-init.h
${SOURCE_DIR}/src/mongoc/mongoc-index.h
${SOURCE_DIR}/src/mongoc/mongoc-iovec.h
${SOURCE_DIR}/src/mongoc/mongoc-log.h
${SOURCE_DIR}/src/mongoc/mongoc-matcher.h
${SOURCE_DIR}/src/mongoc/mongoc-opcode.h
${SOURCE_DIR}/src/mongoc/mongoc-read-prefs.h
${SOURCE_DIR}/src/mongoc/mongoc-socket.h
${SOURCE_DIR}/src/mongoc/mongoc-stream.h
${SOURCE_DIR}/src/mongoc/mongoc-stream-buffered.h
${SOURCE_DIR}/src/mongoc/mongoc-stream-file.h
${SOURCE_DIR}/src/mongoc/mongoc-stream-gridfs.h
${SOURCE_DIR}/src/mongoc/mongoc-stream-socket.h
${SOURCE_DIR}/src/mongoc/mongoc-uri.h
${SOURCE_DIR}/src/mongoc/mongoc-write-concern.h
)
if (OPENSSL_FOUND)
set (HEADERS ${HEADERS}
${SOURCE_DIR}/src/mongoc/mongoc-stream-tls.h
${SOURCE_DIR}/src/mongoc/mongoc-ssl.h)
set (SOURCES ${SOURCES}
${SOURCE_DIR}/src/mongoc/mongoc-stream-tls.c
${SOURCE_DIR}/src/mongoc/mongoc-ssl.c
)
set(LIBS ${LIBS} ${OPENSSL_LIBRARIES})
include_directories(${OPENSSL_INCLUDE_DIR})
endif()
if (MSVC)
if (OPENSSL_FOUND)
set(MONGOC_SHARED_SOURCES ${SOURCES} ${PROJECT_SOURCE_DIR}/build/cmake/libmongoc-ssl.def)
else ()
set(MONGOC_SHARED_SOURCES ${SOURCES} ${PROJECT_SOURCE_DIR}/build/cmake/libmongoc.def)
endif()
else()
set(MONGOC_SHARED_SOURCES ${SOURCES})
endif()
add_library(mongoc_shared SHARED ${MONGOC_SHARED_SOURCES} ${HEADERS})
add_library(mongoc_static STATIC ${SOURCES} ${HEADERS})
target_link_libraries(mongoc_shared ${LIBS})
target_link_libraries(mongoc_static ${LIBS})
set_target_properties(mongoc_shared PROPERTIES COMPILE_DEFINITIONS "MONGOC_COMPILATION")
set_target_properties(mongoc_static PROPERTIES COMPILE_DEFINITIONS "MONGOC_COMPILATION")
set_target_properties(mongoc_shared PROPERTIES VERSION ${MONGOC_VERSION} SOVERSION ${MONGOC_MAJOR_VERSION})
set_target_properties(mongoc_static PROPERTIES VERSION ${MONGOC_VERSION} SOVERSION ${MONGOC_MAJOR_VERSION})
set_target_properties(mongoc_shared PROPERTIES OUTPUT_NAME "mongoc-${MONGOC_API_VERSION}" PREFIX "lib")
set_target_properties(mongoc_static PROPERTIES OUTPUT_NAME "mongoc-static-${MONGOC_API_VERSION}")
enable_testing()
function(mongoc_add_test test use_shared)
add_executable(${test} ${ARGN})
if (${use_shared})
target_link_libraries(${test} mongoc_shared)
else()
set_target_properties(${test} PROPERTIES COMPILE_DEFINITIONS "MONGOC_COMPILATION")
target_link_libraries(${test} mongoc_static)
endif()
if(WIN32)
target_link_libraries(${test} shlwapi)
endif()
endfunction()
function(mongoc_add_example example use_shared)
add_executable(${example} ${ARGN})
if (${use_shared})
target_link_libraries(${example} mongoc_shared)
else()
set_target_properties(${example} PROPERTIES COMPILE_DEFINITIONS "MONGOC_COMPILATION")
target_link_libraries(${example} mongoc_static)
endif()
if(WIN32)
target_link_libraries(${example} shlwapi)
endif()
set (EXAMPLES ${EXAMPLES} ${example})
endfunction()
set(test-libmongoc-sources
${SOURCE_DIR}/tests/ha-test.c
${SOURCE_DIR}/tests/test-libmongoc.c
${SOURCE_DIR}/tests/test-mongoc-array.c
${SOURCE_DIR}/tests/test-mongoc-buffer.c
${SOURCE_DIR}/tests/test-mongoc-client.c
${SOURCE_DIR}/tests/mock-server.c
${SOURCE_DIR}/tests/test-bulk.c
${SOURCE_DIR}/tests/test-mongoc-client-pool.c
${SOURCE_DIR}/tests/test-mongoc-collection.c
${SOURCE_DIR}/tests/test-mongoc-cursor.c
${SOURCE_DIR}/tests/test-mongoc-database.c
${SOURCE_DIR}/tests/test-mongoc-gridfs.c
${SOURCE_DIR}/tests/test-mongoc-gridfs-file-page.c
${SOURCE_DIR}/tests/test-mongoc-list.c
${SOURCE_DIR}/tests/test-mongoc-matcher.c
${SOURCE_DIR}/tests/test-mongoc-queue.c
${SOURCE_DIR}/tests/test-mongoc-read-prefs.c
${SOURCE_DIR}/tests/test-mongoc-rpc.c
${SOURCE_DIR}/tests/test-mongoc-stream.c
${SOURCE_DIR}/tests/test-mongoc-uri.c
${SOURCE_DIR}/tests/test-mongoc-write-concern.c
${SOURCE_DIR}/tests/test-write-commands.c
${SOURCE_DIR}/tests/TestSuite.c
)
if (OPENSSL_FOUND)
set(test-libmongoc-sources ${test-libmongoc-sources}
${SOURCE_DIR}/tests/test-x509.c
${SOURCE_DIR}/tests/ssl-test.c
${SOURCE_DIR}/tests/test-mongoc-stream-tls.c)
mongoc_add_test(test-replica-set-ssl FALSE
${SOURCE_DIR}/tests/test-replica-set-ssl.c
${SOURCE_DIR}/tests/ha-test.c
${SOURCE_DIR}/tests/mongoc-tests.c
)
endif()
mongoc_add_test(test-load FALSE
${SOURCE_DIR}/tests/test-load.c
${SOURCE_DIR}/tests/mongoc-tests.c)
mongoc_add_test(test-secondary FALSE
${SOURCE_DIR}/tests/test-secondary.c
${SOURCE_DIR}/tests/mongoc-tests.c)
mongoc_add_test(test-replica-set FALSE
${SOURCE_DIR}/tests/test-replica-set.c
${SOURCE_DIR}/tests/mongoc-tests.c
${SOURCE_DIR}/tests/ha-test.c)
mongoc_add_test(test-sharded-cluster FALSE
${SOURCE_DIR}/tests/test-sharded-cluster.c
${SOURCE_DIR}/tests/mongoc-tests.c
${SOURCE_DIR}/tests/ha-test.c)
mongoc_add_test(test-libmongoc FALSE ${test-libmongoc-sources})
add_test(NAME test-libmongoc COMMAND test-libmongoc -f -p)
mongoc_add_example(example-gridfs TRUE ${SOURCE_DIR}/examples/example-gridfs.c)
mongoc_add_example(example-client TRUE ${SOURCE_DIR}/examples/example-client.c)
mongoc_add_example(mongoc-dump TRUE ${SOURCE_DIR}/examples/mongoc-dump.c)
mongoc_add_example(mongoc-ping TRUE ${SOURCE_DIR}/examples/mongoc-ping.c)
mongoc_add_example(mongoc-rpc-validate FALSE ${SOURCE_DIR}/examples/mongoc-rpc-validate.c)
mongoc_add_example(mongoc-tail TRUE ${SOURCE_DIR}/examples/mongoc-tail.c)
file(COPY ${SOURCE_DIR}/tests/binary DESTINATION ${PROJECT_BINARY_DIR}/tests)
file(COPY ${SOURCE_DIR}/tests/certificates DESTINATION ${PROJECT_BINARY_DIR}/tests)
#if (OPENSSL_FOUND)
# file(COPY ${SOURCE_DIR}/tests/trust_dir DESTINATION ${PROJECT_BINARY_DIR}/tests)
#endif()
install(
TARGETS mongoc_shared mongoc_static ${EXAMPLES}
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)
install(
FILES ${HEADERS}
DESTINATION "include/libmongoc-${MONGOC_API_VERSION}"
)