Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 259 lines (233 sloc) 9.586 kB
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
1 cmake_minimum_required(VERSION 2.6)
1cbe4ca @kostja CPack: initial commit.
kostja authored
2 project(tarantool)
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
3 include(CheckLibraryExists)
4 include(CheckIncludeFile)
a6c1f38 @kostja Some initial fixed to compile on FreeBSD.
kostja authored
5 include(CheckCCompilerFlag)
b5b3a2b @kostja Blueprint 'unmmap-after-fork': review comments.
kostja authored
6 include(CheckSymbolExists)
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
7 find_program(ECHO echo)
8 find_program(CAT cat)
9 find_program(GIT git)
10 find_program(RAGEL ragel)
11 find_program(CONFETTI confetti)
12
65a207b @rtokarev cmake: Check if C++ compiler can compile ObjectiveC sources.
rtokarev authored
13
14 #
15 # Check if CXX compiler can compile ObjectiveC sources.
16 # The code was borrowed from CMakeTestCXXCompiler.cmake
17 #
18 IF(NOT CMAKE_CXX_OBJECTIVEC_COMPILER_WORKS)
19 MESSAGE(STATUS "Check for working CXX (ObjectiveC) compiler: ${CMAKE_CXX_COMPILER}")
20 FILE(WRITE ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXObjectiveCCompiler.m
21 "int main(){return 0;}\n")
22 TRY_COMPILE(CMAKE_CXX_OBJECTIVEC_COMPILER_WORKS ${CMAKE_BINARY_DIR}
23 ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeTmp/testCXXObjectiveCCompiler.m
24 OUTPUT_VARIABLE OUTPUT)
25 SET(CXX_OBJECTIVEC_TEST_WAS_RUN 1)
26 ENDIF(NOT CMAKE_CXX_OBJECTIVEC_COMPILER_WORKS)
27 IF(NOT CMAKE_CXX_OBJECTIVEC_COMPILER_WORKS)
28 MESSAGE(STATUS "Check for working CXX (ObjectiveC) compiler: ${CMAKE_CXX_COMPILER} -- broken")
29 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
30 "Determining if the CXX (ObjectiveC) compiler works failed with "
31 "the following output:\n${OUTPUT}\n\n")
32 MESSAGE(FATAL_ERROR "The C++ compiler \"${CMAKE_CXX_COMPILER}\" "
33 "is not able to compile a simple ObjectiveC test program.\nIt fails "
34 "with the following output:\n ${OUTPUT}\n\n"
35 "CMake will not be able to correctly generate this project.")
36 ELSE(NOT CMAKE_CXX_OBJECTIVEC_COMPILER_WORKS)
37 IF(CXX_OBJECTIVEC_TEST_WAS_RUN)
38 MESSAGE(STATUS "Check for working CXX (ObjectiveC) compiler: ${CMAKE_CXX_COMPILER} -- works")
39 FILE(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
40 "Determining if the CXX (ObjectiveC) compiler works passed with "
41 "the following output:\n${OUTPUT}\n\n")
42 ENDIF(CXX_OBJECTIVEC_TEST_WAS_RUN)
43 SET(CMAKE_CXX_OBJETIVEC_COMPILER_WORKS 1 CACHE INTERNAL "")
44 ENDIF(NOT CMAKE_CXX_OBJECTIVEC_COMPILER_WORKS)
45
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
46 #
d28b00c @kostja CMake build scripts: prepare for multiple module support.
kostja authored
47 # This instructs the rest of the build system what product
48 # and what modules to produce.
49 #
6908df6 @kostja Rename 'silverbox' to 'box', across the board.
kostja authored
50 set (TARANTOOL_PRODUCT "box")
51 set (TARANTOOL_MODULES "box" "feeder")
d28b00c @kostja CMake build scripts: prepare for multiple module support.
kostja authored
52
53 #
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
54 # Set default build type to Debug. This is to ease a developer's
55 # life. Release binaries are built by BuildBot automatically anyway.
56 #
57 if(NOT CMAKE_BUILD_TYPE)
58 set(CMAKE_BUILD_TYPE Debug CACHE STRING
59 "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
60 FORCE)
61 endif()
62
63 #
64 # Perform operating-system specific configuration.
65 #
66 if (${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
67 set(TARGET_OS_LINUX 1)
68 #
69 # Enable GNU glibc extentions.
70 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_GNU_SOURCE")
71 #
72 # On 32-bit systems, support files larger than 2GB
73 # (see man page for feature_test_macros).
74 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_FILE_OFFSET_BITS=64")
75 elseif (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
76 set(TARGET_OS_FREEBSD 1)
77 else()
78 message (FATAL_ERROR "Unsupported platform -- ${CMAKE_SYSTEM_NAME}")
79 endif()
80
b5b3a2b @kostja Blueprint 'unmmap-after-fork': review comments.
kostja authored
81 check_symbol_exists(MAP_ANON sys/mman.h HAVE_MAP_ANON)
82 check_symbol_exists(MAP_ANONYMOUS sys/mman.h HAVE_MAP_ANONYMOUS)
83
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
84 #
a6c1f38 @kostja Some initial fixed to compile on FreeBSD.
kostja authored
85 # Some versions of GNU libc define non-portable __libc_stack_end
86 # which we use to determine the end (or beginning, actually) of
87 # stack. Find whether or not it's present.
88 check_library_exists("" __libc_stack_end "" HAVE_LIBC_STACK_END)
89
90 #
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
91 # Tarantool uses 'coro' (coroutines) library # to implement
92 # cooperative multi-tasking. Since coro.h is included
93 # universally, define the underlying implementation switch
d28b00c @kostja CMake build scripts: prepare for multiple module support.
kostja authored
94 # in the top level CMakeLists.txt, to ensure a consistent
95 # header file layout across the entire project.
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
96 #
97 if (${CMAKE_SYSTEM_PROCESSOR} MATCHES "86")
98 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCORO_ASM")
99 else()
100 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DCORO_SJLJ")
101 set_target_properties(coro PROPERTIES COMPILE_FLAGS "-DCORO_SJLJ")
102 endif()
103 #
104 # Perform build type specific configuration.
105 #
106 set (CMAKE_C_FLAGS_DEBUG "-ggdb -O0")
107 set (CMAKE_C_FLAGS_RELWITHDEBUGINFO "-ggdb -O2")
108 set (CMAKE_C_FLAGS_RELEASE "-DNDEBUG -DNVALGRIND")
109
110 #
4bc75a7 @kostja Merge branch 'master' of farm.corp.mail.ru:tarantool into cmake-based…
kostja authored
111 # Enable 'make TAGS' target.
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
112 #
927e9db @rtokarev Update files generated by confetti.
rtokarev authored
113 add_custom_target(TAGS COMMAND ctags -R --langmap=ObjectiveC:.m.h -e -f TAGS
4bc75a7 @kostja Merge branch 'master' of farm.corp.mail.ru:tarantool into cmake-based…
kostja authored
114 WORKING_DIRECTORY ${CMAKE_SOURCE_DIR})
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
115
116 #
117 # Define TARANTOOL_VERSION -- a string constant with tarantool version.
118 #
1cbe4ca @kostja CPack: initial commit.
kostja authored
119 set (TARANTOOL_VERSION "")
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
120 execute_process (COMMAND ${GIT} describe HEAD
121 OUTPUT_VARIABLE TARANTOOL_VERSION
122 OUTPUT_STRIP_TRAILING_WHITESPACE
123 )
1cbe4ca @kostja CPack: initial commit.
kostja authored
124 #
125 # Make sure the version is set even if building
126 # out of source.
127 #
128 set (CPACK_PACKAGE_VERSION_MAJOR "1")
5c135dc @kostja Increment the version number (1.4.0).
kostja authored
129 set (CPACK_PACKAGE_VERSION_MINOR "4")
130 set (CPACK_PACKAGE_VERSION_PATCH "0")
1cbe4ca @kostja CPack: initial commit.
kostja authored
131 if (TARANTOOL_VERSION STREQUAL "")
132 set (TARANTOOL_VERSION
133 "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
134 endif()
135
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
136
137 #
138 # Set flags for all include files: those maintained by us and
139 # coming from third parties.
140 # We must set -fno-omit-frame-pointer here, since we rely
141 # on frame pointer when getting a backtrace, and it must
142 # be used consistently across all object files.
143 # The same reasoning applies to -fno-stack-protector switch.
144 #
145 set (CMAKE_C_FLAGS
146 "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fno-stack-protector")
147 #
148 # Tarantool code is written in GNU C dialect.
149 # Additionally, compile it with more strict flags than the rest
150 # of the code.
151 #
152 if (${CMAKE_BUILD_TYPE} STREQUAL "None")
153 set (core_cflags "-std=gnu99")
154 else()
155 set (core_cflags "-std=gnu99 -Wall -Wextra -Werror")
156 set (core_cflags "${core_cflags} -Wno-sign-compare -Wno-strict-aliasing")
157 endif()
158
159 #
160 # Specify where to look for include files.
161 #
162 include_directories("${PROJECT_SOURCE_DIR}")
163 include_directories("${PROJECT_SOURCE_DIR}/include")
164 include_directories("${PROJECT_BINARY_DIR}/include")
165
166 #
167 # Now handle all configuration options.
168 #
169 option(ENABLE_GCOV "Enable integration with gcov, a code coverage program" ON)
170 if (ENABLE_GCOV)
171 check_library_exists (gcov __gcov_flush "" HAVE_GCOV)
172 if (NOT HAVE_GCOV)
173 message (FATAL_ERROR
174 "ENABLE_GCOV option requested but gcov library is not found")
175 endif()
176 endif()
177
6908df6 @kostja Rename 'silverbox' to 'box', across the board.
kostja authored
178 option(ENABLE_TRACE "Enable debug trace of tarantool_box execution to
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
179 a file specified in TARANTOOL_TRACE environment variable" ON)
180
181 option(ENABLE_BACKTRACE "Enable output of fiber backtrace information in 'show
182 fiber' administrative command. Only works on x86 architectures, if compiled
183 with gcc. If GNU binutils and binutils-dev libraries are installed, backtrace
184 is output with resolved function (symbol) names. Otherwise only frame
185 addresses are printed." ${CMAKE_COMPILER_IS_GNUCC})
186
a6c1f38 @kostja Some initial fixed to compile on FreeBSD.
kostja authored
187 set (HAVE_BFD False)
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
188 if (ENABLE_BACKTRACE)
189 if (NOT ${CMAKE_COMPILER_IS_GNUCC} OR
190 NOT (${CMAKE_SYSTEM_PROCESSOR} MATCHES "86"))
191 # We only know this option to work with gcc
192 # on x86 architecture.
193 message (FATAL_ERROR "ENABLE_BACKTRACE option is set but the system is not x86 based (${CMAKE_SYSTEM_PROCESSOR}) or the compiler is not GNU GCC (${CMAKE_C_COMPILER}).")
194 endif()
195 # Use GNU bfd if present.
196 check_library_exists (bfd bfd_init "" HAVE_BFD_LIB)
197 check_include_file(bfd.h HAVE_BFD_H)
198 if (HAVE_BFD_LIB AND HAVE_BFD_H)
a6c1f38 @kostja Some initial fixed to compile on FreeBSD.
kostja authored
199 set (HAVE_BFD True)
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
200 message (STATUS "Found GNU bfd headers and libs, enabling symbol ")
201 message (STATUS "resolve in backtraces.")
202 elseif (NOT HAVE_BFD_LIB)
203 message (STATUS "Not found GNU bfd binaries, no symbol resolve.")
204 elseif (NOT HAVE_BFD_H)
205 message (STATUS "Not found GNU bfd headers, no symbol resolve. ")
206 message (STATUS "Consider installing binutils-dev.")
207 endif()
208 endif()
209
bd6091d @kostja CPack: enable statically built binaries.
kostja authored
210 option(ENABLE_STATIC "Perform static linking whenever possible." OFF)
211
212 if (ENABLE_STATIC)
213 set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
214 endif()
215
927e9db @rtokarev Update files generated by confetti.
rtokarev authored
216 # CMake believes that Objective C is a flavor of C++, not C,
217 # and uses g++ compiler for .m files. Since talking CMake out
218 # of this idea is difficult, and since gcc or g++ are only
219 # front-ends to the language-specific compiler specified in
220 # -x option, simply use CXX flags to build Objective C files.
221 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${CMAKE_C_FLAGS}")
222
223 set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
bd6091d @kostja CPack: enable statically built binaries.
kostja authored
224
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
225 add_subdirectory(third_party)
d28b00c @kostja CMake build scripts: prepare for multiple module support.
kostja authored
226 add_subdirectory(cfg)
4fc9752 @dam-xx Create a simple C connector in connector/c.
dam-xx authored
227 add_subdirectory(connector)
d28b00c @kostja CMake build scripts: prepare for multiple module support.
kostja authored
228 add_subdirectory(core)
229 add_subdirectory(mod)
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
230 add_subdirectory(test)
231
6908df6 @kostja Rename 'silverbox' to 'box', across the board.
kostja authored
232 install (FILES README LICENSE doc/box-protocol.txt
1cbe4ca @kostja CPack: initial commit.
kostja authored
233 DESTINATION doc)
234
235 include (cmake/tarantool_cpack.cmake)
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
236 #
237 # Output compile-time defines into config.h. Do it at the end
238 # of the script to make sure all variables are set.
239 #
240 configure_file(
241 "${PROJECT_SOURCE_DIR}/include/config.h.cmake"
242 "${PROJECT_BINARY_DIR}/include/config.h"
243 )
244
245 message (STATUS "")
d28b00c @kostja CMake build scripts: prepare for multiple module support.
kostja authored
246 message (STATUS "Successfully configured Tarantool infrastructure on ")
247 message (STATUS "${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_PROCESSOR}, build type '${CMAKE_BUILD_TYPE}'. ")
248 message (STATUS "The product you're building is \"${TARANTOOL_PRODUCT}\", enabled modules are ")
249 message (STATUS "${TARANTOOL_MODULES}.")
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
250 message (STATUS "Please check out CMakeCache.txt to view or modify configuration results.")
251 message (STATUS "")
252 message (STATUS "*** The following options are on in this configuration: ***")
253 message (STATUS "ENABLE_GCOV: ${ENABLE_GCOV}")
254 message (STATUS "ENABLE_TRACE: ${ENABLE_TRACE}")
255 message (STATUS "ENABLE_BACKTRACE: ${ENABLE_BACKTRACE}")
256 message (STATUS "Backtrace is with symbol resolve: ${HAVE_BFD}")
bd6091d @kostja CPack: enable statically built binaries.
kostja authored
257 message (STATUS "ENABLE_STATIC: ${ENABLE_STATIC}")
82e966b @kostja Blueprint 'cmake-based-build' initial commit.
kostja authored
258 message (STATUS "")
Something went wrong with that request. Please try again.