forked from HewlettPackard/foedus_code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
308 lines (276 loc) · 13.6 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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#############################################################################
#
# libfoedus-core CMake script
#
# This CMake project is a bit special because we expect user programs to
# directly include this cmake script to build together as a possible use case.
# Therefore, this CMake script must be compilable even if it was NOT invoked
# by the super build.
#
# Output library: foedus-core
#
# Parameters:
#
# FOEDUS_BUILD_STATIC_LIBS, ON/OFF (Default OFF), Whether to build foedus-core as a static library.
# We recommend building the shared version. It saves space, and you won't save more than
# a few CPU cycles per non-inlined function call, which is probably negligible.
# We avoid overloading cmake's standard params, BUILD_SHARED_LIBS etc, because they are used in
# other libraries we link to.
#
#############################################################################
cmake_minimum_required(VERSION 2.4)
cmake_policy(SET CMP0003 NEW)
project(foedus_core)
option(FOEDUS_BUILD_STATIC_LIBS "Build FOEDUS static library." OFF)
# FIRST, prohibit in-source build.
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/WarnInSrcBuild.cmake)
# Pointers to the root folders of this project.
# These are used in a few places of the following cmake scripts, so we define them here.
set(FOEDUS_CORE_SRC_ROOT ${CMAKE_CURRENT_SOURCE_DIR})
set(FOEDUS_CORE_SRC_BIN ${CMAKE_CURRENT_BINARY_DIR})
mark_as_advanced(FOEDUS_CORE_SRC_ROOT FOEDUS_CORE_SRC_BIN)
set(CMAKE_COLOR_MAKEFILE ON)
set(CMAKE_VERBOSE_MAKEFILE ON)
message (STATUS)
message (STATUS "Building libfoedus-core... Environments:")
message (STATUS "========================================")
message (STATUS "CMAKE_SYSTEM=${CMAKE_SYSTEM}")
message (STATUS "CMAKE_SYSTEM_NAME=${CMAKE_SYSTEM_NAME}")
message (STATUS "CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
message (STATUS "CMAKE_C_COMPILER=${CMAKE_C_COMPILER}")
message (STATUS "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}")
message (STATUS "========================================")
message (STATUS)
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
message(STATUS "Yikes, you are on AArch64! Note: FOEDUS's AArch64 support is still experimental.")
endif ()
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
#############################################################################
#
# Compiler Options : BEGIN
#
#############################################################################
# We crucially need libnuma, so it's a required dependency.
# We considered static linking, but statically linking such a low-level library is a bit risky.
find_package(Numa REQUIRED)
# We also need pthread. Note that linking against libstdc with C++11 flag is not enough.
find_package(Threads REQUIRED)
# google-perftools is optional. We use it only for performance experiments.
# Every such code should be within #ifdef HAVE_GOOGLEPERFTOOLS.
find_package(GooglePerftools)
if (GOOGLEPERFTOOLS_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_GOOGLEPERFTOOLS")
endif (GOOGLEPERFTOOLS_FOUND)
# Also PAPI with same cautions.
find_package(Papi)
if (PAPI_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_PAPI")
endif (PAPI_FOUND)
# We do assume C++11.
# However, external projects can link to this library even if they use C++98.
# Our public header files do the switching (hides some API if C++11 is disabled).
if (NOT "${CMAKE_CXX_FLAGS}" MATCHES "\\-std\\=c\\+\\+11")
message(STATUS "The external project that invokes this CMake script disables c++11."
" libfoedus-core can be still used as a shared library, but some API will be disabled.")
# this set(CMAKE_CXX_FLAGS) is directory-wide, so it does not affect external projects
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
endif ()
# We need to make sure -pthread compiler option is specified
if (NOT "${CMAKE_CXX_FLAGS}" MATCHES "\\-pthread")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
endif ()
# We anyway use 64-bit file offsets, but ideally should be consistent with client program's.
if (NOT "${CMAKE_CXX_FLAGS}" MATCHES "\\-D\\_FILE\\_OFFSET\\_BITS\\=64")
message(STATUS "Automatically added -D_FILE_OFFSET_BITS=64 for libfoedus-core."
" Your client program should also enable the compile option.")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -D_FILE_OFFSET_BITS=64")
endif ()
# In an ideal world, our code should be free from bugs caused by careless aliasing.
# gcc gives some warning to achieve that, but in reality far from enough to be safe.
# Hence, we prohibit compilers from assuming strict alising rule.
# If it has a significant performance impact, probably something is anyway wrong..
# http://stackoverflow.com/questions/1225741/performance-impact-of-fno-strict-aliasing
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-strict-aliasing")
# We need gcc's libatomic.so for AArch64. It's not required on x86.
find_package(GccAtomic)
if ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
# gcc-aarch64 doesn't support -mcx16. We use gcc's libatomic instead.
# You must make sure you have libatomic.so.
if (NOT GCCLIBATOMIC_FOUND)
message(SEND_ERROR "ERROR: FOEDUS on AArch64 needs gcc's libatomic.so. We couldn't find it.")
endif ()
else ()
# Enable GCC's built-in 128bit CAS via -mcx16. We don't need libatomic.so on x86.
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mcx16")
endif ()
set(CMAKE_INCLUDE_CURRENT_DIR OFF)
#############################################################################
#
# Build Target Libraries : BEGIN
#
#############################################################################
# include files
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) # our main include folder
include_directories(SYSTEM
# libnuma
${NUMA_INCLUDE_DIR}
# libbacktrace
${CMAKE_CURRENT_SOURCE_DIR}/third_party/libbacktrace
# tinyxml2
${CMAKE_CURRENT_SOURCE_DIR}/third_party/tinyxml2-2.1.0
${CMAKE_CURRENT_SOURCE_DIR}/third_party/glog-0.3.4/src
# We also include the BINARY folder of glog as glog generates config.h
${CMAKE_CURRENT_BINARY_DIR}/third_party/glog-0.3.4/src
${CMAKE_CURRENT_SOURCE_DIR}/third_party/valgrind-3.9.0/include
${CMAKE_CURRENT_SOURCE_DIR}/third_party/xxHash-r39 # xxhash
)
# gperftools is optional for this library
if (GOOGLEPERFTOOLS_FOUND)
include_directories(SYSTEM ${GooglePerftools_INCLUDE_DIR})
endif (GOOGLEPERFTOOLS_FOUND)
# same above
if (PAPI_FOUND)
include_directories(SYSTEM ${PAPI_INCLUDE_DIR})
endif (PAPI_FOUND)
# This project contains glog so that it can compile by itself.
# We also use gflags and gtest, but this core library itself is a pure data processing library
# without executables nor unit tests. So, we don't contain them in her and instead have them
# in one above.
add_subdirectory(third_party)
# Collect all cpp files in the main source folder.
set_property(GLOBAL PROPERTY ALL_FOEDUS_CORE_SRC "")
add_subdirectory(src)
get_property(TMP_ALL_FOEDUS_CORE_SRC GLOBAL PROPERTY ALL_FOEDUS_CORE_SRC)
if (FOEDUS_BUILD_STATIC_LIBS)
add_library(foedus-core STATIC ${TMP_ALL_FOEDUS_CORE_SRC})
else (FOEDUS_BUILD_STATIC_LIBS)
add_library(foedus-core SHARED ${TMP_ALL_FOEDUS_CORE_SRC})
endif (FOEDUS_BUILD_STATIC_LIBS)
set(foedus-dependencies)
# Link to libbacktrace, libglog, libnuma, libgperftools (if found)
set(foedus-dependencies ${foedus-dependencies} backtrace)
set(foedus-dependencies ${foedus-dependencies} glog-static)
set(foedus-dependencies ${foedus-dependencies} ${NUMA_LIBRARY})
set(foedus-dependencies ${foedus-dependencies} tinyxml2static)
set(foedus-dependencies ${foedus-dependencies} xxhashstatic)
set(foedus-dependencies ${foedus-dependencies} ${CMAKE_THREAD_LIBS_INIT})
if (GOOGLEPERFTOOLS_FOUND)
set(foedus-dependencies ${foedus-dependencies} ${GooglePerftools_LIBRARIES})
endif (GOOGLEPERFTOOLS_FOUND)
if (PAPI_FOUND)
# we use dynamic library of PAPI mainly because of fPIC issue.
# in terms of license, it's okay to statically link (BSD-style).
set(foedus-dependencies ${foedus-dependencies} ${PAPI_DYNAMIC_LIBRARY})
endif (PAPI_FOUND)
if (GCCLIBATOMIC_FOUND AND "${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "aarch64")
set(foedus-dependencies ${foedus-dependencies} ${GCCLIBATOMIC_LIBRARY})
endif ()
target_link_libraries(foedus-core ${foedus-dependencies})
# Invoke CPPLINT (if ENABLE_CPPLINT is given)
include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/CpplintWrapper.cmake)
CPPLINT_RECURSIVE(cpplint_include
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include
${CMAKE_CURRENT_BINARY_DIR}/include)
CPPLINT_RECURSIVE(cpplint_src
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_SOURCE_DIR}/src
${CMAKE_CURRENT_BINARY_DIR}/src)
add_dependencies(foedus-core cpplint_include cpplint_src)
#############################################################################
#
# Install headers/libraries/documents : BEGIN
#
#############################################################################
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include" DESTINATION "${CMAKE_INSTALL_PREFIX}")
install(TARGETS foedus-core DESTINATION "${CMAKE_INSTALL_PREFIX}/lib64")
make_directory(${CMAKE_CURRENT_BINARY_DIR}/dox/html)
make_directory(${CMAKE_CURRENT_BINARY_DIR}/dox/latex)
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dox/html"
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/doc/foedus-core")
install(DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/dox/latex"
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/doc/foedus-core")
set(CPACK_PACKAGE_VERSION ${FOEDUS_VERSION})
set(CPACK_GENERATOR "RPM")
set(CPACK_PACKAGE_NAME "foedus-core")
set(CPACK_PACKAGE_RELEASE 1)
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_PACKAGE_VENDOR "Hewlett Packard")
set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_PACKAGE_RELEASE}.${CMAKE_SYSTEM_PROCESSOR}")
set(CPACK_RPM_USER_BINARY_SPECFILE "${CMAKE_CURRENT_BINARY_DIR}/rpm.spec")
set(CPACK_TARGET_RPM_DIR "${CMAKE_CURRENT_BINARY_DIR}/_CPack_Packages/Linux")
make_directory(${CPACK_TARGET_RPM_DIR})
make_directory(${CPACK_TARGET_RPM_DIR}/tmp)
make_directory(${CPACK_TARGET_RPM_DIR}/BUILD)
make_directory(${CPACK_TARGET_RPM_DIR}/RPMS)
make_directory(${CPACK_TARGET_RPM_DIR}/SOURCES)
make_directory(${CPACK_TARGET_RPM_DIR}/SPECS)
make_directory(${CPACK_TARGET_RPM_DIR}/SRPMS)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/rpm.spec.cmake" "${CMAKE_CURRENT_BINARY_DIR}/rpm.spec" @ONLY IMMEDIATE)
include(CPack)
# Cheatsheet:
# http://schneide.wordpress.com/2013/02/11/build-a-rpm-package-using-cmake/
#############################################################################
#
# Doxygen: BEGIN
#
#############################################################################
# Doxygen commands (not mandatory)
find_package(Doxygen)
if(DOXYGEN_FOUND)
set(DOXYGEN_INCLUDE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(DOXYGEN_LAYOUT "${CMAKE_CURRENT_SOURCE_DIR}/DoxygenLayout.xml")
set(DOXYGEN_TARGETS "${CMAKE_CURRENT_SOURCE_DIR}/include")
set(DOXYGEN_TARGETS "${DOXYGEN_TARGETS} ${CMAKE_CURRENT_SOURCE_DIR}/src")
set(DOXYGEN_TARGETS "${DOXYGEN_TARGETS} ${NUMA_INCLUDE_DIR}/numa.h")
# include other dependencies if it's worth doing. Most of them are not.
# set(DOXYGEN_TARGETS "${DOXYGEN_TARGETS} ${CMAKE_CURRENT_BINARY_DIR}/third_party/glog/src") # too big
# Doxygen until ver 1.8.6 had a bug; it allowed only a filename in USE_MDFILE_AS_MAINPAGE,
# not a full path. see https://bugzilla.gnome.org/show_bug.cgi?id=720092
# To work it around, we copy the file to bin folder and use only the file name
set(DOXYGEN_MAINPAGE_MARKDOWN "README.markdown")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/README.markdown ${CMAKE_CURRENT_BINARY_DIR}/README.markdown COPYONLY)
# set(DOXYGEN_MAINPAGE_MARKDOWN "${CMAKE_CURRENT_SOURCE_DIR}/README.markdown")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(dox
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating API documentation with Doxygen" VERBATIM)
add_custom_target(browse-dox
COMMAND google-chrome ${CMAKE_CURRENT_BINARY_DIR}/dox/html/index.html
DEPENDS dox)
# I recommend "yum install texlive texlive-*" to make this work. it requires a few
# additional sty files.
add_custom_target(pdf-dox
COMMAND epstopdf *.eps # sudo yum install texlive-eps*
COMMAND pdflatex refman.tex # sudo yum install texlive
COMMAND makeindex refman.idx
COMMAND pdflatex refman.tex
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dox/latex/
COMMENT "Generating a single PDF with Doxygen"
DEPENDS dox)
add_custom_target(browse-pdf-dox
COMMAND okular refman.pdf
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/dox/latex/
DEPENDS pdf-dox)
else(DOXYGEN_FOUND)
add_custom_target(dox ${CMAKE_COMMAND} -E echo "Doxygen not found. No documents generated.")
endif(DOXYGEN_FOUND)
#############################################################################
#
# Setting environment: BEGIN
#
#############################################################################
add_custom_target(set-env
COMMAND sysctl -w kernel.shmmax=9223372036854775807
COMMAND sysctl -w kernel.shmall=1152921504606846720
COMMAND sysctl -w fs.file-max=1000000
COMMAND sysctl -p
COMMAND sysctl -w vm.nr_hugepages=1000
COMMENT "Sets linux environments for FOEDUS. This is convenient to setup a test/develop environment."
" You need to run this with sudo. To avoid running this after each reboot, you should also set"
"the following in /etc/sysctl.conf: kernel.shmmax = 9223372036854775807"
" kernel.shmall = 1152921504606846720. Also, the nr_hugepages set here is a minimal value"
" to pass testcases. You must configure it for performance tests and real use"
)