f229a5df2f3bc241f258e56edca891745cdab49c
[libcds.git] / build / cmake / readme.md
1 Building library with CMake
2 ===============
3
4 CDS suports both in-source and out-of-source cmake build types. Now project uses:
5
6 - CMake: general cross-platform building
7 - CTest: all unit tests can be run in a standard way by *ctest* command
8 - CPack: for making rpm/deb/nsys etc. packages
9
10 Compiling and testing
11 ----------
12 **Building out-of-source in "RELEASE" mode ("DEBUG" is default)**
13
14 - Wherever create empty directory for building, for instance *libcds-debug*  
15 - Prepare: *cmake -DCMAKE_BUILD_TYPE=RELEASE <path to the project's root directory with CMakeLists.txt>*
16 - Compile: *make -j4*
17 - As a result you'll see shared and static cds libraries in the build directory
18
19 **Warning**: We strongly recommend not to use static cds library. Static library is not tested and not maintained. You can use it on own risk.
20
21 After using command *cmake -L <path to the project's root directory with CMakeLists.txt>* one can see some additional variables, that can activate additional features:
22
23 - *WITH_TESTS:BOOL=OFF*: if you want to build library with unit testing support use *-DWITH_TESTS=ON* on prepare step. Be careful with this flag, because compile time will dramatically increase
24 - *WITH_TESTS_COVERAGE:BOOL=OFF*: Analyze test coverage using gcov (only for gcc)
25 - *WITH_BOOST_ATOMIC:BOOL=OFF*: Use boost atomics (only for boost >= 1.54)
26 - *WITH_ASAN:BOOL=OFF*: compile libcds with AddressSanitizer instrumentation
27 - *WITH_TSAN:BOOL=OFF*: compile libcds with ThreadSanitizer instrumentation
28
29 Packaging
30 ----------
31
32 In order to package library *CPack* is used, command *cpack -G <Generator>* should create correspondent packages for particular operating system. Now the project supports building the following package types:
33
34 - *RPM*: redhat-based linux distribs        
35 - *DEB*: debian-based linux distribs
36 - *TGZ*: simple "*tgz*" archive with library and headers
37 - *NSYS*: windows installer package (NSYS should be installed)   
38   
39 "Live" building and packaging example
40 ----------
41 - git clone https://github.com/khizmax/libcds.git
42 - mkdir libcds-release
43 - cd libcds-release
44 - cmake -DWITH\_TESTS=ON -DCMAKE\_BUILD_TYPE=RELEASE ../libcds
45 ```
46     -- The C compiler identification is GNU 4.8.3
47     -- The CXX compiler identification is GNU 4.8.3
48     ...
49     -- Found Threads: TRUE
50     -- Boost version: 1.54.0
51     -- Found the following Boost libraries:
52     --   system
53     --   thread
54     Build type -- RELEASE
55     -- Configuring done
56     -- Generating done
57     -- Build files have been written to: <...>/libcds-release
58 ``` 
59 - make -j4
60 ```
61     Scanning dependencies of target cds
62     Scanning dependencies of target test-common
63     Scanning dependencies of target cds-s
64     Scanning dependencies of target test-hdr-offsetof
65     [  1%] Building CXX object CMakeFiles/cds-s.dir/src/hp_gc.cpp.o
66     ...
67     [100%] Built target test-hdr
68     gmake: выход из каталога «/home/kel/projects_cds/libcds-debug»
69 ```
70
71 - ctest
72 ```
73     Test project /home/kel/projects_cds/libcds-debug
74         Start 1: test-hdr
75     1/7 Test #1: test-hdr .........................   Passed  1352.24 sec
76         Start 2: cdsu-misc
77     2/7 Test #2: cdsu-misc ........................   Passed    0.00 sec
78         Start 3: cdsu-map
79     ...
80 ```
81
82 - cpack -G RPM
83 ```
84     CPack: Create package using RPM
85     CPack: Install projects
86     CPack: - Run preinstall target for: cds
87     CPack: - Install project: cds
88     CPack: -   Install component: devel
89     CPack: -   Install component: lib
90     CPack: Create package
91     CPackRPM:Debug: Adding /usr/local to builtin omit list.
92     CPackRPM: Will use GENERATED spec file: /home/kel/projects_cds/libcds-debug/_CPack_Packages/Linux/RPM/SPECS/cds-devel.spec
93     CPackRPM: Will use GENERATED spec file: /home/kel/projects_cds/libcds-debug/_CPack_Packages/Linux/RPM/SPECS/cds-lib.spec
94     CPack: - package: /home/kel/projects_cds/libcds-debug/cds-2.1.0-1-devel.rpm generated.
95     CPack: - package: /home/kel/projects_cds/libcds-debug/cds-2.1.0-1-lib.rpm generated.
96 ```
97
98 Future development
99 ----------
100 - CDash: use CI system