2018-03-06 14:00:39 +08:00
# $%BEGINLICENSE%$
# Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 2 of the
# License.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
#
# $%ENDLICENSE%$
PROJECT ( cetus C )
SET ( CMAKE_MODULE_PATH ${ CMAKE_SOURCE_DIR } /cmake )
2018-03-28 15:40:00 +08:00
CMAKE_MINIMUM_REQUIRED ( VERSION 2.8.11 )
2018-03-06 14:00:39 +08:00
INCLUDE ( CheckIncludeFiles )
INCLUDE ( CheckFunctionExists )
INCLUDE ( CheckLibraryExists )
INCLUDE ( FindPkgConfig )
INCLUDE ( CheckTypeSize )
INCLUDE ( ChassisPlugin )
INCLUDE ( ChassisInstall )
INCLUDE ( CTest )
INCLUDE ( Tar )
ENABLE_TESTING ( )
set ( CETUS_TOOLS_DIR ${ PROJECT_SOURCE_DIR } /tools )
OPTION ( ENABLE_GCOV "Enable gcov (debug, Linux builds only)" OFF )
IF ( ENABLE_GCOV AND NOT WIN32 AND NOT APPLE )
MESSAGE ( STATUS "***************building gcov version*************" )
SET ( CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage" )
SET ( CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fprofile-arcs -ftest-coverage" )
SET ( CMAKE_EXE_LINKER_FLAGS_DEBUG
" $ { C M A K E _ E X E _ L I N K E R _ F L A G S _ D E B U G } - f p r o f i l e - a r c s - f t e s t - c o v e r a g e - l g c o v " )
ENDIF ( )
2018-03-12 15:52:54 +08:00
option ( SIMPLE_PARSER "use the simple parser" )
2018-03-06 14:00:39 +08:00
option ( NETWORK_DEBUG_TRACE_IO "if NETWORK_DEBUG_TRACE_IO is defined, the network layer will log the raw MySQL packets as log-level debug" )
option ( NETWORK_DEBUG_TRACE_EVENT "if NETWORK_DEBUG_TRACE_EVENT is defined, cetus will log the abnormal event" )
option ( NETWORK_DEBUG_TRACE_STATE_CHANGES "if NETWORK_DEBUG_TRACE_STATE_CHANGES is defined the state engine for the mysql protocol will log all state changes" )
option ( USE_GLIB_DEBUG_LOG "g_debug() is default defined to nothing, change to ON if you want to use g_debug()" )
EXECUTE_PROCESS ( COMMAND git describe --tags
T I M E O U T 5
O U T P U T _ V A R I A B L E G I T _ R E V I S I O N
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
MESSAGE ( STATUS "building from ${GIT_REVISION}" )
2018-04-17 11:43:20 +08:00
SET ( CPACK_PACKAGE_VERSION_MAJOR "1" )
2018-07-31 15:21:45 +08:00
SET ( CPACK_PACKAGE_VERSION_MINOR "1" )
2018-04-17 11:43:20 +08:00
SET ( CPACK_PACKAGE_VERSION_PATCH "0" )
2018-03-06 14:00:39 +08:00
SET ( CPACK_PACKAGE_VENDOR "MySQL" )
SET ( PACKAGE_NAME cetus )
## SET(CPACK_*) before the INCLUDE(CPack)
INCLUDE ( CPack )
MESSAGE ( STATUS "gthread at libs:${GTHREAD_LIBRARY_DIRS} incl:${GTHREAD_INCLUDE_DIRS}" )
MESSAGE ( STATUS "gmodule at libs:${GMODULE_LIBRARY_DIRS} incl:${GMODULE_INCLUDE_DIRS}" )
## if the paths are not set, use pkg-config to fetch them
IF ( NOT GLIB_DEV_BASE_DIR )
2018-04-04 15:19:12 +08:00
SET ( GMODULE_INCLUDE_DIRS CACHE PATH "gmodule-2.0 include dir [see pkg-config gmodule-2.0 --cflags]" )
SET ( GMODULE_LIBRARY_DIRS CACHE PATH "gmodule-2.0 library dir [see pkg-config gmodule-2.0 --libs]" )
SET ( GTHREAD_INCLUDE_DIRS CACHE PATH "gthread-2.0 include dir [see pkg-config gthread-2.0 --cflags]" )
SET ( GTHREAD_LIBRARY_DIRS CACHE PATH "gthread-2.0 library dir [see pkg-config gthread-2.0 --libs]" )
2018-03-06 14:00:39 +08:00
ENDIF ( NOT GLIB_DEV_BASE_DIR )
SET ( MYSQL_INCLUDE_DIRS CACHE PATH "MySQL include dir" )
SET ( MYSQL_LIBRARY_DIRS CACHE PATH "MySQL library dir" )
MESSAGE ( STATUS "glib2.0 at libs:${GLIB_LIBRARY_DIRS} incl:${GLIB_INCLUDE_DIRS}" )
MESSAGE ( STATUS "gthread at libs:${GTHREAD_LIBRARY_DIRS} incl:${GTHREAD_INCLUDE_DIRS}" )
MESSAGE ( STATUS "gmodule at libs:${GMODULE_LIBRARY_DIRS} incl:${GMODULE_INCLUDE_DIRS}" )
IF ( NOT GLIB_INCLUDE_DIRS )
2018-04-04 15:19:12 +08:00
SET ( __pkg_config_checked_GLIB 0 )
PKG_CHECK_MODULES ( GLIB REQUIRED glib-2.0>=2.28 )
ADD_DEFINITIONS ( -DHAVE_GLIB )
2018-03-06 14:00:39 +08:00
ENDIF ( NOT GLIB_INCLUDE_DIRS )
IF ( NOT GMODULE_INCLUDE_DIRS )
2018-04-04 15:19:12 +08:00
PKG_CHECK_MODULES ( GMODULE REQUIRED gmodule-2.0>=2.28 )
ADD_DEFINITIONS ( -DHAVE_GMODULE )
2018-03-06 14:00:39 +08:00
ENDIF ( NOT GMODULE_INCLUDE_DIRS )
IF ( NOT GTHREAD_INCLUDE_DIRS )
2018-04-04 15:19:12 +08:00
PKG_CHECK_MODULES ( GTHREAD REQUIRED gthread-2.0>=2.28 )
2018-03-06 14:00:39 +08:00
ENDIF ( NOT GTHREAD_INCLUDE_DIRS )
MACRO ( _mysql_config VAR _regex _opt )
2018-04-04 15:19:12 +08:00
EXECUTE_PROCESS ( COMMAND ${ MYSQL_CONFIG_EXECUTABLE } ${ _opt }
O U T P U T _ V A R I A B L E _ m y s q l _ c o n f i g _ o u t p u t
)
SET ( _var ${ _mysql_config_output } )
STRING ( REGEX MATCHALL "${_regex}([^ ]+)" _mysql_config_output "${_mysql_config_output}" )
STRING ( REGEX REPLACE "^[ \t]+" "" _mysql_config_output "${_mysql_config_output}" )
STRING ( REGEX REPLACE "[\r\n]$" "" _mysql_config_output "${_mysql_config_output}" )
STRING ( REGEX REPLACE "${_regex}" "" _mysql_config_output "${_mysql_config_output}" )
SEPARATE_ARGUMENTS ( _mysql_config_output )
SET ( ${ VAR } ${ _mysql_config_output } )
2018-03-06 14:00:39 +08:00
ENDMACRO ( _mysql_config _regex _opt )
IF ( NOT MYSQL_INCLUDE_DIRS )
2018-04-04 15:19:12 +08:00
FIND_PROGRAM ( MYSQL_CONFIG_EXECUTABLE NAMES mysql_config DOC "full path of mysql_config" )
IF ( NOT MYSQL_CONFIG_EXECUTABLE )
MESSAGE ( SEND_ERROR "mysql_config wasn't found, -DMYSQL_CONFIG_EXECUTABLE=..." )
ENDIF ( NOT MYSQL_CONFIG_EXECUTABLE )
_MYSQL_CONFIG ( MYSQL_INCLUDE_DIRS "(^| )-I" "--include" )
_MYSQL_CONFIG ( MYSQL_LIBRARIES "(^| )-l" "--libs" )
_MYSQL_CONFIG ( MYSQL_LIBRARY_DIRS "(^| )-L" "--libs" )
2018-03-06 14:00:39 +08:00
ELSE ( NOT MYSQL_INCLUDE_DIRS )
2018-04-04 15:19:12 +08:00
SET ( MYSQL_LIBRARIES libmysql )
2018-03-06 14:00:39 +08:00
ENDIF ( NOT MYSQL_INCLUDE_DIRS )
SET ( CMAKE_REQUIRED_INCLUDES
2018-04-04 15:19:12 +08:00
$ { M Y S Q L _ I N C L U D E _ D I R S }
$ { G L I B _ I N C L U D E _ D I R S }
$ { G T H R E A D _ I N C L U D E _ D I R S }
2018-03-06 14:00:39 +08:00
)
MESSAGE ( STATUS "checking in dirs: ${CMAKE_REQUIRED_INCLUDES}" )
CHECK_INCLUDE_FILES ( inttypes.h HAVE_INTTYPES_H )
CHECK_INCLUDE_FILES ( netinet/in.h HAVE_NETINET_IN_H )
CHECK_INCLUDE_FILES ( net/if.h HAVE_NET_IF_H )
CHECK_INCLUDE_FILES ( net/if_dl.h HAVE_NET_IF_DL_H )
CHECK_INCLUDE_FILES ( stddef.h HAVE_STDDEF_H )
CHECK_INCLUDE_FILES ( stdint.h HAVE_STDINT_H )
CHECK_INCLUDE_FILES ( stdlib.h HAVE_STDLIB_H )
CHECK_INCLUDE_FILES ( signal.h HAVE_SIGNAL_H )
CHECK_INCLUDE_FILES ( syslog.h HAVE_SYSLOG_H )
CHECK_INCLUDE_FILES ( sys/filio.h HAVE_SYS_FILIO_H )
CHECK_INCLUDE_FILES ( sys/ioctl.h HAVE_SYS_IOCTL_H )
CHECK_INCLUDE_FILES ( sys/param.h HAVE_SYS_PARAM_H )
CHECK_INCLUDE_FILES ( sys/resource.h HAVE_SYS_RESOURCE_H )
CHECK_INCLUDE_FILES ( sys/socket.h HAVE_SYS_SOCKET_H )
CHECK_INCLUDE_FILES ( sys/sockio.h HAVE_SYS_SOCKIO_H )
CHECK_INCLUDE_FILES ( sys/time.h HAVE_SYS_TIME_H )
CHECK_INCLUDE_FILES ( sys/types.h HAVE_SYS_TYPES_H )
CHECK_INCLUDE_FILES ( sys/uio.h HAVE_SYS_UIO_H )
CHECK_INCLUDE_FILES ( sys/un.h HAVE_SYS_UN_H )
CHECK_INCLUDE_FILES ( time.h HAVE_TIME_H )
CHECK_INCLUDE_FILES ( unistd.h HAVE_UNISTD_H )
CHECK_INCLUDE_FILES ( mysql.h HAVE_MYSQL_H )
CHECK_INCLUDE_FILES ( glib.h HAVE_GLIB_H )
2018-03-23 10:46:44 +08:00
CHECK_INCLUDE_FILES ( zlib.h HAVE_ZLIB_H )
2018-03-06 14:00:39 +08:00
CHECK_INCLUDE_FILES ( glib/gthread.h HAVE_GTHREAD_H )
CHECK_INCLUDE_FILES ( pwd.h HAVE_PWD_H )
CHECK_FUNCTION_EXISTS ( inet_ntop HAVE_INET_NTOP )
CHECK_FUNCTION_EXISTS ( getcwd HAVE_GETCWD )
CHECK_FUNCTION_EXISTS ( signal HAVE_SIGNAL )
CHECK_FUNCTION_EXISTS ( strerror HAVE_STRERROR )
CHECK_FUNCTION_EXISTS ( srandom HAVE_SRANDOM )
CHECK_FUNCTION_EXISTS ( writev HAVE_WRITEV )
CHECK_FUNCTION_EXISTS ( sigaction HAVE_SIGACTION )
CHECK_FUNCTION_EXISTS ( getaddrinfo HAVE_GETADDRINFO )
# check for gthread actually being present
CHECK_LIBRARY_EXISTS ( gthread-2.0 g_thread_init "${GTHREAD_LIBRARY_DIRS}" HAVE_GTHREAD )
2018-04-04 15:19:12 +08:00
CHECK_LIBRARY_EXISTS ( tcmalloc malloc "" HAVE_TCMALLOC )
2018-03-06 14:00:39 +08:00
#SET(OLD_CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES})
#SET(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${GTHREAD_LIBRARIES})
# fails for some reason use check_library_exists instead and hope it's better
#CHECK_FUNCTION_EXISTS(g_thread_init HAVE_GTHREAD)
#SET(CMAKE_REQUIRED_LIBRARIES ${OLD_CMAKE_REQUIRED_LIBRARIES})
find_package ( OpenSSL QUIET )
if ( OPENSSL_FOUND )
message ( "-- OpenSSL version: ${OPENSSL_VERSION}" )
set ( HAVE_OPENSSL 1 )
else ( OPENSSL_FOUND )
message ( "-- OpenSSL not found" )
set ( OPENSSL_LIBRARIES "" )
endif ( OPENSSL_FOUND )
2018-03-23 11:29:46 +08:00
find_package ( ZLIB REQUIRED )
if ( ZLIB_FOUND )
message ( "-- ZLIB version: ${ZLIB_VERSION_STRING}" )
else ( ZLIB_FOUND )
message ( "-- ZLIB not found" )
endif ( ZLIB_FOUND )
2018-03-06 14:00:39 +08:00
IF ( ${ HAVE_SYS_TYPES_H } )
2018-04-04 15:19:12 +08:00
SET ( CMAKE_EXTRA_INCLUDE_FILES sys/types.h )
CHECK_TYPE_SIZE ( ulong HAVE_ULONG )
SET ( CMAKE_EXTRA_INCLUDE_FILES )
2018-03-06 14:00:39 +08:00
ENDIF ( ${ HAVE_SYS_TYPES_H } )
IF ( ${ HAVE_SYS_SOCKET_H } )
2018-04-04 15:19:12 +08:00
SET ( CMAKE_EXTRA_INCLUDE_FILES sys/socket.h )
CHECK_TYPE_SIZE ( socklen_t HAVE_SOCKLEN_T )
SET ( CMAKE_EXTRA_INCLUDE_FILES )
2018-03-06 14:00:39 +08:00
ENDIF ( ${ HAVE_SYS_SOCKET_H } )
IF ( ${ HAVE_SYS_RESOURCE_H } )
2018-04-04 15:19:12 +08:00
SET ( CMAKE_EXTRA_INCLUDE_FILES sys/resource.h )
CHECK_TYPE_SIZE ( rlim_t SIZEOF_RLIM_T )
SET ( CMAKE_EXTRA_INCLUDE_FILES )
2018-03-06 14:00:39 +08:00
ENDIF ( ${ HAVE_SYS_RESOURCE_H } )
SET ( OLD_CMAKE_REQUIRED_LIBRARIES ${ CMAKE_REQUIRED_LIBRARIES } )
MESSAGE ( STATUS "CMAKE_REQUIRED_LIBRARIES is ${CMAKE_REQUIRED_LIBRARIES}" )
SET ( CMAKE_REQUIRED_LIBRARIES ${ OLD_CMAKE_REQUIRED_LIBRARIES } )
IF ( GIT_REVISION )
ADD_DEFINITIONS ( -DCHASSIS_BUILD_TAG= "${GIT_REVISION}" )
ENDIF ( GIT_REVISION )
CONFIGURE_FILE ( config.h.cmake config.h )
ADD_DEFINITIONS ( -DHAVE_CONFIG_H )
SET ( PACKAGE_VERSION_ID "(${CPACK_PACKAGE_VERSION_MAJOR} << 16 | ${CPACK_PACKAGE_VERSION_MINOR} << 8 | ${CPACK_PACKAGE_VERSION_PATCH})" )
SET ( PACKAGE_VERSION_STRING "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}" )
SET ( PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}" )
SET ( PACKAGE_STRING "${CMAKE_PROJECT_NAME} ${CPACK_PACKAGE_VERSION}" )
ADD_DEFINITIONS (
2018-04-04 15:19:12 +08:00
- D P A C K A G E _ V E R S I O N _ I D = $ { P A C K A G E _ V E R S I O N _ I D }
- D P A C K A G E _ V E R S I O N = " $ { P A C K A G E _ V E R S I O N } "
- D P A C K A G E _ S T R I N G = " $ { P A C K A G E _ S T R I N G } "
- D P A C K A G E = " $ { C M A K E _ P R O J E C T _ N A M E } "
2018-03-06 14:00:39 +08:00
)
2018-06-06 16:05:33 +08:00
add_subdirectory ( libev )
2018-03-06 14:00:39 +08:00
ADD_SUBDIRECTORY ( src )
ADD_SUBDIRECTORY ( plugins )
IF ( EXISTS examples )
2018-04-04 15:19:12 +08:00
ADD_SUBDIRECTORY ( examples )
2018-03-06 14:00:39 +08:00
ENDIF ( EXISTS examples )
ADD_SUBDIRECTORY ( lib )
CONFIGURE_FILE ( mysql-chassis.pc.cmake mysql-chassis.pc @ONLY )
CONFIGURE_FILE ( cetus.pc.cmake cetus.pc @ONLY )
INSTALL ( FILES ${ CMAKE_CURRENT_BINARY_DIR } /mysql-chassis.pc
D E S T I N A T I O N l i b / p k g c o n f i g /
)
INSTALL ( FILES ${ CMAKE_CURRENT_BINARY_DIR } /cetus.pc
D E S T I N A T I O N l i b / p k g c o n f i g /
)
INSTALL ( FILES README_XA
D E S T I N A T I O N l o g s
)
install ( FILES
d o c / u s e r s . j s o n . e x a m p l e
d o c / v a r i a b l e s . j s o n . e x a m p l e
d o c / s h a r d i n g . j s o n . e x a m p l e
d o c / s h a r d . c o n f . e x a m p l e
d o c / p r o x y . c o n f . e x a m p l e
D E S T I N A T I O N c o n f
)