summaryrefslogtreecommitdiff
path: root/BUILD-CMAKE
blob: aedce4400c6e8e70d8af41334143702214ae93b5 (plain)
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
Copyright (c) 2009, 2010 Sun Microsystems, Inc.
Copyright (c) 2012 Monty Program Ab

How to Build MariaDB server with CMake

WHAT YOU NEED
---------------------------------------------------------------
CMake version 2.6 or later installed on your system.

HOW TO INSTALL:

Linux distributions:
shell> sudo apt-get install cmake

The above works on Debian/Ubuntu based distributions. On others, the command
line needs to be modified to e.g "yum install" on Fedora or "zypper install" 
on OpenSUSE.

OpenSolaris:
shell> pfexec pkgadd install SUNWcmake

Windows and Mac OSX:
Download and install the latest distribution from 
http://www.cmake.org/cmake/resources/software.html
On Windows, download installer exe file and run it. On MacOS, download
the .dmg image and open it.

Other Unixes:
Precompiled packages for other Unix flavors (HPUX, AIX) are available from 
http://www.cmake.org/cmake/resources/software.html 

Alternatively, you can build from source, source package is also available on 
CMake download page.


Compiler Tools
--------------
You will need  a working compiler and make utility on your OS. 
On Windows, install Visual Studio (Express editions will work too). 
On Mac OSX, install Xcode tools.



BUILD 
---------------------------------------------------------------
Ensure that compiler and cmake are in PATH.
The following description assumes that current working directory 
is the source directory. 


- Generic build on Unix, using "Unix Makefiles" generator

shell>cmake . 
shell>make

Note: by default, cmake build is less verbose than automake build. Use 
"make VERBOSE=1" if you want to see add command lines for each compiled source.

- Windows, using "Visual Studio 9 2008" generator
shell>cmake . -G "Visual Studio 9 2008" 
shell>devenv MySQL.sln /build /relwithdebinfo
(alternatively, open MySQL.sln and build using the IDE)

- Windows, using "NMake Makefiles" generator
shell>cmake . -G "NMake Makefiles" 
shell>nmake

- Mac OSX build with Xcode
shell>cmake . -G Xcode
shell>xcodebuild -configuration Relwithdebinfo
(alternatively, open MySQL.xcodeproj and build using the IDE)

Command line build with CMake 2.8
After creating project with cmake -G as above, issue
cmake . --build 
this works with any  CMake generator.

For Visual Studio and Xcode you might want to add an extra 
configuration parameter, to avoid building all configurations.

cmake . --build --config Relwithdebinfo


Building "out-of-source"
---------------------------------------------------------------
Building out-of-source provides additional benefits. For example it allows to 
build both Release and Debug configurations using the single source tree.Or 
build the same source with different version of the same compiler or with 
different compilers. Also you will prevent polluting the source tree with the
objects and binaries produced during the make. 

Here is an example on how to do it (generic Unix), assuming the source tree is
in directory named src and the current working directory is source root.

shell>mkdir ../build # build directory is called build
shell>cd ../build
shell>cmake ../src

Note: if a directory was used for in-source build, out-of-source will 
not work. To re-enable out-of-source build, remove <source-root>/CMakeCache.txt
file.


CONFIGURATION PARAMETERS
---------------------------------------------------------------
The procedure above will build with default configuration.

Let's you want to change the  configuration parameters and have archive
storage engine compiled into the server instead of building it as pluggable 
module.

1)You can provide parameters on the command line, like

shell> cmake .  -DWITH_ARCHIVE_STORAGE_ENGINE=1

This can be done during the initial configuration or any time later.

Note, that parameters are "sticky", that is they are remebered in the CMake 
cache (CMakeCache.txt file in the build directory)

2) Configuration using cmake-gui (Windows, OSX, or Linux with cmake-gui 
installed)

From the build directory, issue
shell> cmake-gui .

- Check the WITH_INNOBASE_STORAGE_ENGINE checkbox
- Click on "Configure" button
- Click on "Generate" button
- Close cmake-gui
shell> make

3)Using ccmake (Unix)
ccmake is curses-based GUI application that provides the same functionality 
as cmake-gui. It is less user-friendly compared to cmake-gui but works also 
on exotic Unixes like HPUX, AIX or Solaris.

Besides storage engines, probably the most important parameter from a 
developer's point of view is CMAKE_BUILD_TYPE (this allows to build server with 
dbug tracing library and with debug compile flags).

After changing the configuration, recompile using
shell> make


Listing configuration parameters
---------------------------------------------------------------
shell> cmake -L 

Gives a brief overview of important configuration parameters (dump to stdout)

shell> cmake -LH

Does the same but also provides a short help text for each parameter.

shell> cmake -LAH 

Dumps all config parameters (including advanced) to the stdout.

PACKAGING
---------------------------------------------------------------
-- Binary distribution --
Packaging in form of tar.gz archives (or .zip on Windows) is also supported
To create a tar.gz package, 

1)If you're using "generic" Unix build with makefiles

shell> make package
this will create a tar.gz file in the top level build directory.

2)On Windows, using  "NMake Makefiles" generator

shell> nmake package

3)On Windows, using "Visual Studio"  generator

shell> devenv mysql.sln /build relwithdebinfo /project package

Note On Windows, 7Zip or Winzip must be installed and 7z.exe rsp winzip.exe 
need to be in the PATH.


Another way to build packages is calling cpack executable directly like
shell> cpack -G TGZ --config CPackConfig.cmake
(-G TGZ is for tar.gz generator, there is also -GZIP)

-- Source distribution --
"make dist" target is provided. 

ADDITIONAL MAKE TARGETS: "make install" AND "make test"
----------------------------------------------------------------
install target also provided for Makefile based generators. Installation 
directory can be controlled using configure-time parameter 
CMAKE_INSTALL_PREFIX (default is /usr/local. It is also possible to install to
non-configured directory, using

shell> make install DESTDIR="/some/absolute/path"

"make test" runs unit tests (uses CTest for it)
"make test-force" runs mysql-test-run.pl tests with --test-force parameter

FOR PROGRAMMERS: WRITING PLATFORM CHECKS
--------------------------------------------------------------
If you modify MySQL source and want to add a new platform check,please read 
http://www.vtk.org/Wiki/CMake_HowToDoPlatformChecks first. In MySQL, most of 
the platform tests are implemented in configure.cmake and the template header 
file is config.h.cmake

Bigger chunks of functionality, for example non-trivial macros are implemented 
in files <src-root>/cmake subdirectory.

For people with autotools background, it is important to remember CMake does 
not provide autoheader functionality. That is, when you add a check

CHECK_FUNCTION_EXISTS(foo HAVE_FOO)
to config.cmake, then you will also need to add
#cmakedefine HAVE_FOO 1
to config.h.cmake

Troubleshooting platform checks
--------------------------------
If you suspect that a platform check returned wrong result, examine 
<build-root>/CMakeFiles/CMakeError.log and 
<build-root>/CMakeFiles/CMakeOutput.log
These files they contain compiler command line, and exact error messages.

Troubleshooting CMake code
----------------------------------
While there are advanced flags for cmake like -debug-trycompile and --trace,
a simple and efficient way to debug to add 
MESSAGE("interesting variable=${some_invariable}")
to the interesting places in CMakeLists.txt


Tips:
- When using Makefile generator it is easy to examine which compiler flags are 
used to build. For example, compiler flags for mysqld are in 
<build-root>/sql/CMakeFiles/mysqld.dir/flags.make and the linker command line
is in <build-root>/sql/CMakeFiles/mysqld.dir/link.txt

- CMake caches results of platform checks in CMakeCache.txt. It is a nice 
feature because tests do not rerun when reconfiguring (e.g when a new test was 
added).The downside of caching is that when a platform test was wrong and was 
later corrected, the cached result is still used. If you encounter this 
situation,  which should be a rare occation, you need either to remove the 
offending entry from CMakeCache.txt (if test was for HAVE_FOO, remove lines 
containing HAVE_FOO from CMakeCache.txt) or just remove the cache file.