1# -*- mode: cmake; cmake-tab-width: 4; indent-tabs-mode: nil -*-
2#
3# libcouchbase
4# Copyright (C) 2013 Couchbase, Inc
5# All rights reserved.
6#
7#   Licensed under the Apache License, Version 2.0 (the "License");
8#   you may not use this file except in compliance with the License.
9#   You may obtain a copy of the License at
10#
11#       http://www.apache.org/licenses/LICENSE-2.0
12#
13#   Unless required by applicable law or agreed to in writing, software
14#   distributed under the License is distributed on an "AS IS" BASIS,
15#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16#   See the License for the specific language governing permissions and
17#   limitations under the License.
18
19# centos-7:      2.8.12
20# amazonlinux-2: 2.8.12.2
21# ubuntu-16.04:  3.5.1
22# debian-9:      3.7.2
23# amazonlinux-2: 3.13.1 (cmake3 package)
24# centos-7:      3.17.3 (cmake3 package from epel-release)
25CMAKE_MINIMUM_REQUIRED(VERSION 3.5.1)
26
27### BEGIN CONFIGURABLES ###
28# These variables can be modified as needed
29
30# Couchbase mock path to download
31SET(COUCHBASE_MOCK_VERSION 1.5.25)
32SET(COUCHBASE_MOCK_URL "https://github.com/couchbase/CouchbaseMock/releases/download/${COUCHBASE_MOCK_VERSION}/CouchbaseMock-${COUCHBASE_MOCK_VERSION}.jar")
33project(libcouchbase VERSION 3.2.4 LANGUAGES C CXX)
34
35if (NOT CMAKE_VERSION VERSION_LESS "3.13")
36    # CMP0077: option() honors normal variables
37    # https://cmake.org/cmake/help/latest/policy/CMP0077.html
38    cmake_policy(SET CMP0077 NEW)
39endif()
40
41OPTION(LCB_NO_TESTS "Disable building of tests" OFF)
42OPTION(LCB_NO_TOOLS "Disable building of additional tools" OFF)
43OPTION(LCB_NO_PLUGINS "Disable the building of IO plugins for external libs" OFF)
44SET(LCB_PLUGINS_DIR "libcouchbase" CACHE STRING "Directory for IO plugins")
45OPTION(LCB_BUILD_LIBEVENT "Build the libevent plugin" ON)
46OPTION(LCB_BUILD_LIBEV "Build the libev plugin (if available)" ON)
47OPTION(LCB_BUILD_LIBUV "Build the libuv plugin (if available)" ON)
48OPTION(LCB_MAINTAINER_MODE "Enables maintainer mode" OFF)
49OPTION(LCB_NO_SSL "Do not compile SSL support" OFF)
50OPTION(LCB_USE_ASAN "Use AddressSanitizer support (Requires Clang)" OFF)
51OPTION(LCB_USE_COVERAGE "Build with code coverage support" OFF)
52OPTION(LCB_USE_ARCHLIBDIR "Use architecture-prefixed library installation directory, if possible" OFF)
53OPTION(LCB_BUILD_EXAMPLES "Build example applications" OFF)
54OPTION(LCB_NO_MOCK "Don't run tests which depend on the mock" OFF)
55OPTION(LCB_BUILD_DTRACE "Build DTrace instrumentation, if available on platform" ON)
56OPTION(LCB_EMBED_PLUGIN_LIBEVENT "Embed the libevent plugin" OFF)
57OPTION(LCB_STATIC_LIBEVENT "Link static libevent (only applicable if EMBED_PLUGIN_LIBEVENT is ON" OFF)
58OPTION(LCB_USE_HDR_HISTOGRAM "Use HdrHistogram for statistics recording" ON)
59OPTION(LCB_INSTALL_HEADERS "Install header files" ON)
60OPTION(LCB_INSTALL_LIBRARY "Install library files" ON)
61OPTION(LCB_INSTALL_PKGCONFIG "Install pkgconfig/libcouchbase.pc" ON)
62OPTION(LCB_DUMP_PACKETS "Enable dumping network packets on TRACE log level" OFF)
63OPTION(LCB_USE_PROFILER "Build with profiler support (from gperftools)" OFF)
64OPTION(LCB_SKIP_GIT_VERSION "Skip version detection using git" OFF)
65# Read more at https://wiki.wireshark.org/TLS
66option(LCB_TLS_LOG_KEYS "Write per-session secrets to log file specified by env TLS_KEY_LOG_FILE. (Useful for Wireshark SSL/TLS dissection)" OFF)
67
68STRING(TIMESTAMP LCB_BUILD_TIMESTAMP "%Y-%m-%d %H:%M:%S" UTC)
69
70### END CONFIGURABLES ###
71IF(MSVC)
72    SET(CMAKE_DEBUG_POSTFIX "_d")
73ELSE()
74    IF(APPLE)
75        SET(CMAKE_MACOSX_RPATH ON)
76    ENDIF()
77    SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
78    SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
79    IF("${CMAKE_INSTALL_RPATH}" STREQUAL "")
80        LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
81        IF("${isSystemDir}" STREQUAL "-1")
82            SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
83        ENDIF("${isSystemDir}" STREQUAL "-1")
84    ENDIF()
85ENDIF()
86
87# If building from a configured autotools tree, bail.
88IF(EXISTS ${PROJECT_SOURCE_DIR}/src/config.h)
89    MESSAGE(FATAL_ERROR "config.h found in src/. This will break the CMake build. Remove it manually then rerun")
90ENDIF()
91
92SET(LCB_GENSRCDIR ${PROJECT_BINARY_DIR}/generated)
93INCLUDE_DIRECTORIES(${LCB_GENSRCDIR})
94SET(LCB_GENINFODIR ${PROJECT_SOURCE_DIR}/packaging/distinfo)
95
96INCLUDE(cmake/Modules/GetLibcouchbaseFlags.cmake)
97INCLUDE(cmake/Modules/FindCouchbaseLibevent.cmake)
98IF (LCB_BUILD_LIBEV)
99    INCLUDE(cmake/Modules/FindCouchbaseLibev.cmake)
100ENDIF()
101IF (LCB_BUILD_LIBUV)
102    INCLUDE(cmake/Modules/FindCouchbaseLibuv.cmake)
103ENDIF()
104INCLUDE(cmake/Modules/GetPlatformCCInfo.cmake)
105INCLUDE(cmake/Modules/GetVersionInfo.cmake)
106INCLUDE(cmake/Modules/DownloadLcbDep.cmake)
107INCLUDE(CheckIncludeFiles)
108INCLUDE(cmake/source_files.cmake)
109
110IF(LCB_USE_PROFILER)
111    INCLUDE(cmake/Modules/FindProfiler.cmake)
112ENDIF()
113IF(LCB_USE_HDR_HISTOGRAM)
114    # Allow for building libcouchbase inside a larger CMake project that
115    # already includes HdrHistogram_c
116    IF (NOT TARGET hdr_histogram_static)
117        ADD_SUBDIRECTORY(contrib/HdrHistogram_c)
118        MESSAGE(STATUS "Using embedded HdrHistogram_c")
119    ELSE ()
120        MESSAGE(STATUS "Using HdrHistogram_c from larger project (building inside Server)")
121    ENDIF ()
122
123    # Use #include files from wherever the hdr_histogram project was loaded
124    INCLUDE_DIRECTORIES(BEFORE SYSTEM "${hdr_histogram_SOURCE_DIR}/src")
125
126    # Given we are linking hdr_histogram_static into libcouchbase.so, need
127    # -fPIC set also on hdr_histogram_static.
128    SET_TARGET_PROPERTIES(hdr_histogram_static
129            PROPERTIES POSITION_INDEPENDENT_CODE TRUE)
130
131    SET(LCB_HDR_HISTOGRAM_LINK hdr_histogram_static)
132    LIST(APPEND LCB_CORE_SRC "src/hdr_timings.c")
133ELSE()
134    MESSAGE(STATUS "HdrHistogram_c is not enabled")
135    SET(LCB_HDR_HISTOGRAM_LINK "")
136    LIST(APPEND LCB_CORE_SRC "src/timings.c")
137ENDIF()
138
139IF(LIB_INSTALL_DIR)
140    SET(CMAKE_INSTALL_LIBDIR "${LIB_INSTALL_DIR}")
141ENDIF()
142IF(NOT LCB_USE_ARCHLIBDIR AND NOT CMAKE_INSTALL_LIBDIR)
143    SET(CMAKE_INSTALL_LIBDIR "lib")
144ENDIF()
145INCLUDE(GNUInstallDirs)
146
147
148SET(CPACK_PACKAGE_VERSION_MAJOR "${LCB_VERSION_MAJOR}")
149SET(CPACK_PACKAGE_VERSION_MINOR "${LCB_VERSION_MINOR}")
150SET(CPACK_PACKAGE_VERSION_PATCH "${LCB_VERSION_PATCH}")
151IF(NOT CMAKE_BUILD_TYPE)
152    SET(CPACK_INSTALL_SCRIPT
153        "${PROJECT_SOURCE_DIR}/cmake/Modules/DistScript.cmake")
154ENDIF()
155SET(lcb_package_name "libcouchbase-${LCB_VERSION}_${LCB_CC_STRING}_${LCB_ARCH_STRING}")
156SET(CPACK_PACKAGE_FILE_NAME ${lcb_package_name})
157
158IF(WIN32)
159    SET(CPACK_GENERATOR "ZIP")
160ELSE()
161    SET(CPACK_GENERATOR "TGZ")
162ENDIF()
163
164INCLUDE(CPack)
165
166CONFIGURE_FILE(
167    ${PROJECT_SOURCE_DIR}/include/libcouchbase/configuration.h.in
168    ${LCB_GENSRCDIR}/libcouchbase/configuration.h
169    @ONLY)
170
171CONFIGURE_FILE(
172    ${PROJECT_SOURCE_DIR}/cmake/defs.mk.in
173    ${PROJECT_BINARY_DIR}/defs.mk)
174
175CONFIGURE_FILE(
176    ${PROJECT_SOURCE_DIR}/packaging/dllversion.rc.in
177    ${PROJECT_BINARY_DIR}/dllversion.rc)
178
179SET(NT_REQUIRED_VERSION 0x0600)
180
181ADD_DEFINITIONS(-DLIBCOUCHBASE_INTERNAL=1)
182
183SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
184SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
185IF(WIN32)
186    SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
187ELSE()
188    SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
189ENDIF()
190
191SET(SOURCE_ROOT ${PROJECT_SOURCE_DIR})
192
193IF(WIN32)
194    ADD_DEFINITIONS(-DWINVER=${NT_REQUIRED_VERSION})
195    ADD_DEFINITIONS(-D_WIN32_WINNT=${NT_REQUIRED_VERSION})
196    SET(lcb_plat_includes "${SOURCE_ROOT}/contrib/win32-defs")
197    SET(lcb_plat_libs ws2_32.lib dnsapi.lib)
198    SET(lcb_plat_objs $<TARGET_OBJECTS:couchbase_iocp>)
199ELSE()
200    SET(lcb_plat_libs m)
201    IF(NOT CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
202        SET(lcb_plat_libs ${lcb_plat_libs} dl resolv)
203    ELSE()
204        # BSD _and_ DTrace
205        IF(LCB_BUILD_DTRACE)
206            SET(lcb_plat_libs ${lcb_plat_libs} elf)
207        ENDIF()
208    ENDIF()
209    IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
210        SET(lcb_plat_libs ${lcb_plat_libs} nsl socket)
211    ENDIF()
212    IF(LCB_EMBED_PLUGIN_LIBEVENT)
213        SET(lcb_plat_objs ${lcb_plat_objs} $<TARGET_OBJECTS:couchbase_libevent>)
214        SET(lcb_plat_libs ${lcb_plat_libs} ${LIBEVENT_LIBRARIES})
215        ADD_DEFINITIONS(-DLCB_EMBED_PLUGIN_LIBEVENT)
216    ENDIF()
217ENDIF()
218
219INCLUDE_DIRECTORIES(BEFORE ${SOURCE_ROOT}/include
220                           ${SOURCE_ROOT}/contrib
221                           ${SOURCE_ROOT}/contrib/cbsasl/include
222                           ${SOURCE_ROOT}/src
223                           ${lcb_plat_includes}
224                           ${SOURCE_ROOT})
225
226# These files are bundled in a static library.
227# They export no symbols of their own and may
228# be considered as 'static'
229
230ADD_LIBRARY(couchbase_utils OBJECT ${LCB_UTILS_SRC})
231ADD_LIBRARY(couchbase_utils-cxx OBJECT ${LCB_UTILS_CXXSRC})
232
233MACRO(LCB_UTIL tgt)
234    SET_TARGET_PROPERTIES(${tgt}
235        PROPERTIES
236        COMPILE_FLAGS "${LCB_CORE_CFLAGS}"
237        POSITION_INDEPENDENT_CODE TRUE)
238ENDMACRO()
239
240MACRO(LCB_CXXUTIL tgt)
241    SET_TARGET_PROPERTIES(${tgt}
242        PROPERTIES
243        COMPILE_FLAGS "${LCB_CORE_CXXFLAGS}"
244        POSITION_INDEPENDENT_CODE TRUE)
245ENDMACRO()
246
247ADD_LIBRARY(netbuf OBJECT ${LCB_NETBUF_SRC})
248ADD_LIBRARY(netbuf-malloc OBJECT ${LCB_NETBUF_SRC})
249ADD_LIBRARY(mcreq OBJECT ${LCB_MC_SRC})
250ADD_LIBRARY(mcreq-cxx OBJECT ${LCB_MC_CXXSRC})
251ADD_LIBRARY(rdb OBJECT ${LCB_RDB_SRC})
252ADD_LIBRARY(lcbio OBJECT ${LCB_IO_SRC})
253ADD_LIBRARY(lcbio-cxx OBJECT ${LCB_IO_CXXSRC})
254ADD_LIBRARY(lcbht OBJECT ${LCB_HT_SRC})
255ADD_LIBRARY(lcbcore OBJECT ${LCB_CORE_SRC})
256ADD_LIBRARY(lcbcore-cxx OBJECT ${LCB_CORE_CXXSRC})
257
258SET_TARGET_PROPERTIES(netbuf-malloc PROPERTIES COMPILE_DEFINITIONS NETBUF_LIBC_PROXY=1)
259LCB_UTIL(netbuf-malloc)
260LCB_UTIL(netbuf)
261LCB_UTIL(rdb)
262LCB_UTIL(lcbio)
263LCB_CXXUTIL(lcbio-cxx)
264LCB_CXXUTIL(couchbase_utils-cxx)
265LCB_UTIL(couchbase_utils)
266LCB_UTIL(mcreq)
267LCB_CXXUTIL(mcreq-cxx)
268LCB_UTIL(lcbht)
269LCB_UTIL(lcbcore)
270LCB_CXXUTIL(lcbcore-cxx)
271
272IF(LCB_NO_SSL)
273    MESSAGE(STATUS "SSL support will be disabled")
274    ADD_DEFINITIONS(-DLCB_NO_SSL=1)
275ELSE()
276    IF(NOT OPENSSL_FOUND)
277        # When building under Couchbase Server we've already detected
278        # and set the appropriate OpenSSL variables
279        IF(APPLE)
280            IF(NOT OpenSSL_DIR)
281                EXECUTE_PROCESS(COMMAND brew --prefix openssl
282                    OUTPUT_VARIABLE OPENSSL_ROOT_DIR
283                    OUTPUT_STRIP_TRAILING_WHITESPACE)
284                MESSAGE(STATUS "Found OpenSSL Prefix: ${OPENSSL_ROOT_DIR}")
285            ENDIF()
286        ENDIF()
287        FIND_PACKAGE(OpenSSL)
288    ENDIF(NOT OPENSSL_FOUND)
289
290    IF(OPENSSL_FOUND)
291        MESSAGE(STATUS "SSL Found: ${OPENSSL_VERSION} (${OPENSSL_LIBRARIES})")
292    ELSE()
293        MESSAGE(STATUS "SSL Not Found. SSL support will be disabled")
294        ADD_DEFINITIONS(-DLCB_NO_SSL=1)
295    ENDIF()
296ENDIF()
297
298ADD_SUBDIRECTORY(src/vbucket)
299ADD_SUBDIRECTORY(contrib/cbsasl)
300ADD_SUBDIRECTORY(contrib/cliopts)
301ADD_SUBDIRECTORY(src/ssl)
302ADD_SUBDIRECTORY(contrib/lcb-jsoncpp)
303IF(NOT LCB_SNAPPY_LIB)
304    ADD_SUBDIRECTORY(contrib/snappy)
305ENDIF()
306IF(NOT LCB_SNAPPY_INCLUDE_DIR)
307    INCLUDE_DIRECTORIES(contrib/snappy)
308ELSE()
309    INCLUDE_DIRECTORIES(${LCB_SNAPPY_INCLUDE_DIR})
310ENDIF()
311IF(LCB_BUILD_EXAMPLES)
312    ADD_SUBDIRECTORY(example)
313ENDIF()
314
315IF(LCB_BUILD_STATIC)
316    SET(_lcb_linkspec STATIC)
317ELSE()
318    SET(_lcb_linkspec SHARED)
319ENDIF()
320
321# CMake configuration
322IF(NOT WIN32 AND LCB_BUILD_DTRACE)
323    INCLUDE(cmake/Modules/ConfigureDtrace.cmake)
324ENDIF()
325
326FILE(GLOB LCB_JSPARSE_SRC src/jsparse/*.cc)
327ADD_LIBRARY(lcb_jsparse OBJECT ${LCB_JSPARSE_SRC})
328LCB_CXXUTIL(lcb_jsparse)
329
330SET(LCB_CORE_OBJS
331    $<TARGET_OBJECTS:couchbase_select>
332    $<TARGET_OBJECTS:couchbase_utils>
333    $<TARGET_OBJECTS:couchbase_utils-cxx>
334    $<TARGET_OBJECTS:vbucket-lcb>
335    $<TARGET_OBJECTS:mcreq>
336    $<TARGET_OBJECTS:mcreq-cxx>
337    $<TARGET_OBJECTS:netbuf>
338    $<TARGET_OBJECTS:cbsasl-lcb>
339    $<TARGET_OBJECTS:cbsasl-lcb-cxx>
340    $<TARGET_OBJECTS:lcbio>
341    $<TARGET_OBJECTS:lcbio-cxx>
342    $<TARGET_OBJECTS:rdb>
343    $<TARGET_OBJECTS:lcbht>
344    $<TARGET_OBJECTS:lcbcore>
345    $<TARGET_OBJECTS:lcbcore-cxx>
346    $<TARGET_OBJECTS:lcb_jsparse>
347    $<TARGET_OBJECTS:lcb_jsoncpp>
348    ${LCB_DTRACE_OBJECT}
349    ${lcb_plat_objs}
350    ${lcb_ssl_objs})
351
352IF(NOT LCB_SNAPPY_LIB)
353    LIST (APPEND LCB_CORE_OBJS $<TARGET_OBJECTS:lcb_snappy>)
354ENDIF()
355
356ADD_LIBRARY(couchbaseS STATIC ${LCB_CORE_OBJS})
357ADD_LIBRARY(couchbase ${_lcb_linkspec} ${LCB_CORE_OBJS} ${PROJECT_BINARY_DIR}/dllversion.rc)
358# For DTrace implementations which need to gain access to all the *.o files first
359# we need to hook the linker command to a custom perl script which will intercept
360# the object files passed to the linker, run dtrace on them, and inject the generated
361# object into the linker commandline. This is a bit fragile but we don't officially
362# support any of these platforms anyway
363IF(LCB_DTRACE_INSTRO)
364    SET(_lcb_linkhook "${PROJECT_SOURCE_DIR}/cmake/dtrace-instr-link.pl ${LCB_DTRACE_SRC}")
365    SET_TARGET_PROPERTIES(couchbase PROPERTIES RULE_LAUNCH_LINK ${_lcb_linkhook})
366    SET_TARGET_PROPERTIES(couchbaseS PROPERTIES RULE_LAUNCH_LINK ${_lcb_linkhook})
367ENDIF()
368
369# This is done to be ABI-compatible with Autotools. On OSX, autotools generates
370# a library with a Compatibility and Current versions of 3.x despite our library
371# actually being versioned at 2.x. To make things worse, autotools also actually
372# provided a _symlink_ of libcouchbase.2.dylib. CMake cannot do this manually
373# and thus we disable the SOVERSION appending when on OS X, and revert to
374# inserting the version information by hand.
375IF(NOT APPLE)
376    SET_TARGET_PROPERTIES(couchbase PROPERTIES
377        SOVERSION "${LCB_SONAME_MAJOR}" VERSION "${LCB_SONAME_FULL}")
378ELSE()
379    SET_TARGET_PROPERTIES(couchbase PROPERTIES
380        LINK_FLAGS "-compatibility_version ${LCB_SONAME_MAJOR} -current_version ${LCB_SONAME_FULL}"
381        OUTPUT_NAME couchbase.2)
382    IF(NOT LCB_BUILD_STATIC)
383        ADD_CUSTOM_COMMAND(TARGET couchbase POST_BUILD
384            COMMAND rm -f libcouchbase.dylib
385            COMMAND ln libcouchbase.2.dylib libcouchbase.dylib
386            WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
387        IF(LCB_INSTALL_LIBRARY)
388            INSTALL(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcouchbase.dylib
389                DESTINATION ${CMAKE_INSTALL_LIBDIR})
390        ENDIF()
391    ENDIF()
392ENDIF()
393
394SET_TARGET_PROPERTIES(couchbase PROPERTIES PREFIX "lib")
395SET_TARGET_PROPERTIES(couchbase PROPERTIES IMPORT_PREFIX "lib")
396SET(LCB_LINK_DEPS ${lcb_plat_libs} ${lcb_ssl_libs} ${LCB_HDR_HISTOGRAM_LINK})
397IF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
398    SET(LCB_LINK_DEPS ${LCB_LINK_DEPS} rt)
399ENDIF()
400IF(LIBPROFILER)
401    SET(LCB_LINK_DEPS ${LCB_LINK_DEPS} ${LIBPROFILER})
402ENDIF()
403IF(LCB_SNAPPY_LIB)
404    SET(LCB_LINK_DEPS ${LCB_LINK_DEPS} ${LCB_SNAPPY_LIB})
405ENDIF()
406
407TARGET_LINK_LIBRARIES(couchbase ${LCB_LINK_DEPS})
408TARGET_LINK_LIBRARIES(couchbaseS ${LCB_LINK_DEPS})
409
410ENABLE_TESTING()
411IF(NOT LCB_NO_TESTS)
412    ADD_SUBDIRECTORY(tests tests)
413ELSE()
414    ADD_TEST(NAME dummytest COMMAND echo "No Tests!")
415ENDIF(NOT LCB_NO_TESTS)
416
417IF(NOT LCB_NO_TOOLS)
418    ADD_SUBDIRECTORY(tools tools)
419ENDIF(NOT LCB_NO_TOOLS)
420
421# Always add this file, as we need the headers for this!
422ADD_SUBDIRECTORY(plugins/io/libuv)
423IF(NOT LCB_NO_PLUGINS AND LCB_BUILD_LIBUV)
424ENDIF()
425
426IF(NOT LCB_NO_PLUGINS AND NOT WIN32)
427    IF(LCB_BUILD_LIBEVENT)
428        ADD_SUBDIRECTORY(plugins/io/libevent)
429    ENDIF()
430    IF(LCB_BUILD_LIBEV)
431        ADD_SUBDIRECTORY(plugins/io/libev)
432    ENDIF()
433    IF(NOT (HAVE_LIBEV OR HAVE_LIBEVENT))
434        MESSAGE(FATAL_ERROR
435            "libev or libevent development files missing.
436            You can disable these dependencies by passing
437            -DLCB_NO_PLUGINS=1 to Cmake, or
438            --disable-plugins to the configure script")
439    ENDIF()
440ENDIF()
441
442
443IF(LCB_MAINTAINER_MODE)
444    IF(NOT (HAVE_LIBEV AND HAVE_LIBEVENT AND HAVE_LIBUV))
445        MESSAGE(FATAL_ERROR "Maintainer mode requires all plugins to be present")
446    ENDIF()
447ENDIF()
448
449ADD_SUBDIRECTORY(plugins/io/select)
450ADD_SUBDIRECTORY(plugins/io/iocp)
451IF(LCB_INSTALL_LIBRARY)
452    INSTALL(TARGETS couchbase RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
453        LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
454        ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
455ENDIF()
456
457IF(LCB_INSTALL_HEADERS)
458    INSTALL(DIRECTORY include/libcouchbase ${LCB_GENSRCDIR}/libcouchbase
459            DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
460            FILES_MATCHING PATTERN *.h PATTERN *.c)
461ENDIF()
462
463IF(NOT LCB_NO_TOOLS)
464    INSTALL(DIRECTORY doc/man/ DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 FILES_MATCHING PATTERN *.1)
465    INSTALL(DIRECTORY doc/man/ DESTINATION ${CMAKE_INSTALL_MANDIR}/man4  FILES_MATCHING PATTERN *.4)
466ENDIF()
467
468IF(LCB_INSTALL_LIBRARY)
469    IF(MSVC)
470        IF(NOT LCB_BUILD_STATIC)
471            INSTALL(FILES $<TARGET_PDB_FILE:couchbase> DESTINATION ${CMAKE_INSTALL_BINDIR} OPTIONAL)
472        ENDIF()
473        INSTALL(DIRECTORY $<TARGET_LINKER_FILE_DIR:couchbase>/ DESTINATION ${CMAKE_INSTALL_LIBDIR} OPTIONAL FILES_MATCHING PATTERN "*.exp")
474    ENDIF()
475ENDIF()
476
477SET(_lcb_tarname "libcouchbase-${LCB_VERSION}")
478SET(_lcb_manifest "${LCB_GENINFODIR}/MANIFEST")
479
480# pkg-config stuff goes with installation
481IF(NOT WIN32 AND LCB_INSTALL_PKGCONFIG)
482    CONFIGURE_FILE(packaging/libcouchbase.pc.in packaging/libcouchbase.pc @ONLY)
483    INSTALL(FILES ${PROJECT_BINARY_DIR}/packaging/libcouchbase.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
484ENDIF()
485
486
487ADD_CUSTOM_TARGET(uninstall
488    COMMAND xargs rm -vf < ${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt)
489
490ADD_CUSTOM_TARGET(file_manifest
491    COMMAND sh -c 'test -e ${_lcb_manifest} || git ls-files > ${_lcb_manifest}'
492    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
493
494
495ADD_CUSTOM_TARGET(dist
496    COMMAND rm -rf "${_lcb_tarname}"
497    COMMAND mkdir "${_lcb_tarname}"
498    COMMAND tar -cf - -C ${PROJECT_SOURCE_DIR} -T ${_lcb_manifest} | tar xf - -C "${_lcb_tarname}"
499    COMMAND cp -a "${LCB_GENINFODIR}" "${_lcb_tarname}/packaging"
500    COMMAND tar -czf "${_lcb_tarname}.tar.gz" "${_lcb_tarname}"
501    COMMAND rm -rf "${_lcb_tarname}"
502    DEPENDS file_manifest)
503
504# Generate our configuration file _after_ we've collected everything
505INCLUDE(cmake/Modules/GenerateConfigDotH.cmake)
506
507# Build any local tests/scripts
508IF (EXISTS ${SOURCE_ROOT}/tests/LOCAL)
509    ADD_SUBDIRECTORY(${SOURCE_ROOT}/tests/LOCAL)
510ENDIF()
511