Skip to content

Commit 13cd717

Browse files
committed
WL#5161 : Cross-platform build with CMake
1 parent 411a6bf commit 13cd717

File tree

110 files changed

+6265
-1030
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+6265
-1030
lines changed

BUILD-CMAKE

+243
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
How to Build MySQL server with CMake
2+
3+
WHAT YOU NEED
4+
---------------------------------------------------------------
5+
CMake version 2.6 or later installed on your system.
6+
7+
HOW TO INSTALL:
8+
9+
Linux distributions:
10+
shell> sudo apt-get install cmake
11+
12+
The above works on do Debian/Ubuntu based distributions.On others, command
13+
line needs to be modified to e.g "yum install" on Fedora or "zypper install"
14+
on OpenSUSE.
15+
16+
OpenSolaris:
17+
shell> pfexec pkgadd install SUNWCMake
18+
19+
Windows and Mac OSX:
20+
Download and install the latest distribution from
21+
http://www.cmake.org/cmake/resources/software.html.On Windows, download
22+
installer exe file and run it. On Mac, download the .dmg image and open it.
23+
24+
Other Unixes:
25+
Precompiled packages for other Unix flavors (HPUX, AIX) are available from
26+
http://www.cmake.org/cmake/resources/software.html
27+
28+
Alternatively, you can build from source, source package is also available on
29+
CMake download page.
30+
31+
32+
Compiler Tools
33+
--------------
34+
You will need a working compiler and make utility on your OS.
35+
On Windows, install Visual Studio (Express editions will work too).
36+
On Mac OSX, install Xcode tools.
37+
38+
39+
40+
BUILD
41+
---------------------------------------------------------------
42+
Ensure that compiler and cmake are in PATH.
43+
The following description assumes that current working directory
44+
is the source directory.
45+
46+
47+
- Generic build on Unix, using "Unix Makefiles" generator
48+
49+
shell>cmake .
50+
shell>make
51+
52+
Note: by default, cmake build is less verbose than automake build. Use
53+
"make VERBOSE=1" if you want to see add command lines for each compiled source.
54+
55+
- Windows, using "Visual Studio 9 2008" generator
56+
shell>cmake . -G "Visual Studio 9 2008"
57+
shell>devenv MySQL.sln /build /relwithdebinfo
58+
(alternatively, open MySQL.sln and build using the IDE)
59+
60+
- Windows, using "NMake Makefiles" generator
61+
shell>cmake . -G "NMake Makefiles"
62+
shell>nmake
63+
64+
- Mac OSX build with Xcode
65+
shell>cmake . -G Xcode
66+
shell>xcodebuild -configuration Relwithdebinfo
67+
(alternatively, open MySQL.xcodeproj and build using the IDE)
68+
69+
Command line build with CMake 2.8
70+
After creating project with cmake -G as above, issue
71+
cmake . --build
72+
this works with any CMake generator.
73+
74+
For Visual Studio and Xcode you might want to add an extra
75+
configuration parameter, to avoid building all configurations.
76+
77+
cmake . --build --config Relwithdebinfo
78+
79+
80+
Building "out-of-source"
81+
---------------------------------------------------------------
82+
Building out-of-source provides additional benefits. For example it allows to
83+
build both Release and Debug configurations using the single source tree.Or
84+
build the same source with different version of the same compiler or with
85+
different compilers. Also you will prevent polluting the source tree with the
86+
objects and binaries produced during the make.
87+
88+
Here is an example on how to do it (generic Unix), assuming the source tree is
89+
in directory named src and the current working directory is source root.
90+
91+
shell>mkdir ../build # build directory is called build
92+
shell>cd ../build
93+
shell>cmake ../src
94+
95+
Note: if a directory was used for in-source build, out-of-source will
96+
not work. To reenable out-of-source build, remove <source-root>/CMakeCache.txt
97+
file.
98+
99+
100+
CONFIGURATION PARAMETERS
101+
---------------------------------------------------------------
102+
The procedure above will build with default configuration.
103+
104+
Let's you want to change the configuration parameters and have archive
105+
storage engine compiled into the server instead of building it as pluggable
106+
module.
107+
108+
1)You can provide parameters on the command line, like
109+
110+
shell> cmake . -DWITH_ARCHIVE_STORAGE_ENGINE=1
111+
112+
This can be done during the initial configuration or any time later.
113+
114+
Note, that parameters are "sticky", that is they are remebered in the CMake
115+
cache (CMakeCache.txt file in the build directory)
116+
117+
2) Configuration using cmake-gui (Windows, OSX, or Linux with cmake-gui
118+
installed)
119+
120+
From the build directory, issue
121+
shell> cmake-gui .
122+
123+
- Check the WITH_INNOBASE_STORAGE_ENGINE checkbox
124+
- Click on "Configure" button
125+
- Click on "Generate" button
126+
- Close cmake-gui
127+
shell> make
128+
129+
3)Using ccmake (Unix)
130+
ccmake is curses-based GUI application that provides the same functionality
131+
as cmake-gui. It is less user-friendly compared to cmake-gui but works also
132+
on exotic Unixes like HPUX, AIX or Solaris.
133+
134+
Besides storage engines, probably the most important parameter from a
135+
developer's point of view is WITH_DEBUG (this allows to build server with
136+
dbug tracing library and with debug compile flags).
137+
138+
After changing the configuration, recompile using
139+
shell> make
140+
141+
142+
Listing configuration parameters
143+
---------------------------------------------------------------
144+
shell> cmake -L
145+
146+
Gives a brief overview of important configuration parameters (dump to stdout)
147+
148+
shell> cmake -LH
149+
150+
Does the same but also provides a short help text for each parameter.
151+
152+
shell> cmake -LAH
153+
154+
Dumps all config parameters (including advanced) to the stdout.
155+
156+
PACKAGING
157+
---------------------------------------------------------------
158+
-- Binary distribution --
159+
Packaging in form of tar.gz archives (or .zip on Windows) is also supported
160+
To create a tar.gz package,
161+
162+
1)If you're using "generic" Unix build with makefiles
163+
164+
shell> make package
165+
this will create a tar.gz file in the top level build directory.
166+
167+
2)On Windows, using "NMake Makefiles" generator
168+
169+
shell> nmake package
170+
171+
3)On Windows, using "Visual Studio" generator
172+
173+
shell> devenv mysql.sln /build relwithdebinfo /project package
174+
175+
Note On Windows, 7Zip or Winzip must be installed and 7z.exe rsp winzip.exe
176+
need to be in the PATH.
177+
178+
179+
Another way to build packages is calling cpack executable directly like
180+
shell> cpack -G TGZ --config CPackConfig.cmake
181+
(-G TGZ is for tar.gz generator, there is also -GZIP)
182+
183+
-- Source distribution --
184+
"make dist" target is provided.
185+
186+
ADDITIONAL MAKE TARGETS: "make install" AND "make test"
187+
----------------------------------------------------------------
188+
install target also provided for Makefile based generators. Installation
189+
directory can be controlled using configure-time parameter
190+
CMAKE_INSTALL_PREFIX (default is /usr/local. It is also possible to install to
191+
non-configured directory, using
192+
193+
shell> make install DESTDIR="/some/absolute/path"
194+
195+
"make test" runs unit tests (uses CTest for it)
196+
"make test-force" runs mysql-test-run.pl tests with --test-force parameter
197+
198+
FOR PROGRAMMERS: WRITING PLATFORM CHECKS
199+
--------------------------------------------------------------
200+
If you modify MySQL source and want to add a new platform check,please read
201+
http://www.vtk.org/Wiki/CMake_HowToDoPlatformChecks first. In MySQL, most of
202+
the platform tests are implemented in config.cmake and the template header file
203+
is config.h.cmake
204+
205+
Bigger chunks of functionality, for example non-trivial macros are implemented
206+
in files <src-root>/cmake subdirectory.
207+
208+
For people with autotools background, it is important to remember CMake does
209+
not provide autoheader functionality. That is, when you add a check
210+
211+
CHECK_FUNCTION_EXISTS(foo HAVE_FOO)
212+
to config.cmake, then you will also need to add
213+
#cmakedefine HAVE_FOO 1
214+
to config.h.cmake
215+
216+
Troubleshooting platform checks
217+
--------------------------------
218+
If you suspect that a platform check returned wrong result, examine
219+
<build-root>/CMakeFiles/CMakeError.log and
220+
<build-root>/CMakeFiles/CMakeOutput.log
221+
These files they contain compiler command line, and exact error messages.
222+
223+
Troubleshooting CMake code
224+
----------------------------------
225+
While there are advanced flags for cmake like -debug-trycompile and --trace,
226+
a simple and efficient way to debug to add
227+
MESSAGE("interesting variable=${some_invariable}")
228+
to the interesting places in CMakeLists.txt
229+
230+
231+
Tips:
232+
- When using Makefile generator it is easy to examine which compiler flags are
233+
used to build. For example, compiler flags for mysqld are in
234+
<build-root>/sql/CMakeFiles/mysqld.dir/flags.make and the linker command line
235+
is in <build-root>/sql/CMakeFiles/mysqld.dir/link.txt
236+
237+
- CMake caches results of platform checks in CMakeCache.txt. It is a nice
238+
feature because tests do not rerun when reconfiguring (e.g when a new test was
239+
added).The downside of caching is that when a platform test was wrong and was
240+
later corrected, the cached result is still used. If you encounter this
241+
situation, which should be a rare occation, you need either to remove the
242+
offending entry from CMakeCache.txt (if test was for HAVE_FOO, remove lines
243+
containing HAVE_FOO from CMakeCache.txt) or just remove the cache file.

BUILD/Makefile.am

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
EXTRA_DIST = FINISH.sh \
2121
SETUP.sh \
2222
autorun.sh \
23+
choose_configure.sh \
2324
build_mccge.sh \
2425
check-cpu \
2526
cleanup \

BUILD/autorun.sh

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ do
2020
done
2121
IFS="$save_ifs"
2222

23+
rm -rf configure
2324
aclocal || die "Can't execute aclocal"
2425
autoheader || die "Can't execute autoheader"
2526
# --force means overwrite ltmain.sh script if it already exists
@@ -29,3 +30,9 @@ $LIBTOOLIZE --automake --force --copy || die "Can't execute libtoolize"
2930
# and --force to overwrite them if they already exist
3031
automake --add-missing --force --copy || die "Can't execute automake"
3132
autoconf || die "Can't execute autoconf"
33+
# Do not use autotools generated configure directly. Instead, use a script
34+
# that will either call CMake or original configure shell script at build
35+
# time (CMake is preferred if installed).
36+
mv configure configure.am
37+
cp BUILD/choose_configure.sh configure
38+
chmod a+x configure

BUILD/choose_configure.sh

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
# Choose whether to use autoconf created configure
3+
# of perl script that calls cmake.
4+
5+
# Ensure cmake and perl are there
6+
cmake -P cmake/check_minimal_version.cmake >/dev/null 2>&1 || HAVE_CMAKE=no
7+
perl --version >/dev/null 2>&1 || HAVE_CMAKE=no
8+
if test "$HAVE_CMAKE" = "no"
9+
then
10+
sh ./configure.am $@
11+
else
12+
perl ./cmake/configure.pl $@
13+
fi
14+

0 commit comments

Comments
 (0)