1d602442cSChiyoung Seo## Dependencies
2d602442cSChiyoung Seo
3d602442cSChiyoung SeoOn non-Windows platforms, there is a dependency on Snappy library because ForestDB supports an option to compress a document body using Snappy.
4d602442cSChiyoung SeoPlease visit [Snappy site](https://code.google.com/p/snappy/) for more details.
5d602442cSChiyoung Seo
6d602442cSChiyoung Seo* **Ubuntu**
7d602442cSChiyoung Seo
8c6c3d274SChiyoung Seo    `sudo apt-get install libsnappy-dev`
9d602442cSChiyoung Seo
10d602442cSChiyoung Seo* **CentOS**
11d602442cSChiyoung Seo
12d602442cSChiyoung Seo    `wget https://snappy.googlecode.com/files/snappy-1.1.1.tar.gz`
13d602442cSChiyoung Seo
14d602442cSChiyoung Seo    `tar -xvfz snappy-1.1.1.tar.gz`
15d602442cSChiyoung Seo
16d602442cSChiyoung Seo    `cd snappy-1.1.1`
17d602442cSChiyoung Seo
18d602442cSChiyoung Seo    `./configure && make && sudo make install`
19d602442cSChiyoung Seo
20d602442cSChiyoung Seo* **OS X**
21d602442cSChiyoung Seo
22d602442cSChiyoung Seo    `sudo brew install snappy`
23d602442cSChiyoung Seo
24c893197bSChiyoung SeoWe also use the asynchronous I/O library `libaio` on Linux if it is available, to submit multiple I/O requests at once to speed up fetching non-resident blocks from disk. As of this time, we use `libaio` to read data blocks from the old file during the compaction.
25c6c3d274SChiyoung Seo
26c6c3d274SChiyoung Seo* **Ubuntu**
27c6c3d274SChiyoung Seo
28c6c3d274SChiyoung Seo    `sudo apt-get install libaio-devel`
29c6c3d274SChiyoung Seo
30c6c3d274SChiyoung Seo* **CentOS**
31c893197bSChiyoung Seo
32c6c3d274SChiyoung Seo    `sudo yum install libaio-devel`
33c6c3d274SChiyoung Seo
34c6c3d274SChiyoung SeoWe plan to support asynchronous I/O in other operating systems such as Windows and OS X, soon.
35c6c3d274SChiyoung Seo
3630eab6fdSChiyoung SeoFor better memory fragmentation and concurrency management, jemalloc can be linked to ForestDB if available on the host environment. Please visit [jemalloc site](http://www.canonware.com/jemalloc/) for more information and install guideline.
3730eab6fdSChiyoung Seo
38bc44457dSChiyoung SeoDatabase encryption is also supported and can be enabled at compilation time. Currently, we support CommonCrypto library on iOS and OS X, [OpenSSL](https://www.openssl.org/), and [LibTomCrypt](https://github.com/libtom/libtomcrypt).
39bc44457dSChiyoung Seo
40d602442cSChiyoung Seo## Compilation and Build
41d602442cSChiyoung Seo
42aa8ae3abSChiyoung SeoWe use [CMake](http://www.cmake.org/cmake/) to provide the build support for a wide range of platforms. Cmake version 3.1 is required at least to have C++11 support. Please follow the instructions below to install CMake in your target platform.
43d602442cSChiyoung Seo
44d932ffa5SJung-Sang Ahn* **Ubuntu**
45d932ffa5SJung-Sang Ahn
46d932ffa5SJung-Sang Ahn    `sudo apt-get install cmake`
47d932ffa5SJung-Sang Ahn
48d932ffa5SJung-Sang Ahn* **Centos**
49d602442cSChiyoung Seo
50c83d9833SChiyoung Seo    `wget http://www.cmake.org/files/v2.8/cmake-3.4.3.tar.gz`
51d602442cSChiyoung Seo
52c83d9833SChiyoung Seo    `tar xvfz cmake-3.4.3.tar.gz`
53d602442cSChiyoung Seo
54c83d9833SChiyoung Seo    `cd cmake-3.4.3`
55d602442cSChiyoung Seo
56d602442cSChiyoung Seo    `./bootstrap && make && sudo make install`
57d602442cSChiyoung Seo
58d602442cSChiyoung Seo* **OS X**
59d602442cSChiyoung Seo
60d602442cSChiyoung Seo    `brew install cmake`
61d602442cSChiyoung Seo
62d602442cSChiyoung Seo* **Windows**
63d602442cSChiyoung Seo
64d932ffa5SJung-Sang Ahn    Please download and install CMake binary for Windows from [CMake download page](http://www.cmake.org/cmake/resources/software.html).
65d602442cSChiyoung Seo
66d602442cSChiyoung SeoOnce CMake is installed, please follow the instructions below to compile and build ForestDB on Ubuntu, Centos, or OS X:
67d602442cSChiyoung Seo
68f664b506SChris Hillery`git clone git://github.com/couchbase/forestdb`
69d602442cSChiyoung Seo
70d602442cSChiyoung Seo`cd forestdb`
71d602442cSChiyoung Seo
72d602442cSChiyoung Seo`mkdir build`
73d602442cSChiyoung Seo
74d602442cSChiyoung Seo`cd build`
75d602442cSChiyoung Seo
76d602442cSChiyoung Seo`cmake ../`
77d602442cSChiyoung Seo
781e4828d5SJung-Sang Ahn(The default value of `CMAKE_BUILD_TYPE` is `RelWithDebInfo`. If you want to build with optimizations disabled for debugging, type `cmake -DCMAKE_BUILD_TYPE=Debug ../` instead.)
791e4828d5SJung-Sang Ahn
8030eab6fdSChiyoung Seo`_JEMALLOC` variable can be optionally set to 1 and passed to link jemalloc to ForestDB (`cmake -D_JEMALLOC=1 ../`)
8130eab6fdSChiyoung Seo
82bc44457dSChiyoung Seo`_ENCRYPTION` macro can be also optionally passed to specify which crypto library (`commoncrypto`, `openssl`, or `libtomcrypt`) is used to support database encryption (e.g., `cmake -D_ENCRYPTION=commoncrypto ../`)
83bc44457dSChiyoung Seo
84d602442cSChiyoung Seo`make all`
85d602442cSChiyoung Seo
86d932ffa5SJung-Sang AhnOn Windows (using Visual Studio's CL compiler), the instructions are as follows:
87d932ffa5SJung-Sang Ahn
88f664b506SChris Hillery`git clone git://github.com/couchbase/forestdb` (or clone repository using [TortoiseGit](http://code.google.com/p/tortoisegit/))
89d932ffa5SJung-Sang Ahn
90d932ffa5SJung-Sang Ahn`cd forestdb`
91d932ffa5SJung-Sang Ahn
92d932ffa5SJung-Sang Ahn`mkdir build`
93d932ffa5SJung-Sang Ahn
94d932ffa5SJung-Sang Ahn`cd build`
95d932ffa5SJung-Sang Ahn
96d932ffa5SJung-Sang AhnNote that the path and environment variables for command-line builds need to be set before moving to the next step. Please refer to the [MSDN Page](http://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx).
97d932ffa5SJung-Sang Ahn
98d932ffa5SJung-Sang Ahn`cmake -G "NMake Makefiles" ..\`
99d932ffa5SJung-Sang Ahn
1001e4828d5SJung-Sang Ahn(The default value of `CMAKE_BUILD_TYPE` is `Debug`. If you want to build with optimizations enabled for better performance, type `cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release ../` instead.)
1011e4828d5SJung-Sang Ahn
102d932ffa5SJung-Sang Ahn`nmake all`
103d602442cSChiyoung Seo
104d602442cSChiyoung Seo## Test
105d602442cSChiyoung Seo
106d602442cSChiyoung SeoTo run all the unit tests:
107d602442cSChiyoung Seo
108d932ffa5SJung-Sang Ahn* **Ubuntu**, **Centos**, and **OS X**
109d932ffa5SJung-Sang Ahn
110d932ffa5SJung-Sang Ahn    `make test`
111d932ffa5SJung-Sang Ahn
112d932ffa5SJung-Sang Ahn* **Windows**
113d932ffa5SJung-Sang Ahn
114d932ffa5SJung-Sang Ahn    `nmake test`
115d932ffa5SJung-Sang Ahn
116bdca3052STommie McAfee* To enable code-coverage reporting for tests, install ```gcov``` and ```lcov``` for your OS. (Windows not supported).  Also make sure build type is **Coverage**
1179bdfe182STommie McAfeee
118bdca3052STommie McAfee     `cmake -DCMAKE_BUILD_TYPE=Coverage ../`
1199bdfe182STommie McAfeee
1209bdfe182STommie McAfeee     `make all`
1219bdfe182STommie McAfeee
1229bdfe182STommie McAfeee     `make test_coverage`
1239bdfe182STommie McAfeee
1249bdfe182STommie McAfeee    This target will run the tests and output coverage report to ```<repo>/coverage/index.html```
1258be49e09SSundar Sridharan
1268be49e09SSundar Sridharan* To enable valgrind tests, install ```valgrind``` for your OS. (Windows not supported).  Also make sure build type is **Valgrind**
1278be49e09SSundar Sridharan
1288be49e09SSundar Sridharan     `cmake -DCMAKE_BUILD_TYPE=Valgrind ../`
1298be49e09SSundar Sridharan
1308be49e09SSundar Sridharan     `make all`
1318be49e09SSundar Sridharan
1328be49e09SSundar Sridharan     `make test_valgrind`
1338be49e09SSundar Sridharan
1348be49e09SSundar Sridharan    This target will run the tests and output the memory report to the console
1356d0ca5b7SSundar Sridharan
136ac637abaSSundar Sridharan* By default, every run will produce an additional .lat file which indicates the latencies
137ac637abaSSundar Sridharan  of the forestdb api. This is disabled if CMAKE_BUILD_TYPE=Release
138ac637abaSSundar Sridharan
139dce07a74STommie McAfee* To enable the use of threadsanitizer for tests, install clang 3.5+ (currently only Ubuntu 14.04 is supported).  Also make sure to set flag **CB_THREADSANITIZER**
140dce07a74STommie McAfee
141dce07a74STommie McAfee     `cmake  -DCMAKE_C_COMPILER=clang-3.5 -DCMAKE_CXX_COMPILER=clang++-3.5  -DCB_THREADSANITIZER=1 ..`
142dce07a74STommie McAfee
143dce07a74STommie McAfee     `make all`
144dce07a74STommie McAfee
145dce07a74STommie McAfee     `make test`
146dce07a74STommie McAfee
147dce07a74STommie McAfee     Alternatively you can manually run tests under build/tests/<component>/ for real-time analysis.  When running as standalone it is recommended to include false error suppressions:
148dce07a74STommie McAfee
149dce07a74STommie McAfee     `TSAN_OPTIONS="second_deadlock_stack=1 suppressions=../../../cmake/Modules/tsan.suppressions" ./fdb_functional_test`
150dce07a74STommie McAfee
1516d0ca5b7SSundar Sridharan* For hardware accelerated CRC32C which can improve ForestDB performance, please fetch the optional couchbase platform repository into the forestdb source directory before building.
1526d0ca5b7SSundar Sridharan
153bc44457dSChiyoung Seo     `cd forestdb`
1546d0ca5b7SSundar Sridharan
155bc44457dSChiyoung Seo     `git clone https://github.com/couchbase/platform.git`
1566d0ca5b7SSundar Sridharan
157bc44457dSChiyoung Seo     `Follow the rest of the platform specific build instructions from above`
158