1fea58e03SSergey Avseyev# -*- mode: cmake; cmake-tab-width: 4; indent-tabs-mode: nil -*-
2fea58e03SSergey Avseyev#
323b04a19STrond Norbye# libcouchbase
423b04a19STrond Norbye# Copyright (C) 2013 Couchbase, Inc
523b04a19STrond Norbye# All rights reserved.
623b04a19STrond Norbye#
723b04a19STrond Norbye#   Licensed under the Apache License, Version 2.0 (the "License");
823b04a19STrond Norbye#   you may not use this file except in compliance with the License.
923b04a19STrond Norbye#   You may obtain a copy of the License at
1023b04a19STrond Norbye#
1123b04a19STrond Norbye#       http://www.apache.org/licenses/LICENSE-2.0
1223b04a19STrond Norbye#
1323b04a19STrond Norbye#   Unless required by applicable law or agreed to in writing, software
1423b04a19STrond Norbye#   distributed under the License is distributed on an "AS IS" BASIS,
1523b04a19STrond Norbye#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1623b04a19STrond Norbye#   See the License for the specific language governing permissions and
1723b04a19STrond Norbye#   limitations under the License.
1823b04a19STrond Norbye
19b916b7d4SSergey AvseyevCMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
2023b04a19STrond Norbye
2145f09580SMark Nunberg### BEGIN CONFIGURABLES ###
2245f09580SMark Nunberg# These variables can be modified as needed
2345f09580SMark Nunberg
2445f09580SMark Nunberg# Couchbase mock path to download
257306abbdSSergey AvseyevSET(COUCHBASE_MOCK_VERSION 1.5.25)
2622fd6348SSergey AvseyevSET(COUCHBASE_MOCK_URL "https://github.com/couchbase/CouchbaseMock/releases/download/${COUCHBASE_MOCK_VERSION}/CouchbaseMock-${COUCHBASE_MOCK_VERSION}.jar")
272298c115SMark Nunbergproject(libcouchbase)
28e8c42547SMark Nunberg
2973c2d27cSSergey Avseyevif (NOT CMAKE_VERSION VERSION_LESS "3.13")
3073c2d27cSSergey Avseyev    # CMP0077: option() honors normal variables
3173c2d27cSSergey Avseyev    # https://cmake.org/cmake/help/latest/policy/CMP0077.html
3273c2d27cSSergey Avseyev    cmake_policy(SET CMP0077 NEW)
3373c2d27cSSergey Avseyevendif()
3473c2d27cSSergey Avseyev
3545f09580SMark NunbergOPTION(LCB_NO_TESTS "Disable building of tests" OFF)
3645f09580SMark NunbergOPTION(LCB_NO_TOOLS "Disable building of additional tools" OFF)
37e1ad8c50SMark NunbergOPTION(LCB_NO_PLUGINS "Disable the building of IO plugins for external libs" OFF)
38ee28858eSMark NunbergOPTION(LCB_BUILD_LIBEVENT "Build the libevent plugin" ON)
39ee28858eSMark NunbergOPTION(LCB_BUILD_LIBEV "Build the libev plugin (if available)" ON)
40ee28858eSMark NunbergOPTION(LCB_BUILD_LIBUV "Build the libuv plugin (if available)" ON)
41e1ad8c50SMark NunbergOPTION(LCB_MAINTAINER_MODE "Enables maintainer mode" OFF)
42378e2fa9SMark NunbergOPTION(LCB_NO_SSL "Do not compile SSL support" OFF)
433b68ede6SMark NunbergOPTION(LCB_USE_ASAN "Use AddressSanitizer support (Requires Clang)" OFF)
44ad23b248SMark NunbergOPTION(LCB_USE_COVERAGE "Build with code coverage support" OFF)
4500236339SMark NunbergOPTION(LCB_USE_ARCHLIBDIR "Use architecture-prefixed library installation directory, if possible" OFF)
46cecab16aSMark NunbergOPTION(LCB_BUILD_EXAMPLES "Build example applications" OFF)
4775532fc0SMark NunbergOPTION(LCB_NO_MOCK "Don't run tests which depend on the mock" OFF)
4811e5515bSMark NunbergOPTION(LCB_BUILD_DTRACE "Build DTrace instrumentation, if available on platform" ON)
49fb8e27b9SMark NunbergOPTION(LCB_EMBED_PLUGIN_LIBEVENT "Embed the libevent plugin" OFF)
50fb8e27b9SMark NunbergOPTION(LCB_STATIC_LIBEVENT "Link static libevent (only applicable if EMBED_PLUGIN_LIBEVENT is ON" OFF)
512cec3ee9SDave RigbyOPTION(LCB_USE_HDR_HISTOGRAM "Use HdrHistogram for statistics recording" OFF)
5242240629STrond NorbyeOPTION(LCB_INSTALL_HEADERS "Install header files" ON)
5342240629STrond NorbyeOPTION(LCB_INSTALL_PKGCONFIG "Install pkgconfig/libcouchbase.pc" ON)
549249c3cfSSergey AvseyevOPTION(LCB_DUMP_PACKETS "Enable dumping network packets on TRACE log level" OFF)
55493aa4dbSSergey AvseyevOPTION(LCB_USE_PROFILER "Build with profiler support (from gperftools)" OFF)
5632409ce1SSergey AvseyevOPTION(LCB_SKIP_GIT_VERSION "Skip version detection using git" OFF)
5745f09580SMark Nunberg
58a6e91ceaSSergey AvseyevSTRING(TIMESTAMP LCB_BUILD_TIMESTAMP "%Y-%m-%d %H:%M:%S" UTC)
59a6e91ceaSSergey Avseyev
6045f09580SMark Nunberg### END CONFIGURABLES ###
61202fcd2aSMark NunbergIF(MSVC)
62202fcd2aSMark Nunberg    SET(CMAKE_DEBUG_POSTFIX "_d")
630cf47471SMark NunbergELSE()
640cf47471SMark Nunberg    IF(APPLE)
650cf47471SMark Nunberg        SET(CMAKE_MACOSX_RPATH ON)
660cf47471SMark Nunberg    ENDIF()
670cf47471SMark Nunberg    SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
680cf47471SMark Nunberg    SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
690cf47471SMark Nunberg    LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
700cf47471SMark Nunberg    IF("${isSystemDir}" STREQUAL "-1")
710cf47471SMark Nunberg        SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
720cf47471SMark Nunberg    ENDIF("${isSystemDir}" STREQUAL "-1")
73202fcd2aSMark NunbergENDIF()
74202fcd2aSMark Nunberg
75f9f090c1SMark Nunberg# If building from a configured autotools tree, bail.
762a07f70bSMark NunbergIF(EXISTS ${PROJECT_SOURCE_DIR}/src/config.h)
77f9f090c1SMark Nunberg    MESSAGE(FATAL_ERROR "config.h found in src/. This will break the CMake build. Remove it manually then rerun")
78f9f090c1SMark NunbergENDIF()
79f9f090c1SMark Nunberg
802a07f70bSMark NunbergSET(LCB_GENSRCDIR ${PROJECT_BINARY_DIR}/generated)
81e70ee32fSMark NunbergINCLUDE_DIRECTORIES(${LCB_GENSRCDIR})
82c6b6dbceSMark NunbergSET(LCB_GENINFODIR ${PROJECT_SOURCE_DIR}/packaging/distinfo)
83e70ee32fSMark Nunberg
84e1ad8c50SMark NunbergINCLUDE(cmake/Modules/GetLibcouchbaseFlags.cmake)
85e1ad8c50SMark NunbergINCLUDE(cmake/Modules/FindCouchbaseLibevent.cmake)
8609a56192SSergey AvseyevIF (LCB_BUILD_LIBEV)
8709a56192SSergey Avseyev    INCLUDE(cmake/Modules/FindCouchbaseLibev.cmake)
8809a56192SSergey AvseyevENDIF()
8909a56192SSergey AvseyevIF (LCB_BUILD_LIBUV)
9009a56192SSergey Avseyev    INCLUDE(cmake/Modules/FindCouchbaseLibuv.cmake)
9109a56192SSergey AvseyevENDIF()
92e1ad8c50SMark NunbergINCLUDE(cmake/Modules/GetPlatformCCInfo.cmake)
93e1ad8c50SMark NunbergINCLUDE(cmake/Modules/GetVersionInfo.cmake)
9468ff03b9SSergey AvseyevIF (MSVC)
9568ff03b9SSergey Avseyev    INCLUDE(cmake/Modules/CopyPDB.cmake)
9668ff03b9SSergey AvseyevENDIF ()
9753264f9eSMark NunbergINCLUDE(cmake/Modules/DownloadLcbDep.cmake)
98e1ad8c50SMark NunbergINCLUDE(CheckIncludeFiles)
99dbdb5953SMark NunbergINCLUDE(cmake/source_files.cmake)
100e1ad8c50SMark Nunberg
101493aa4dbSSergey AvseyevIF(LCB_USE_PROFILER)
102493aa4dbSSergey Avseyev    INCLUDE(cmake/Modules/FindProfiler.cmake)
103493aa4dbSSergey AvseyevENDIF()
1042cec3ee9SDave RigbyIF(LCB_USE_HDR_HISTOGRAM)
1052cec3ee9SDave Rigby    INCLUDE(cmake/Modules/FindCouchbaseHdrHistogram.cmake)
1062cec3ee9SDave RigbyENDIF()
1072cec3ee9SDave RigbyIF(HDR_HISTOGRAM_FOUND)
1082cec3ee9SDave Rigby    INCLUDE_DIRECTORIES(${HDR_HISTOGRAM_INCLUDES})
1092cec3ee9SDave Rigby    SET(LCB_HDR_HISTOGRAM_LINK "${HDR_HISTOGRAM_LIBRARIES}")
1102cec3ee9SDave Rigby    LIST(APPEND LCB_CORE_SRC "src/hdr_timings.c")
1112cec3ee9SDave RigbyELSE()
1122cec3ee9SDave Rigby    SET(LCB_HDR_HISTOGRAM_LINK "")
1132cec3ee9SDave Rigby    LIST(APPEND LCB_CORE_SRC "src/timings.c")
1142cec3ee9SDave RigbyENDIF()
1152cec3ee9SDave Rigby
116c5fcad2cSMark NunbergIF(LIB_INSTALL_DIR)
117c5fcad2cSMark Nunberg    SET(CMAKE_INSTALL_LIBDIR "${LIB_INSTALL_DIR}")
118c5fcad2cSMark NunbergENDIF()
11900236339SMark NunbergIF(NOT LCB_USE_ARCHLIBDIR AND NOT CMAKE_INSTALL_LIBDIR)
12000236339SMark Nunberg    SET(CMAKE_INSTALL_LIBDIR "lib")
12100236339SMark NunbergENDIF()
12200236339SMark NunbergINCLUDE(GNUInstallDirs)
12300236339SMark Nunberg
124378e2fa9SMark Nunberg
125e1ad8c50SMark NunbergSET(CPACK_PACKAGE_VERSION_MAJOR "${LCB_VERSION_MAJOR}")
126e1ad8c50SMark NunbergSET(CPACK_PACKAGE_VERSION_MINOR "${LCB_VERSION_MINOR}")
127e1ad8c50SMark NunbergSET(CPACK_PACKAGE_VERSION_PATCH "${LCB_VERSION_PATCH}")
1282811ef1eSMark NunbergIF(NOT CMAKE_BUILD_TYPE)
1292811ef1eSMark Nunberg    SET(CPACK_INSTALL_SCRIPT
1302a07f70bSMark Nunberg        "${PROJECT_SOURCE_DIR}/cmake/Modules/DistScript.cmake")
1312811ef1eSMark NunbergENDIF()
13257c4fcefSSergey AvseyevSET(lcb_package_name "libcouchbase-${LCB_VERSION}_${LCB_CC_STRING}_${LCB_ARCH_STRING}")
1335d255ca1SMark NunbergSET(CPACK_PACKAGE_FILE_NAME ${lcb_package_name})
1345d255ca1SMark Nunberg
1352811ef1eSMark NunbergIF(WIN32)
1362811ef1eSMark Nunberg    SET(CPACK_GENERATOR "ZIP")
1372811ef1eSMark NunbergELSE()
1382811ef1eSMark Nunberg    SET(CPACK_GENERATOR "TGZ")
1392811ef1eSMark NunbergENDIF()
140e1ad8c50SMark Nunberg
141e1ad8c50SMark NunbergINCLUDE(CPack)
142e1ad8c50SMark Nunberg
143e1ad8c50SMark NunbergCONFIGURE_FILE(
1442a07f70bSMark Nunberg    ${PROJECT_SOURCE_DIR}/include/libcouchbase/configuration.h.in
145e70ee32fSMark Nunberg    ${LCB_GENSRCDIR}/libcouchbase/configuration.h
146e1ad8c50SMark Nunberg    @ONLY)
147e70ee32fSMark Nunberg
14800236339SMark NunbergCONFIGURE_FILE(
1492a07f70bSMark Nunberg    ${PROJECT_SOURCE_DIR}/cmake/defs.mk.in
1502a07f70bSMark Nunberg    ${PROJECT_BINARY_DIR}/defs.mk)
15100236339SMark Nunberg
152e1ad8c50SMark NunbergCONFIGURE_FILE(
1537100e5bdSMark Nunberg    ${PROJECT_SOURCE_DIR}/packaging/dllversion.rc.in
1542a07f70bSMark Nunberg    ${PROJECT_BINARY_DIR}/dllversion.rc)
15545f09580SMark Nunberg
156d5195d38SMark NunbergSET(NT_REQUIRED_VERSION 0x0600)
1572298c115SMark Nunberg
158e1ad8c50SMark NunbergADD_DEFINITIONS(-DLIBCOUCHBASE_INTERNAL=1)
15945f09580SMark Nunberg
160e1ad8c50SMark NunbergSET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
161e1ad8c50SMark NunbergSET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
162e1ad8c50SMark NunbergIF(WIN32)
163e1ad8c50SMark Nunberg    SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)
16445f09580SMark NunbergELSE()
165e1ad8c50SMark Nunberg    SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/lib)
16645f09580SMark NunbergENDIF()
16745f09580SMark Nunberg
1682a07f70bSMark NunbergSET(SOURCE_ROOT ${PROJECT_SOURCE_DIR})
1693ad56078SMark Nunberg
1703ad56078SMark NunbergIF(WIN32)
171e1ad8c50SMark Nunberg    ADD_DEFINITIONS(-DWINVER=${NT_REQUIRED_VERSION})
172d5195d38SMark Nunberg    ADD_DEFINITIONS(-D_WIN32_WINNT=${NT_REQUIRED_VERSION})
1737100e5bdSMark Nunberg    SET(lcb_plat_includes "${SOURCE_ROOT}/contrib/win32-defs")
1740fb123d8SMark Nunberg    SET(lcb_plat_libs ws2_32.lib dnsapi.lib)
1759e0bb92fSMark Nunberg    SET(lcb_plat_objs $<TARGET_OBJECTS:couchbase_iocp>)
1763ad56078SMark NunbergELSE()
1777dc493a4SSergey Avseyev    SET(lcb_plat_libs m)
178d7a144f8SMark Nunberg    IF(NOT CMAKE_SYSTEM_NAME STREQUAL "FreeBSD")
1797dc493a4SSergey Avseyev        SET(lcb_plat_libs ${lcb_plat_libs} dl resolv)
180d7a144f8SMark Nunberg    ELSE()
181d7a144f8SMark Nunberg        # BSD _and_ DTrace
182d7a144f8SMark Nunberg        IF(LCB_BUILD_DTRACE)
183d7a144f8SMark Nunberg            SET(lcb_plat_libs ${lcb_plat_libs} elf)
184d7a144f8SMark Nunberg        ENDIF()
185d7a144f8SMark Nunberg    ENDIF()
18611e5515bSMark Nunberg    IF(CMAKE_SYSTEM_NAME STREQUAL "SunOS")
18711e5515bSMark Nunberg        SET(lcb_plat_libs ${lcb_plat_libs} nsl socket)
18811e5515bSMark Nunberg    ENDIF()
189fb8e27b9SMark Nunberg    IF(LCB_EMBED_PLUGIN_LIBEVENT)
190fb8e27b9SMark Nunberg        SET(lcb_plat_objs ${lcb_plat_objs} $<TARGET_OBJECTS:couchbase_libevent>)
191fb8e27b9SMark Nunberg        SET(lcb_plat_libs ${lcb_plat_libs} ${LIBEVENT_LIBRARIES})
192fb8e27b9SMark Nunberg        ADD_DEFINITIONS(-DLCB_EMBED_PLUGIN_LIBEVENT)
193fb8e27b9SMark Nunberg    ENDIF()
1943ad56078SMark NunbergENDIF()
1953ad56078SMark Nunberg
19623b04a19STrond NorbyeINCLUDE_DIRECTORIES(BEFORE ${SOURCE_ROOT}/include
19723b04a19STrond Norbye                           ${SOURCE_ROOT}/contrib
19862ac21b9SSergey Avseyev                           ${SOURCE_ROOT}/contrib/cbsasl/include
19923b04a19STrond Norbye                           ${SOURCE_ROOT}/src
2003ad56078SMark Nunberg                           ${lcb_plat_includes}
20123b04a19STrond Norbye                           ${SOURCE_ROOT})
20223b04a19STrond Norbye
203e8c42547SMark Nunberg# These files are bundled in a static library.
204e8c42547SMark Nunberg# They export no symbols of their own and may
205e8c42547SMark Nunberg# be considered as 'static'
206dbdb5953SMark Nunberg
207dbdb5953SMark NunbergADD_LIBRARY(couchbase_utils OBJECT ${LCB_UTILS_SRC})
208e1ad8c50SMark Nunberg
209378e2fa9SMark NunbergMACRO(LCB_UTIL tgt)
210378e2fa9SMark Nunberg    SET_TARGET_PROPERTIES(${tgt}
211378e2fa9SMark Nunberg        PROPERTIES
212378e2fa9SMark Nunberg        COMPILE_FLAGS "${LCB_CORE_CFLAGS}"
213378e2fa9SMark Nunberg        POSITION_INDEPENDENT_CODE TRUE)
214378e2fa9SMark NunbergENDMACRO()
215378e2fa9SMark Nunberg
216320142efSMark NunbergMACRO(LCB_CXXUTIL tgt)
217320142efSMark Nunberg    SET_TARGET_PROPERTIES(${tgt}
218320142efSMark Nunberg        PROPERTIES
219320142efSMark Nunberg        COMPILE_FLAGS "${LCB_CORE_CXXFLAGS}"
220320142efSMark Nunberg        POSITION_INDEPENDENT_CODE TRUE)
221320142efSMark NunbergENDMACRO()
222320142efSMark Nunberg
223dbdb5953SMark NunbergADD_LIBRARY(netbuf OBJECT ${LCB_NETBUF_SRC})
224dbdb5953SMark NunbergADD_LIBRARY(netbuf-malloc OBJECT ${LCB_NETBUF_SRC})
225dbdb5953SMark NunbergADD_LIBRARY(mcreq OBJECT ${LCB_MC_SRC})
2267273dbd9SSergey AvseyevADD_LIBRARY(mcreq-cxx OBJECT ${LCB_MC_CXXSRC})
227dbdb5953SMark NunbergADD_LIBRARY(rdb OBJECT ${LCB_RDB_SRC})
228dbdb5953SMark NunbergADD_LIBRARY(lcbio OBJECT ${LCB_IO_SRC})
22911e9a2e3SMark NunbergADD_LIBRARY(lcbio-cxx OBJECT ${LCB_IO_CXXSRC})
230dbdb5953SMark NunbergADD_LIBRARY(lcbht OBJECT ${LCB_HT_SRC})
2315e994557SMark NunbergADD_LIBRARY(lcbcore OBJECT ${LCB_CORE_SRC})
2328a2dca0cSMark NunbergADD_LIBRARY(lcbcore-cxx OBJECT ${LCB_CORE_CXXSRC})
233378e2fa9SMark Nunberg
234378e2fa9SMark NunbergSET_TARGET_PROPERTIES(netbuf-malloc PROPERTIES COMPILE_DEFINITIONS NETBUF_LIBC_PROXY=1)
235378e2fa9SMark NunbergLCB_UTIL(netbuf-malloc)
236378e2fa9SMark NunbergLCB_UTIL(netbuf)
237378e2fa9SMark NunbergLCB_UTIL(rdb)
238378e2fa9SMark NunbergLCB_UTIL(lcbio)
23911e9a2e3SMark NunbergLCB_CXXUTIL(lcbio-cxx)
240378e2fa9SMark NunbergLCB_UTIL(couchbase_utils)
241378e2fa9SMark NunbergLCB_UTIL(mcreq)
2427273dbd9SSergey AvseyevLCB_CXXUTIL(mcreq-cxx)
243378e2fa9SMark NunbergLCB_UTIL(lcbht)
2445e994557SMark NunbergLCB_UTIL(lcbcore)
2458a2dca0cSMark NunbergLCB_CXXUTIL(lcbcore-cxx)
246378e2fa9SMark Nunberg
24740ff8088SGuillaume Molleda / Amadeus IT GroupIF(LCB_NO_SSL)
24840ff8088SGuillaume Molleda / Amadeus IT Group    MESSAGE(STATUS "SSL support will be disabled")
24940ff8088SGuillaume Molleda / Amadeus IT Group    ADD_DEFINITIONS(-DLCB_NO_SSL=1)
25040ff8088SGuillaume Molleda / Amadeus IT GroupELSE()
251349b7f2dSTrond Norbye    IF(NOT OPENSSL_FOUND)
252349b7f2dSTrond Norbye        # When building under Couchbase Server we've already detected
253349b7f2dSTrond Norbye        # and set the appropriate OpenSSL variables
254349b7f2dSTrond Norbye        IF(APPLE)
255349b7f2dSTrond Norbye            IF(NOT OpenSSL_DIR)
256349b7f2dSTrond Norbye                EXECUTE_PROCESS(COMMAND brew --prefix openssl
257349b7f2dSTrond Norbye                    OUTPUT_VARIABLE OPENSSL_ROOT_DIR
258349b7f2dSTrond Norbye                    OUTPUT_STRIP_TRAILING_WHITESPACE)
259349b7f2dSTrond Norbye                MESSAGE(STATUS "Found OpenSSL Prefix: ${OPENSSL_ROOT_DIR}")
260349b7f2dSTrond Norbye            ENDIF()
26140ff8088SGuillaume Molleda / Amadeus IT Group        ENDIF()
262349b7f2dSTrond Norbye        FIND_PACKAGE(OpenSSL)
263349b7f2dSTrond Norbye    ENDIF(NOT OPENSSL_FOUND)
264349b7f2dSTrond Norbye
26540ff8088SGuillaume Molleda / Amadeus IT Group    IF(OPENSSL_FOUND)
266d74167d8SSergey Avseyev        MESSAGE(STATUS "SSL Found: ${OPENSSL_VERSION} (${OPENSSL_LIBRARIES})")
26740ff8088SGuillaume Molleda / Amadeus IT Group    ELSE()
2685bf25415SSergey Avseyev        MESSAGE(STATUS "SSL Not Found. SSL support will be disabled")
2695bf25415SSergey Avseyev        ADD_DEFINITIONS(-DLCB_NO_SSL=1)
27040ff8088SGuillaume Molleda / Amadeus IT Group    ENDIF()
27140ff8088SGuillaume Molleda / Amadeus IT GroupENDIF()
27240ff8088SGuillaume Molleda / Amadeus IT Group
273378e2fa9SMark NunbergADD_SUBDIRECTORY(src/vbucket)
274e1ad8c50SMark NunbergADD_SUBDIRECTORY(contrib/cbsasl)
275d365fc95SMark NunbergADD_SUBDIRECTORY(contrib/cliopts)
276378e2fa9SMark NunbergADD_SUBDIRECTORY(src/ssl)
277833bc83aSMark NunbergADD_SUBDIRECTORY(contrib/lcb-jsoncpp)
27886287387SSergey AvseyevADD_SUBDIRECTORY(contrib/snappy)
279cecab16aSMark NunbergIF(LCB_BUILD_EXAMPLES)
280cecab16aSMark Nunberg    ADD_SUBDIRECTORY(example)
281cecab16aSMark NunbergENDIF()
282378e2fa9SMark Nunberg
283f1e0c2dbSMark NunbergIF(LCB_BUILD_STATIC)
284f1e0c2dbSMark Nunberg    SET(_lcb_linkspec STATIC)
285f1e0c2dbSMark NunbergELSE()
286f1e0c2dbSMark Nunberg    SET(_lcb_linkspec SHARED)
287f1e0c2dbSMark NunbergENDIF()
288378e2fa9SMark Nunberg
28911e5515bSMark Nunberg# CMake configuration
29011e5515bSMark NunbergIF(NOT WIN32 AND LCB_BUILD_DTRACE)
291b3f8b193SMark Nunberg    INCLUDE(cmake/Modules/ConfigureDtrace.cmake)
292b3f8b193SMark NunbergENDIF()
29311e5515bSMark Nunberg
2941d0e36ebSMark NunbergFILE(GLOB LCB_JSPARSE_SRC src/jsparse/*.cc)
29507541ddcSMark NunbergADD_LIBRARY(lcb_jsparse OBJECT ${LCB_JSPARSE_SRC})
2961d0e36ebSMark NunbergLCB_CXXUTIL(lcb_jsparse)
29707541ddcSMark Nunberg
29886287387SSergey AvseyevINCLUDE_DIRECTORIES(contrib/snappy)
29986287387SSergey Avseyev
300dbdb5953SMark NunbergSET(LCB_CORE_OBJS
301dbdb5953SMark Nunberg    $<TARGET_OBJECTS:couchbase_select>
302dbdb5953SMark Nunberg    $<TARGET_OBJECTS:couchbase_utils>
303584b8338SChris Hillery    $<TARGET_OBJECTS:vbucket-lcb>
304dbdb5953SMark Nunberg    $<TARGET_OBJECTS:mcreq>
3057273dbd9SSergey Avseyev    $<TARGET_OBJECTS:mcreq-cxx>
306dbdb5953SMark Nunberg    $<TARGET_OBJECTS:netbuf>
307584b8338SChris Hillery    $<TARGET_OBJECTS:cbsasl-lcb>
308dbdb5953SMark Nunberg    $<TARGET_OBJECTS:lcbio>
30911e9a2e3SMark Nunberg    $<TARGET_OBJECTS:lcbio-cxx>
310dbdb5953SMark Nunberg    $<TARGET_OBJECTS:rdb>
311ef0c36b7SMark Nunberg    $<TARGET_OBJECTS:lcbht>
3125e994557SMark Nunberg    $<TARGET_OBJECTS:lcbcore>
3138a2dca0cSMark Nunberg    $<TARGET_OBJECTS:lcbcore-cxx>
31407541ddcSMark Nunberg    $<TARGET_OBJECTS:lcb_jsparse>
3158a2dca0cSMark Nunberg    $<TARGET_OBJECTS:lcb_jsoncpp>
31686287387SSergey Avseyev    $<TARGET_OBJECTS:lcb_snappy>
31711e5515bSMark Nunberg    ${LCB_DTRACE_OBJECT}
3189e0bb92fSMark Nunberg    ${lcb_plat_objs}
31911e5515bSMark Nunberg    ${lcb_ssl_objs})
320dbdb5953SMark Nunberg
3215e994557SMark NunbergADD_LIBRARY(couchbaseS STATIC ${LCB_CORE_OBJS})
3222a07f70bSMark NunbergADD_LIBRARY(couchbase ${_lcb_linkspec} ${LCB_CORE_OBJS} ${PROJECT_BINARY_DIR}/dllversion.rc)
32311e5515bSMark Nunberg
32411e5515bSMark Nunberg# For DTrace implementations which need to gain access to all the *.o files first
32511e5515bSMark Nunberg# we need to hook the linker command to a custom perl script which will intercept
32611e5515bSMark Nunberg# the object files passed to the linker, run dtrace on them, and inject the generated
32711e5515bSMark Nunberg# object into the linker commandline. This is a bit fragile but we don't officially
32811e5515bSMark Nunberg# support any of these platforms anyway
32911e5515bSMark NunbergIF(LCB_DTRACE_INSTRO)
33011e5515bSMark Nunberg    SET(_lcb_linkhook "${PROJECT_SOURCE_DIR}/cmake/dtrace-instr-link.pl ${LCB_DTRACE_SRC}")
33111e5515bSMark Nunberg    SET_TARGET_PROPERTIES(couchbase PROPERTIES RULE_LAUNCH_LINK ${_lcb_linkhook})
33211e5515bSMark Nunberg    SET_TARGET_PROPERTIES(couchbaseS PROPERTIES RULE_LAUNCH_LINK ${_lcb_linkhook})
33311e5515bSMark NunbergENDIF()
33411e5515bSMark Nunberg
335b3f8b193SMark Nunberg# This is done to be ABI-compatible with Autotools. On OSX, autotools generates
336b3f8b193SMark Nunberg# a library with a Compatibility and Current versions of 3.x despite our library
337b3f8b193SMark Nunberg# actually being versioned at 2.x. To make things worse, autotools also actually
338b3f8b193SMark Nunberg# provided a _symlink_ of libcouchbase.2.dylib. CMake cannot do this manually
339b3f8b193SMark Nunberg# and thus we disable the SOVERSION appending when on OS X, and revert to
340b3f8b193SMark Nunberg# inserting the version information by hand.
341b3f8b193SMark NunbergIF(NOT APPLE)
342b3f8b193SMark Nunberg    SET_TARGET_PROPERTIES(couchbase PROPERTIES
343b3f8b193SMark Nunberg        SOVERSION "${LCB_SONAME_MAJOR}" VERSION "${LCB_SONAME_FULL}")
344b3f8b193SMark NunbergELSE()
345b3f8b193SMark Nunberg    SET_TARGET_PROPERTIES(couchbase PROPERTIES
346b3f8b193SMark Nunberg        LINK_FLAGS "-compatibility_version ${LCB_SONAME_MAJOR} -current_version ${LCB_SONAME_FULL}"
347b3f8b193SMark Nunberg        OUTPUT_NAME couchbase.2)
348357518f2SSergey Avseyev    IF(NOT LCB_BUILD_STATIC)
349357518f2SSergey Avseyev        ADD_CUSTOM_COMMAND(TARGET couchbase POST_BUILD
350357518f2SSergey Avseyev            COMMAND rm -f libcouchbase.dylib
351357518f2SSergey Avseyev            COMMAND ln libcouchbase.2.dylib libcouchbase.dylib
352357518f2SSergey Avseyev            WORKING_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
353357518f2SSergey Avseyev        INSTALL(FILES ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/libcouchbase.dylib
354357518f2SSergey Avseyev            DESTINATION ${CMAKE_INSTALL_LIBDIR})
355357518f2SSergey Avseyev    ENDIF()
356b3f8b193SMark NunbergENDIF()
35723b04a19STrond Norbye
358968a7580SMark NunbergSET_TARGET_PROPERTIES(couchbase PROPERTIES PREFIX "lib")
35945f09580SMark NunbergSET_TARGET_PROPERTIES(couchbase PROPERTIES IMPORT_PREFIX "lib")
36086287387SSergey AvseyevSET(LCB_LINK_DEPS ${lcb_plat_libs} ${lcb_ssl_libs} ${LCB_HDR_HISTOGRAM_LINK})
36191e86676SMark NunbergIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
36291e86676SMark Nunberg    SET(LCB_LINK_DEPS ${LCB_LINK_DEPS} rt)
36391e86676SMark NunbergENDIF()
364493aa4dbSSergey AvseyevIF(LIBPROFILER)
365493aa4dbSSergey Avseyev    SET(LCB_LINK_DEPS ${LCB_LINK_DEPS} ${LIBPROFILER})
366493aa4dbSSergey AvseyevENDIF()
36723b04a19STrond Norbye
368dbdb5953SMark NunbergTARGET_LINK_LIBRARIES(couchbase ${LCB_LINK_DEPS})
369dbdb5953SMark NunbergTARGET_LINK_LIBRARIES(couchbaseS ${LCB_LINK_DEPS})
370e8c42547SMark Nunberg
37131786854SMark NunbergENABLE_TESTING()
372e8c42547SMark NunbergIF(NOT LCB_NO_TESTS)
373e1ad8c50SMark Nunberg    ADD_SUBDIRECTORY(tests tests)
37400236339SMark NunbergELSE()
37531786854SMark Nunberg    ADD_TEST(NAME dummytest COMMAND echo "No Tests!")
376e8c42547SMark NunbergENDIF(NOT LCB_NO_TESTS)
377e8c42547SMark Nunberg
37845f09580SMark NunbergIF(NOT LCB_NO_TOOLS)
379e1ad8c50SMark Nunberg    ADD_SUBDIRECTORY(tools tools)
38045f09580SMark NunbergENDIF(NOT LCB_NO_TOOLS)
381365e5808STrond Norbye
38242d713deSMark Nunberg# Always add this file, as we need the headers for this!
38342d713deSMark NunbergADD_SUBDIRECTORY(plugins/io/libuv)
384ee28858eSMark NunbergIF(NOT LCB_NO_PLUGINS AND LCB_BUILD_LIBUV)
3857b1a473cSMark NunbergENDIF()
3867b1a473cSMark Nunberg
3877b1a473cSMark NunbergIF(NOT LCB_NO_PLUGINS AND NOT WIN32)
388ee28858eSMark Nunberg    IF(LCB_BUILD_LIBEVENT)
389ee28858eSMark Nunberg        ADD_SUBDIRECTORY(plugins/io/libevent)
390ee28858eSMark Nunberg    ENDIF()
391ee28858eSMark Nunberg    IF(LCB_BUILD_LIBEV)
392ee28858eSMark Nunberg        ADD_SUBDIRECTORY(plugins/io/libev)
393ee28858eSMark Nunberg    ENDIF()
3946505a840SMark Nunberg    IF(NOT (HAVE_LIBEV OR HAVE_LIBEVENT))
39536776cf5SMark Nunberg        MESSAGE(FATAL_ERROR
39636776cf5SMark Nunberg            "libev or libevent development files missing.
39736776cf5SMark Nunberg            You can disable these dependencies by passing
39836776cf5SMark Nunberg            -DLCB_NO_PLUGINS=1 to Cmake, or
39936776cf5SMark Nunberg            --disable-plugins to the configure script")
4006505a840SMark Nunberg    ENDIF()
401e1ad8c50SMark NunbergENDIF()
402295ff401SMark Nunberg
403378e2fa9SMark Nunberg
404e1ad8c50SMark NunbergIF(LCB_MAINTAINER_MODE)
405e1ad8c50SMark Nunberg    IF(NOT (HAVE_LIBEV AND HAVE_LIBEVENT AND HAVE_LIBUV))
406e1ad8c50SMark Nunberg        MESSAGE(FATAL_ERROR "Maintainer mode requires all plugins to be present")
407ca7a5670SMark Nunberg    ENDIF()
4083ad56078SMark NunbergENDIF()
4093ad56078SMark Nunberg
410e1ad8c50SMark NunbergADD_SUBDIRECTORY(plugins/io/select)
411e1ad8c50SMark NunbergADD_SUBDIRECTORY(plugins/io/iocp)
41223b04a19STrond NorbyeINSTALL(TARGETS couchbase
41300236339SMark Nunberg    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
41400236339SMark Nunberg    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
41500236339SMark Nunberg    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR})
416968a7580SMark Nunberg
41742240629STrond NorbyeIF(LCB_INSTALL_HEADERS)
41842240629STrond Norbye    INSTALL(DIRECTORY include/libcouchbase ${LCB_GENSRCDIR}/libcouchbase
41942240629STrond Norbye            DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
42042240629STrond Norbye            FILES_MATCHING PATTERN *.h PATTERN *.c)
42142240629STrond NorbyeENDIF()
4222d93db6eSMark Nunberg
423ea63daecSMark NunbergINSTALL(DIRECTORY doc/man/ DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 FILES_MATCHING PATTERN *.1)
424ea63daecSMark NunbergINSTALL(DIRECTORY doc/man/ DESTINATION ${CMAKE_INSTALL_MANDIR}/man4  FILES_MATCHING PATTERN *.4)
42500236339SMark Nunberg
42668ff03b9SSergey AvseyevIF(MSVC)
42768ff03b9SSergey Avseyev    INSTALL_PDBS(couchbase)
42868ff03b9SSergey AvseyevENDIF()
4298d98592dSMark Nunberg
430b2f9a8b5SMark NunbergSET(_lcb_tarname "libcouchbase-${LCB_VERSION}")
431c6b6dbceSMark NunbergSET(_lcb_manifest "${LCB_GENINFODIR}/MANIFEST")
432b2f9a8b5SMark Nunberg
433814cde7bSMark Nunberg# pkg-config stuff goes with installation
43442240629STrond NorbyeIF(NOT WIN32 AND LCB_INSTALL_PKGCONFIG)
435814cde7bSMark Nunberg    CONFIGURE_FILE(packaging/libcouchbase.pc.in packaging/libcouchbase.pc @ONLY)
436814cde7bSMark Nunberg    INSTALL(FILES ${PROJECT_BINARY_DIR}/packaging/libcouchbase.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
437814cde7bSMark NunbergENDIF()
438814cde7bSMark Nunberg
439814cde7bSMark Nunberg
4408d98592dSMark NunbergADD_CUSTOM_TARGET(uninstall
4418d98592dSMark Nunberg    COMMAND xargs rm -vf < ${CMAKE_CURRENT_BINARY_DIR}/install_manifest.txt)
442b2f9a8b5SMark Nunberg
443b2f9a8b5SMark NunbergADD_CUSTOM_TARGET(file_manifest
444b2f9a8b5SMark Nunberg    COMMAND sh -c 'test -e ${_lcb_manifest} || git ls-files > ${_lcb_manifest}'
4452a07f70bSMark Nunberg    WORKING_DIRECTORY ${PROJECT_SOURCE_DIR})
446b2f9a8b5SMark Nunberg
447b2f9a8b5SMark Nunberg
448b2f9a8b5SMark NunbergADD_CUSTOM_TARGET(dist
449b2f9a8b5SMark Nunberg    COMMAND rm -rf "${_lcb_tarname}"
450b2f9a8b5SMark Nunberg    COMMAND mkdir "${_lcb_tarname}"
451