You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

245 lines
8.3 KiB

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