forked from couchbase/ns_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
222 lines (188 loc) · 8.76 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
CMAKE_MINIMUM_REQUIRED (VERSION 2.8)
PROJECT (ns_server)
INCLUDE (FindCouchbaseErlang)
INCLUDE (FindCouchbaseGo)
# Global project variables
# Installation subdir
SET (INST_LIBDIR "lib/ns_server/erlang/lib")
SET (PRODUCT_VERSION "" CACHE STRING "Product version with build number")
# If PRODUCT_VERSION is set externally, derive product version string based on
# it and BUILD_ENTERPRISE. Otherwise, fallback to output of 'git describe'.
IF ("${PRODUCT_VERSION}" STREQUAL "")
# Cache "git describe" output
EXECUTE_PROCESS(COMMAND git describe
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
OUTPUT_VARIABLE _product_version
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE)
ELSE ("${PRODUCT_VERSION}" STREQUAL "")
SET(_product_version "${PRODUCT_VERSION}")
ENDIF ("${PRODUCT_VERSION}" STREQUAL "")
IF (BUILD_ENTERPRISE)
SET (_ns_version "${_product_version}-enterprise")
ELSE (BUILD_ENTERPRISE)
SET (_ns_version "${_product_version}-community")
ENDIF (BUILD_ENTERPRISE)
SET (NS_SERVER_VERSION "${_ns_version}" CACHE STRING
"Couchbase server version" FORCE)
MARK_AS_ADVANCED (NS_SERVER_VERSION)
# Create rebar.config
SET (COUCHDB_SRC_DIR "${PROJECT_SOURCE_DIR}/../couchdb" CACHE PATH "Path to couchdb source")
SET (COUCHDB_BIN_DIR "${CMAKE_BINARY_DIR}/couchdb" CACHE PATH "Path to couchdb build directory")
IF (NOT EXISTS "${COUCHDB_SRC_DIR}/src/couchdb/couch_db.hrl")
MESSAGE (FATAL_ERROR "Could not find couch_db.hrl; please re-run CMake with "
"-DCOUCHDB_SRC_DIR=<path/to/couchdb source>")
ENDIF (NOT EXISTS "${COUCHDB_SRC_DIR}/src/couchdb/couch_db.hrl")
# Other generated files
SET (all_img_js "${PROJECT_SOURCE_DIR}/priv/public/js/all-images.js")
ADD_CUSTOM_COMMAND (OUTPUT "${all_img_js}"
COMMAND "${CMAKE_COMMAND}" -D "pubdir=${PROJECT_SOURCE_DIR}/priv/public"
-D "outfile=${all_img_js}"
-P "${PROJECT_SOURCE_DIR}/cmake_modules/build-all-images.cmake")
ADD_CUSTOM_TARGET (all_images ALL DEPENDS "${all_img_js}")
FILE (WRITE "${PROJECT_BINARY_DIR}/cluster_run.configuration"
"prefix=\"${CMAKE_INSTALL_PREFIX}\"\n")
SET (app_min_js "${PROJECT_BINARY_DIR}/priv/public/ui/app.min.js")
SET (index_min_html "${PROJECT_BINARY_DIR}/priv/public/ui/index.min.html")
ADD_CUSTOM_TARGET (minify ALL
COMMAND "${CMAKE_COMMAND}"
-D "PROJECT_SOURCE_DIR=${PROJECT_SOURCE_DIR}"
-D "INDEX_HTML_FILE=${PROJECT_SOURCE_DIR}/priv/public/ui/index.html"
-D "APP_MIN_FILE=${app_min_js}"
-D "INDEX_MIN_FILE=${index_min_html}"
-P "${PROJECT_SOURCE_DIR}/cmake_modules/minify.cmake"
DEPENDS ns_minify)
# Various cleaning targets
ADD_CUSTOM_TARGET (ns_realclean
COMMAND "${CMAKE_COMMAND}" -E remove -f cov.html erl_crash.dump deps/vbmap/vbmap
COMMAND "${CMAKE_COMMAND}" -E remove_directory test/log
COMMAND "${CMAKE_COMMAND}" -E remove_directory ebin
COMMAND "${CMAKE_COMMAND}" -E remove_directory docs
COMMAND "${CMAKE_COMMAND}" -E remove -f rebar.config
COMMAND "${CMAKE_COMMAND}" -E remove -f src/ns_server.app.src
COMMAND "${CMAKE_COMMAND}" -E remove -f ${all_img_js}
COMMAND "${CMAKE_COMMAND}" -E remove -f ${app_min_js}
COMMAND "${CMAKE_COMMAND}" -E remove -f ${index_min_html}
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
VERBATIM)
ADD_DEPENDENCIES (realclean ns_realclean)
ADD_CUSTOM_TARGET (ns_dataclean
COMMAND "${CMAKE_COMMAND}" -E remove_directory data
COMMAND "${CMAKE_COMMAND}" -E remove_directory coverage
COMMAND "${CMAKE_COMMAND}" -E remove_directory couch
COMMAND "${CMAKE_COMMAND}" -E remove_directory logs
COMMAND "${CMAKE_COMMAND}" -E remove_directory tmp
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
VERBATIM)
SET (ns_server_app_src "${PROJECT_SOURCE_DIR}/src/ns_server.app.src")
SET (rebar_config "${PROJECT_SOURCE_DIR}/rebar.config")
ADD_CUSTOM_TARGET (ns_cfg DEPENDS "${ns_server_app_src}" "${rebar_config}")
ADD_CUSTOM_COMMAND(OUTPUT "${ns_server_app_src}"
COMMAND "${CMAKE_COMMAND}" -D "INPUT_FILE=${ns_server_app_src}.in"
-D "OUTPUT_FILE=${ns_server_app_src}"
-D "SEARCH=NS_SERVER_VERSION"
-D "REPLACE=${NS_SERVER_VERSION}"
-P "${PROJECT_SOURCE_DIR}/cmake_modules/string-replace.cmake"
VERBATIM)
ADD_CUSTOM_COMMAND(OUTPUT "${rebar_config}"
COMMAND "${CMAKE_COMMAND}" -D "INPUT_FILE=${rebar_config}.in"
-D "OUTPUT_FILE=${rebar_config}"
-D "SEARCH=COUCHDB_SRC_DIR"
-D "REPLACE=${COUCHDB_SRC_DIR}"
-P "${PROJECT_SOURCE_DIR}/cmake_modules/string-replace.cmake"
VERBATIM)
ADD_CUSTOM_TARGET (ns_distclean)
ADD_DEPENDENCIES (ns_distclean realclean ns_dataclean)
ADD_SUBDIRECTORY (deps)
Rebar (TARGET ns_server NOCLEAN
DEPENDS ale mlockall ns_babysitter ns_ssl_proxy gen_smtp ns_couchdb ns_cfg)
# Test invocation
ADD_TEST(NAME ns_test
COMMAND "${CMAKE_COMMAND}" -D "ERL_EXECUTABLE=${ERL_EXECUTABLE}"
-D "COUCHDB_BIN_DIR=${COUCHDB_BIN_DIR}"
-P "${PROJECT_SOURCE_DIR}/cmake_modules/do-test.cmake"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}")
# Also create a custom target
ADD_CUSTOM_TARGET (ns_test COMMAND ${CMAKE_CTEST_COMMAND} -VV -R ns_test)
ADD_DEPENDENCIES (ns_test ns_server)
# Add custom target allowing folks to easily run the tests via
# make (and not via directly invoking ctest).
ADD_CUSTOM_TARGET(ns_ui_test COMMAND karma start karma.conf.js --single-run
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}/priv/public/ui)
# Docs
ADD_CUSTOM_TARGET (ns_docs COMMAND priv/erldocs ./docs/erldocs
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" VERBATIM)
#
# Dialyzer targets
#
# Get COUCHBASE_PLT from environment, if specified
IF (DEFINED ENV{COUCHBASE_PLT})
SET (_couchbase_plt "$ENV{COUCHBASE_PLT}")
SET (_force_plt FORCE)
ELSE (DEFINED ENV{COUCHBASE_PLT})
SET (_couchbase_plt "${PROJECT_SOURCE_DIR}/couchbase.plt")
ENDIF (DEFINED ENV{COUCHBASE_PLT})
GET_FILENAME_COMPONENT (_couchbase_plt "${_couchbase_plt}" REALPATH)
SET (COUCHBASE_PLT "${_couchbase_plt}" CACHE FILEPATH
"Full path to couchbase.plt for dialyzer targets" ${_force_plt})
MESSAGE (STATUS "COUCHBASE_PLT set to ${COUCHBASE_PLT}")
# Find OTP version
EXECUTE_PROCESS (COMMAND "${ERL_EXECUTABLE}" -noshell -eval
"io:format(\"~s~n\", [erlang:system_info(otp_release)]), erlang:halt()."
OUTPUT_VARIABLE OTP_RELEASE)
SET (dialyzer_args -Wno_return -Wno_improper_lists)
IF (OTP_RELEASE MATCHES "^R?1[5-9].*$$")
LIST (APPEND dialyzer_args -Wno_undefined_callbacks)
ENDIF ()
ADD_CUSTOM_TARGET (ns_dialyzer
COMMAND "${CMAKE_COMMAND}" -D "COUCHDB_BIN_DIR=${COUCHDB_BIN_DIR}"
-D "DIALYZER_FLAGS=${dialyzer_args}"
-D "COUCHBASE_PLT=${COUCHBASE_PLT}"
-P "${PROJECT_SOURCE_DIR}/cmake_modules/do-dialyzer.cmake"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" VERBATIM)
ADD_DEPENDENCIES (ns_dialyzer ns_server)
SET (obsessive_args -Wunmatched_returns -Werror_handling -Wrace_conditions
-Wbehaviours -Wunderspecs)
ADD_CUSTOM_TARGET (ns_dialyzer_obsessive
COMMAND "${CMAKE_COMMAND}" -D "COUCHDB_BIN_DIR=${COUCHDB_BIN_DIR}"
-D "DIALYZER_FLAGS=${obsessive_args}"
-D "COUCHBASE_PLT=${COUCHBASE_PLT}"
-P "${PROJECT_SOURCE_DIR}/cmake_modules/do-dialyzer.cmake"
WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" VERBATIM)
ADD_DEPENDENCIES (ns_dialyzer_obsessive ns_server)
#
# Install
#
INSTALL (DIRECTORY ebin DESTINATION "${INST_LIBDIR}/ns_server")
INSTALL (DIRECTORY priv/public DESTINATION "${INST_LIBDIR}/ns_server/priv")
INSTALL (PROGRAMS cbbrowse_logs cbcollect_info cbreset_password DESTINATION bin)
INSTALL (PROGRAMS scripts/cbdump-config scripts/dump-guts DESTINATION bin)
INSTALL (PROGRAMS scripts/escript-wrapper scripts/dump-stats DESTINATION bin)
# Configure custom copies of scripts for installation
SET (PREFIX "${CMAKE_INSTALL_PREFIX}")
SET (_instdir "${PROJECT_BINARY_DIR}/instfiles")
FILE (REMOVE_RECURSE "${_instdir}")
CONFIGURE_FILE (couchbase-server.sh.in "${_instdir}/couchbase-server" @ONLY)
INSTALL (PROGRAMS "${_instdir}/couchbase-server" DESTINATION bin)
SET (_etcdir "${_instdir}/etc")
FILE (MAKE_DIRECTORY "${_etcdir}")
# MacOS (at least) has a distinction between DATA_PREFIX and BIN_PREFIX, so we
# need to replace both
SET (DATA_PREFIX "${PREFIX}")
SET (BIN_PREFIX "${PREFIX}")
CONFIGURE_FILE (etc/static_config.in "${_etcdir}/couchbase/static_config" @ONLY)
FILE (WRITE "${_etcdir}/couchbase/config" "") # create empty file
SET (_cdbetcdir "${_etcdir}/couchdb/default.d")
FILE (MAKE_DIRECTORY "${_cdbetcdir}")
SET (COUCHBASE_DB_DIR "${CMAKE_INSTALL_PREFIX}/var/lib/couchbase/data")
CONFIGURE_FILE (etc/capi.ini.in "${_cdbetcdir}/capi.ini" @ONLY)
INSTALL (DIRECTORY "${_etcdir}/" DESTINATION etc)
# Empty directory to be "installed" multiple times with varying permissions
FILE (MAKE_DIRECTORY "${_instdir}/var")
INSTALL (DIRECTORY "${_instdir}/var/" DESTINATION var/lib)
INSTALL (DIRECTORY "${_instdir}/var/" DESTINATION var/lib/couchbase
DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_WRITE GROUP_EXECUTE)
INSTALL (DIRECTORY "${_instdir}/var/" DESTINATION var/lib/couchbase/logs
DIRECTORY_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE
GROUP_READ GROUP_WRITE GROUP_EXECUTE)