# Copyright (C) 2006-2008 MySQL AB, 2009 Sun Microsystems, Inc # # 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 CMAKE_MINIMUM_REQUIRED(VERSION 2.6.0 FATAL_ERROR) # First, decide about build type (debug or release) # If custom compiler flags are set or cmake is invoked with -DCMAKE_BUILD_TYPE, # respect user wishes and do not (re)define CMAKE_BUILD_TYPE. If WITH_DEBUG{_FULL} # is given, set CMAKE_BUILD_TYPE = Debug. Otherwise, use Relwithdebinfo. IF(CMAKE_BUILD_TYPE) SET(HAVE_CMAKE_BUILD_TYPE TRUE) ENDIF() SET(CUSTOM_C_FLAGS $ENV{CFLAGS}) IF(NOT CUSTOM_C_FLAGS) SET(CUSTOM_C_FLAGS ${CMAKE_C_FLAGS}) ENDIF() OPTION(WITH_DEBUG "Use dbug" OFF) OPTION(WITH_DEBUG_FULL "Use dbug and safemalloc/safemutex. Slow" OFF) IF(NOT HAVE_CMAKE_BUILD_TYPE AND NOT CUSTOM_C_FLAGS) IF(WITH_DEBUG) SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Debug build" FORCE) ELSE() SET(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING "RelWithDebInfo build" FORCE) ENDIF() ENDIF() IF(WITH_DEBUG_FULL) SET(WITH_DEBUG ON CACHE BOOL "Use DBUG") ENDIF() PROJECT(MySQL) IF(CYGWIN) SET(WIN32 0) ENDIF() IF(WIN32) SET(IF_WIN 0) ELSE() SET(IF_WIN 1) ENDIF() # Add macros INCLUDE(cmake/character_sets.cmake) INCLUDE(cmake/zlib.cmake) INCLUDE(cmake/ssl.cmake) INCLUDE(cmake/readline.cmake) INCLUDE(cmake/mysql_version.cmake) INCLUDE(cmake/libutils.cmake) INCLUDE(cmake/dtrace.cmake) INCLUDE(cmake/plugin.cmake) INCLUDE(cmake/install_macros.cmake) # Handle options OPTION(DISABLE_SHARED "Don't build shared libraries, compile code as position-dependent" OFF) IF(DISABLE_SHARED) SET(WITHOUT_DYNAMIC_PLUGINS 1) ENDIF() OPTION(ENABLED_PROFILING "Enable profiling" ON) OPTION(CYBOZU "" OFF) OPTION(BACKUP_TEST "" OFF) OPTION(WITHOUT_SERVER OFF) MARK_AS_ADVANCED(CYBOZU BACKUP_TEST WITHOUT_SERVER DISABLE_SHARED) OPTION(ENABLE_DEBUG_SYNC "Enable debug sync (debug builds only)" ON) IF(ENABLE_DEBUG_SYNC) SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DENABLED_DEBUG_SYNC") SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DENABLED_DEBUG_SYNC") ENDIF() OPTION(WITH_ERROR_INJECT "Enable error injection in MySQL Server (debug builds only)" OFF) IF(WITH_ERROR_INJECT) SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DERROR_INJECT_SUPPORT") SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -DERROR_INJECT_SUPPORT") ENDIF() OPTION(ENABLE_LOCAL_INFILE "If we should should enable LOAD DATA LOCAL by default" ${IF_WIN}) MARK_AS_ADVANCED(ENABLE_LOCAL_INFILE) # Set DBUG_OFF for non-debug project types. FOREACH(BUILD_TYPE RELEASE RELWITHDEBINFO MINSIZEREL) FOREACH(LANG C CXX) SET(CMAKE_${LANG}_FLAGS_${BUILD_TYPE} "${CMAKE_${LANG}_FLAGS_${BUILD_TYPE}} -DDBUG_OFF") ENDFOREACH() ENDFOREACH() IF(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_GENERATOR MATCHES "Visual Studio" AND NOT CMAKE_GENERATOR MATCHES "Xcode") # This is the case of no CMAKE_BUILD_TYPE choosen, typical for VS and Xcode # or if custom C flags are set. In VS and Xcode for non-Debug configurations # DBUG_OFF is already correctly set. Use DBUG_OFF for Makefile based projects # without build type too, unless user specifically requests DBUG. IF(NOT CMAKE_C_FLAGS MATCHES "-DDBUG_ON") ADD_DEFINITIONS(-DDBUG_OFF) ENDIF() ENDIF() # Add safemalloc and safemutex for debug condifurations, except on Windows # (C runtime library provides safemalloc functionality and safemutex has never # worked there) IF(WITH_DEBUG OR WITH_DEBUG_FULL AND NOT WIN32) FOREACH(LANG C CXX) IF(WITH_DEBUG_FULL) SET(CMAKE_${LANG}_FLAGS_DEBUG "-DSAFEMALLOC -DSAFE_MUTEX") ELSE() SET(CMAKE_${LANG}_FLAGS_DEBUG "-DSAFE_MUTEX") ENDIF() ENDFOREACH() ENDIF() # Set commonly used variables IF(WIN32) SET(DEFAULT_MYSQL_HOME "C:/Program Files/MySQL/MySQL Server ${MYSQL_BASE_VERSION}/" ) SET(SHAREDIR share) ELSE() SET(DEFAULT_MYSQL_HOME ${CMAKE_INSTALL_PREFIX}) SET(SHAREDIR ${DEFAULT_MYSQL_HOME}share) ENDIF() SET(DEFAULT_BASEDIR "${DEFAULT_MYSQL_HOME}") SET(MYSQL_DATADIR "${DEFAULT_MYSQL_HOME}data") SET(DEFAULT_CHARSET_HOME "${DEFAULT_MYSQL_HOME}") # Optionally read user configuration, generated by configure.js. # This is left for backward compatibility reasons only. IF(WIN32) INCLUDE(win/configure.data OPTIONAL) ENDIF() # Run platform tests INCLUDE(configure.cmake) # Common defines and includes ADD_DEFINITIONS(-DHAVE_CONFIG_H) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include) # Add bundled or system zlib. MYSQL_CHECK_ZLIB_WITH_COMPRESS() # Optionally add bundled yassl/taocrypt or system openssl. MYSQL_CHECK_SSL() # Add readline or libedit. MYSQL_CHECK_READLINE() IF(NOT WITHOUT_SERVER) # Add storage engines and plugins. CONFIGURE_PLUGINS() ENDIF() ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(dbug) ADD_SUBDIRECTORY(strings) ADD_SUBDIRECTORY(vio) ADD_SUBDIRECTORY(regex) ADD_SUBDIRECTORY(mysys) ADD_SUBDIRECTORY(libmysql) OPTION (WITH_UNIT_TESTS "Compile MySQL with unit tests" ON) IF(WITH_UNIT_TESTS) ENABLE_TESTING() ENDIF() IF(WITH_UNIT_TESTS) ADD_SUBDIRECTORY(unittest/mytap) ADD_SUBDIRECTORY(unittest/mysys) ENDIF() IF(NOT WITHOUT_SERVER) ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(extra) ADD_SUBDIRECTORY(client) ADD_SUBDIRECTORY(sql) ADD_SUBDIRECTORY(sql/share) ADD_SUBDIRECTORY(libservices) OPTION (WITH_EMBEDDED_SERVER "Compile MySQL with embedded server" OFF) IF(WITH_EMBEDDED_SERVER) ADD_SUBDIRECTORY(libmysqld) ADD_SUBDIRECTORY(libmysqld/examples) ENDIF(WITH_EMBEDDED_SERVER) ADD_SUBDIRECTORY(mysql-test) ADD_SUBDIRECTORY(mysql-test/lib/My/SafeProcess) ADD_SUBDIRECTORY(support-files) ADD_SUBDIRECTORY(scripts) ADD_SUBDIRECTORY(sql-bench) IF(UNIX) ADD_SUBDIRECTORY(man) ENDIF() ENDIF() INCLUDE(cmake/abi_check.cmake) CONFIGURE_FILE(config.h.cmake ${CMAKE_BINARY_DIR}/include/my_config.h) CONFIGURE_FILE(config.h.cmake ${CMAKE_BINARY_DIR}/include/config.h) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/include/mysql_version.h.in ${CMAKE_BINARY_DIR}/include/mysql_version.h ) # Packaging IF(WIN32) SET(CPACK_GENERATOR "ZIP") ELSE() SET(CPACK_GENERATOR "TGZ") ENDIF() INCLUDE(CPack) INSTALL(FILES COPYING EXCEPTIONS-CLIENT README DESTINATION .) IF(UNIX) INSTALL(FILES Docs/INSTALL-BINARY DESTINATION .) ENDIF()