diff --git a/CMakeLists.txt b/CMakeLists.txt index 0b0e32405..a2604c114 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,22 +69,14 @@ if(CMAKE_VERSION VERSION_GREATER 2.6) endif() endif() -if(BUILD_TYPE STREQUAL Debug) +if(CMAKE_BUILD_TYPE STREQUAL Debug) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEBUG_FLAGS} -DSS_DEBUG") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEBUG_FLAGS} -DSS_DEBUG") message(STATUS "Generating debugging symbols and enabling debugging code") -elseif(BUILD_TYPE STREQUAL DebugSymbols) +elseif(CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${DEBUG_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DEBUG_FLAGS}") message(STATUS "Generating debugging symbols") -elseif(BUILD_TYPE MATCHES Optimized) - if(NOT (DEFINED OLEVEL)) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O2") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O2") - message(STATUS "Optimization level at: 2") - endif() -else() - endif() if(DEFINED OLEVEL ) @@ -157,7 +149,7 @@ install(FILES ${CMAKE_SOURCE_DIR}/LICENSE DESTINATION .) install(DIRECTORY DESTINATION log) # Install startup scripts and ldconfig files -if( NOT ( (DEFINED INSTALL_SYSTEM_FILES) AND ( NOT ( INSTALL_SYSTEM_FILES ) ) ) ) +if(WITH_SCRIPTS) configure_file(${CMAKE_SOURCE_DIR}/maxscale.conf.in ${CMAKE_BINARY_DIR}/maxscale.conf @ONLY) if(DEB_BASED) configure_file(${CMAKE_SOURCE_DIR}/etc/ubuntu/init.d/maxscale.in ${CMAKE_BINARY_DIR}/maxscale @ONLY) @@ -233,20 +225,20 @@ if(PACKAGE) endif() add_custom_target(buildtests - COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DBUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DINSTALL_SYSTEM_FILES=N ${CMAKE_SOURCE_DIR} + COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DWITH_SCRIPTS=N ${CMAKE_SOURCE_DIR} COMMAND make COMMENT "Building test suite..." VERBATIM ) add_custom_target(testall - COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DBUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DINSTALL_SYSTEM_FILES=N ${CMAKE_SOURCE_DIR} + COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DWITH_SCRIPTS=N ${CMAKE_SOURCE_DIR} COMMAND make install COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/server/test/MaxScale_test.cnf ${CMAKE_BINARY_DIR}/etc/MaxScale.cnf COMMAND ${CMAKE_COMMAND} -P ${CMAKE_SOURCE_DIR}/cmake/testall.cmake COMMENT "Running full test suite..." VERBATIM) add_custom_target(testcore - COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DBUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DINSTALL_SYSTEM_FILES=N ${CMAKE_SOURCE_DIR} + COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DWITH_SCRIPTS=N ${CMAKE_SOURCE_DIR} COMMAND make install COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/server/test/MaxScale_test.cnf ${CMAKE_BINARY_DIR}/etc/MaxScale.cnf COMMAND ctest -R Internal @@ -278,7 +270,7 @@ endif() # Testall target with Valgrind if(VALGRIND_FOUND) add_custom_target(testall-valgrind - COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DBUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DINSTALL_SYSTEM_FILES=N ${CMAKE_SOURCE_DIR} + COMMAND ${CMAKE_COMMAND} -DDEPS_OK=Y -DBUILD_TESTS=Y -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR} -DWITH_SCRIPTS=N ${CMAKE_SOURCE_DIR} COMMAND make install COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_SOURCE_DIR}/server/test/MaxScale_test.cnf ${CMAKE_BINARY_DIR}/etc/MaxScale.cnf COMMAND /bin/sh -c "valgrind --track-fds=yes --leak-check=full --show-leak-kinds=all --log-file=${CMAKE_BINARY_DIR}/valgrind.log ${CMAKE_BINARY_DIR}/bin/maxscale -c ${CMAKE_BINARY_DIR} &>/dev/null" diff --git a/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md b/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md index f95d2de9a..b5f43a658 100644 --- a/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md +++ b/Documentation/Getting-Started/Building-MaxScale-from-Source-Code.md @@ -12,87 +12,126 @@ You will need a number of tools and libraries in order to achieve this. * libedit 2.11 or later (used by the MaxAdmin tool) -The full list of dependencies for the most common distros is provided in the next section. +## Build dependencied + +The full list of dependencies for the most common distributions is provided in this section. If your system is not listed here, MaxScale building isn't guaranteed to be compatible but might still be successful. + +### All RHEL, CentOS and Fedora versions + +``` +gcc gcc-c++ ncurses-devel bison glibc-devel cmake libgcc perl make libtool +openssl-devel libaio libaio-devel librabbitmq-devel +``` -### All RHEL, CentOS and Fedora versions: - gcc gcc-c++ ncurses-devel bison glibc-devel cmake libgcc perl make libtool - openssl-devel libaio libaio-devel librabbitmq-devel In addition, if you wish to to build an RPM package include: +``` rpm-build - +``` + #### RHEL 6, 7, CentOS 6, 7, Fedora: - libedit-devel + +``` +libedit-devel +``` #### RHEL 7, CentOS 7: - mariadb-devel mariadb-embedded-devel + +``` +mariadb-devel mariadb-embedded-devel +``` #### RHEL 5, 7, CentOS 5, 6, Fedora 19, 20 - MariaDB-devel MariaDB-server +MariaDB-devel MariaDB-server #### Fedora 19, 20 - systemtap-sdt-devel -### All Ubuntu and Debian versions: +``` +systemtap-sdt-devel +``` + +### All Ubuntu and Debian versions + +``` build-essential libssl-dev libaio-dev ncurses-dev bison cmake perl libtool librabbitmq-dev +``` + If you want to build a DEB package, you will also need: +``` dpkg-dev +``` #### Ubuntu 14.04 or later, Debian 8 (Jessie) or later + +``` libmariadbclient-dev libmariadbd-dev +``` #### Earlier versions of Ubuntu or Debian For these, you will need to obtain the MariaDB embedded library. It has to be manually extracted from the tarball. But first ascertain what version of glibc is installed. Run the command: +``` dpkg -l | grep libc6 +``` + which will show the version number. If the version is less than 2.14 you should obtain the library from: [https://downloads.mariadb.org/interstitial/mariadb-5.5.41/bintar-linux-x86_64/mariadb-5.5.41-linux-x86_64.tar.gz](https://downloads.mariadb.org/interstitial/mariadb-5.5.41/bintar-linux-x86_64/mariadb-5.5.41-linux-x86_64.tar.gz). Otherwise, from: [https://downloads.mariadb.org/interstitial/mariadb-5.5.41/bintar-linux-glibc_214-x86_64/mariadb-5.5.41-linux-glibc_214-x86_64.tar.gz](https://downloads.mariadb.org/interstitial/mariadb-5.5.41/bintar-linux-glibc_214-x86_64/mariadb-5.5.41-linux-glibc_214-x86_64.tar.gz) -The suggested location for extracting the tarball is /usr so the operation can be done by the following commands: +The suggested location for extracting the tarball is `/usr` so the operation can be done by the following commands: +``` cd /usr tar -xzvf /path/to/mariadb.library.tar.gz +``` + where /path/to/mariadb.library.tar.gz is replaced by the actual path and name of the downloaded tarball. ### OpenSUSE -(mariadb-devel package, build fails????) +At the time this guide was written, the MariaDB development packages for OpenSUSE were broken and the build failed. The packages required are: - gcc gcc-c++ ncurses-devel bison glibc-devel cmake libgcc_s1 perl - make libtool libopenssl-devel libaio libaio-devel - libedit-devel librabbitmq-devel +``` +gcc gcc-c++ ncurses-devel bison glibc-devel cmake libgcc_s1 perl +make libtool libopenssl-devel libaio libaio-devel +libedit-devel librabbitmq-devel MariaDB-devel MariaDB-client MariaDB-server -(if zypper ask which MariaDB client should be installed 'MariaDB-client' or 'mariadb-client' - please select 'MariaDB-client') +``` +If zypper ask which MariaDB client should be installed `MariaDB-client` or `mariadb-client` + please select `MariaDB-client`. This is the package provided by the MariaDB repository. ##Obtaining the MaxScale Source Code + Now clone the GitHub project to your machine either via the web interface, your favorite graphical interface or the git command line - $ git clone https://github.com/mariadb-corporation/MaxScale - Cloning into 'MaxScale'... - remote: Counting objects: 16228, done. - ... +``` +$ git clone https://github.com/mariadb-corporation/MaxScale +Cloning into 'MaxScale'... +remote: Counting objects: 16228, done. +... +``` -Change directory to the MaxScale directory, create a build directory and change directory to that build directory +Change directory to the `MaxScale` directory, create a build directory and change directory to that build directory + +``` +$ cd MaxScale +$ mkdir build +$ cd build +``` - $ cd MaxScale - $ mkdir build - $ cd build - The next step is to run the cmake command to build the Makefile you need to compile Maxscale. There are a number of options you may give to configure cmake and point it to the various packages it requires. In this example we will assume the MariaDB developer packages have been installed as described above and set all the options required to locate these, along with options to build the unit tests and configure the installation target directory. If you run into any trouble while configuring CMake, you can always remove the -'CMakeCache.txt' file to clear CMake's internal cache. This resets all values to their -defaults and can be used to fix a 'stuck' configuration of CMake. This is also a good -reason why you should always build into a separate directory, because you can safely +`CMakeCache.txt` file to clear CMake's internal cache. This resets all values to their +defaults and can be used quickly force a reconfiguration of CMake variables. There is also a make target, `make rebuild_cache`, that cleans the CMake cache. +This is also a good reason why you should always build into a separate directory, because you can safely wipe the build directory clean without the danger of deleting important files when something goes wrong. Building 'out-of-source' also allows you to have multiple configurations of MaxScale at the same time. @@ -103,88 +142,96 @@ variables manually at configuration time. To display all CMake variables with their descriptions: - cmake -LH +``` +cmake -LH +``` When you are ready to run cmake: - $ cmake -DMYSQL\_DIR=/usr/mariadb-5.5.41-linux-x86_64/include/mysql \ - -DEMBEDDED\_LIB=/usr/mariadb-5.5.41-linux-x86\_64/lib/libmysqld.a \ - -DMYSQLCLIENT\_LIBRARIES=/usr/mariadb-5.5.41-linux-x86_64/lib/libmysqlclient.so \ - -DERRMSG=/usr/mariadb-5.5.41-linux-x86\_64/share/english/errmsg.sys \ - -DINSTALL\_DIR=/home/maxscale/MaxScale -DBUILD_TESTS=Y \ - -DINSTALL\_SYSTEM\_FILES=N \ - -DBUILD_BINLOG=Y .. -DBUILD_RABBITMQ=N/ - +``` +$ cmake -DMYSQL_DIR=/usr/mariadb-5.5.41-linux-x86_64/include/mysql \ +-DEMBEDDED_LIB=/usr/mariadb-5.5.41-linux-x86_64/lib/libmysqld.a \ +-DMYSQLCLIENT_LIBRARIES=/usr/mariadb-5.5.41-linux-x86_64/lib/libmysqlclient.so \ +-DERRMSG=/usr/mariadb-5.5.41-linux-x86_64/share/english/errmsg.sys \ +-DCMAKE_INSTALL_PREFIX=/home/maxscale/MaxScale -DBUILD_TESTS=Y \ +-DWITH_SCRIPTS=N +
-    -- CMake version: 2.8.12.2
-    -- The C compiler identification is GNU 4.4.7
-    -- The CXX compiler identification is GNU 4.4.7
-    -- Check for working C compiler: /usr/bin/cc
-    -- Check for working C compiler: /usr/bin/cc -- works
-    -- Detecting C compiler ABI info
-    -- Detecting C compiler ABI info - done
-    -- Check for working CXX compiler: /usr/bin/c++
-    -- Check for working CXX compiler: /usr/bin/c++ -- works
-    -- Detecting CXX compiler ABI info
-    -- Detecting CXX compiler ABI info - done
-    -- Library was found at: /lib64/libaio.so
-    -- Library was found at: /usr/lib64/libssl.so
-    -- Library was found at: /usr/lib64/libcrypt.so
-    -- Library was found at: /usr/lib64/libcrypto.so
-    -- Library was found at: /usr/lib64/libz.so
-    -- Library was found at: /usr/lib64/libm.so
-    -- Library was found at: /usr/lib64/libdl.so
-    -- Library was found at: /usr/lib64/librt.so
-    -- Library was found at: /usr/lib64/libpthread.so
-    -- Using errmsg.sys found at: /home/maxscale/usr/share/mysql/english/errmsg.sys
-    -- Using embedded library: /home/mpinto/usr/lib64/libmysqld.a
-    -- Valgrind found: /usr/bin/valgrind
-    -- Found dynamic MySQL client library: /home/maxscale/usr/lib64/libmysqlclient.so
-    -- Found static MySQL client library: /usr/lib/libmysqlclient.a
-    -- C Compiler supports: -Werror=format-security
-    -- Linking against: /home/mpinto/usr/lib64/libmysqlclient.so
-    -- Installing MaxScale to: /usr/local/maxscale/
-    -- Generating RPM packages
-    -- Found Doxygen: /usr/bin/doxygen (found version "1.6.1") 
-    -- Configuring done
-    -- Generating done
-    -- Build files have been written to: /home/maxscale/develop/build
+-- CMake version: 2.8.12.2
+-- The C compiler identification is GNU 4.4.7
+-- The CXX compiler identification is GNU 4.4.7
+-- Check for working C compiler: /usr/bin/cc
+-- Check for working C compiler: /usr/bin/cc -- works
+-- Detecting C compiler ABI info
+-- Detecting C compiler ABI info - done
+-- Check for working CXX compiler: /usr/bin/c++
+-- Check for working CXX compiler: /usr/bin/c++ -- works
+-- Detecting CXX compiler ABI info
+-- Detecting CXX compiler ABI info - done
+-- Library was found at: /lib64/libaio.so
+-- Library was found at: /usr/lib64/libssl.so
+-- Library was found at: /usr/lib64/libcrypt.so
+-- Library was found at: /usr/lib64/libcrypto.so
+-- Library was found at: /usr/lib64/libz.so
+-- Library was found at: /usr/lib64/libm.so
+-- Library was found at: /usr/lib64/libdl.so
+-- Library was found at: /usr/lib64/librt.so
+-- Library was found at: /usr/lib64/libpthread.so
+-- Using errmsg.sys found at: /home/maxscale/usr/share/mysql/english/errmsg.sys
+-- Using embedded library: /home/mpinto/usr/lib64/libmysqld.a
+-- Valgrind found: /usr/bin/valgrind
+-- Found dynamic MySQL client library: /home/maxscale/usr/lib64/libmysqlclient.so
+-- Found static MySQL client library: /usr/lib/libmysqlclient.a
+-- C Compiler supports: -Werror=format-security
+-- Linking against: /home/mpinto/usr/lib64/libmysqlclient.so
+-- Installing MaxScale to: /usr/local/maxscale/
+-- Generating RPM packages
+-- Found Doxygen: /usr/bin/doxygen (found version "1.6.1") 
+-- Configuring done
+-- Generating done
+-- Build files have been written to: /home/maxscale/develop/build
+```
 
 Once the cmake command is complete simply run make to build the MaxScale binaries.
 
-    $ make
-  
+```
+$ make
+
 
-    **Scanning dependencies of target utils**
-    [  1%] Building CXX object utils/CMakeFiles/utils.dir/skygw_utils.cc.o
-    **Linking CXX static library libutils.a**
-    [  1%] Built target utils
-    **Scanning dependencies of target log_manager**
-    [  2%] Building CXX object log_manager/CMakeFiles/log_manager.dir/log_manager.cc.o
-    ...
+**Scanning dependencies of target utils**
+[  1%] Building CXX object utils/CMakeFiles/utils.dir/skygw_utils.cc.o
+**Linking CXX static library libutils.a**
+[  1%] Built target utils
+**Scanning dependencies of target log_manager**
+[  2%] Building CXX object log_manager/CMakeFiles/log_manager.dir/log_manager.cc.o
+...
 
+``` After the completion of the make process the installation can be achieved by running the make install target. - $ make install - ... +``` +$ make install +... +``` -This will result in an installation being created which is identical to that which would be achieved by installing the binary package. The only difference is that init.d scripts aren't installed and the RabbitMQ components are not built. +This will result in an installation being created which is identical to that which would be achieved by installing the binary package. The only difference is that init.d scripts aren't installed. -By default, MaxScale installs to '/usr/local/mariadb-maxscale' and places init.d scripts and ldconfig files into their folders. Change the CMAKE_INSTALL_PREFIX variable to your desired installation directory and set INSTALL_SYSTEM_FILES=N to prevent the init.d script and ldconfig file installation. +By default, MaxScale installs to `/usr/local/mariadb-maxscale` and places init.d scripts and ldconfig files into their folders. Change the `CMAKE_INSTALL_PREFIX` variable to your desired installation directory and set `WITH_SCRIPTS=N` to prevent the init.d script and ldconfig file installation. Other useful targets for Make are `documentation`, which generates the Doxygen documentation, and `uninstall` which uninstall MaxScale binaries after an install. ## Running the MaxScale testsuite -To run "make testall" you need to have four mysqld servers running on localhost. It assumes a master-slave replication setup with one slave and three slaves. +MaxScale has a core test suite for internal components and an extended suite of test for modules. To run the core tests, run `make testcore`. This will test the core maxscale executable. -The ports to which these servers are listening and the credentials to use for testing - can be specified in the 'macros.cmake' file. +To run `make testall`, the full test suite, you need to have four mysqld servers running on localhost. It assumes a master-slave replication setup with one slave and three slaves. -On the master full privileges on the databases "test" and "FOO" are needed, on the saves SELECT permissions on test.* should be sufficient. +The ports to which these servers are listening and the credentials to use for testing can be specified in the `macros.cmake` file found in the root source folder. -When you run the 'make testall' target after configuring the build with CMake a local version of MaxScale is installed into the build folder. After this a MaxScale instance is started and the test set is executed. +On the master full privileges on the databases `test` are needed, on the slaves `SELECT` permissions on `test.*` should be sufficient. -After testing has finished you can find a full testlog generated by CTest in Testing/Temporary/ directory and MaxScale's log files in the log/ directory of the build root. +When you run the `make testall` target after configuring the build with CMake a local version of MaxScale is installed into the build folder. After this a MaxScale instance is started and the test set is executed. + +After testing has finished you can find a full testlog generated by CTest in `Testing/Temporary/` directory and MaxScale's log files in the `log/` directory of the build root. diff --git a/macros.cmake b/macros.cmake index c9abffd2b..63bbd23d3 100644 --- a/macros.cmake +++ b/macros.cmake @@ -17,9 +17,6 @@ macro(set_maxscale_version) endmacro() macro(set_variables) - - # Build type - set(BUILD_TYPE "None" CACHE STRING "Build type, possible values are:None, Debug, DebugSymbols, Optimized.") # hostname or IP address of MaxScale's host set(TEST_HOST "127.0.0.1" CACHE STRING "hostname or IP address of MaxScale's host") @@ -61,7 +58,7 @@ macro(set_variables) set(GCOV FALSE CACHE BOOL "Use gcov build flags") # Install init.d scripts and ldconf configuration files - set(INSTALL_SYSTEM_FILES TRUE CACHE BOOL "Install init.d scripts and ldconf configuration files") + set(WITH_SCRIPTS TRUE CACHE BOOL "Install init.d scripts and ldconf configuration files") # Build tests set(BUILD_TESTS FALSE CACHE BOOL "Build tests")