Commit e8113f75 authored by Marko Mäkelä's avatar Marko Mäkelä

CMake cleanup: Make WITH_URING, WITH_PMEM Boolean

The new default values WITH_URING:BOOL=OFF, WITH_PMEM:BOOL=OFF imply
that the dependencies are optional.
An explicit request WITH_URING=ON or WITH_PMEM=ON will cause the
build to fail if the requested dependencies are not available.

Last, to prevent a feature to be built in even though the built-time
dependencies are available, the following can be used:

cmake -DCMAKE_DISABLE_FIND_PACKAGE_URING=1
cmake -DCMAKE_DISABLE_FIND_PACKAGE_PMEM=1

This cleanup was suggested by Vladislav Vaintroub.
parent 4eeea4e2
...@@ -173,8 +173,6 @@ INCLUDE(systemd) ...@@ -173,8 +173,6 @@ INCLUDE(systemd)
INCLUDE(mysql_add_executable) INCLUDE(mysql_add_executable)
INCLUDE(symlinks) INCLUDE(symlinks)
INCLUDE(compile_flags) INCLUDE(compile_flags)
INCLUDE(pmem)
INCLUDE(uring)
# Handle options # Handle options
OPTION(DISABLE_SHARED OPTION(DISABLE_SHARED
...@@ -395,7 +393,7 @@ MYSQL_CHECK_READLINE() ...@@ -395,7 +393,7 @@ MYSQL_CHECK_READLINE()
SET(MALLOC_LIBRARY "system") SET(MALLOC_LIBRARY "system")
CHECK_PCRE() CHECK_PCRE()
CHECK_URING() ADD_SUBDIRECTORY(tpool)
CHECK_SYSTEMD() CHECK_SYSTEMD()
IF(CMAKE_CROSSCOMPILING) IF(CMAKE_CROSSCOMPILING)
...@@ -448,7 +446,6 @@ ADD_SUBDIRECTORY(client) ...@@ -448,7 +446,6 @@ ADD_SUBDIRECTORY(client)
ADD_SUBDIRECTORY(extra) ADD_SUBDIRECTORY(extra)
ADD_SUBDIRECTORY(libservices) ADD_SUBDIRECTORY(libservices)
ADD_SUBDIRECTORY(sql/share) ADD_SUBDIRECTORY(sql/share)
ADD_SUBDIRECTORY(tpool)
IF(NOT WITHOUT_SERVER) IF(NOT WITHOUT_SERVER)
ADD_SUBDIRECTORY(tests) ADD_SUBDIRECTORY(tests)
......
find_path(LIBPMEM_INCLUDE_DIR NAMES libpmem.h)
find_library(LIBPMEM_LIBRARIES NAMES pmem)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
PMEM DEFAULT_MSG
LIBPMEM_LIBRARIES LIBPMEM_INCLUDE_DIR)
mark_as_advanced(LIBPMEM_INCLUDE_DIR LIBPMEM_LIBRARIES)
find_path(LIBURING_INCLUDE_DIR NAMES liburing.h)
find_library(LIBURING_LIBRARIES NAMES uring)
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(
URING DEFAULT_MSG
LIBURING_LIBRARIES LIBURING_INCLUDE_DIR)
mark_as_advanced(LIBURING_INCLUDE_DIR LIBURING_LIBRARIES)
INCLUDE(CheckIncludeFiles)
SET(WITH_PMEM "auto" CACHE STRING "Enable persistent memory features")
IF(WITH_PMEM STREQUAL "yes" OR WITH_PMEM STREQUAL "auto")
FIND_LIBRARY(LIBPMEM pmem)
CHECK_INCLUDE_FILES(libpmem.h HAVE_LIBPMEM_H)
IF (NOT LIBPMEM)
IF(WITH_PMEM STREQUAL "yes")
MESSAGE(FATAL_ERROR "Can't find libpmem")
ENDIF()
UNSET(HAVE_LIBPMEM_H CACHE)
UNSET(LIBPMEM CACHE)
ELSEIF(NOT HAVE_LIBPMEM_H)
IF(WITH_PMEM STREQUAL "yes")
MESSAGE(FATAL_ERROR "Can't find libpmem.h")
ENDIF()
UNSET(HAVE_LIBPMEM_H CACHE)
UNSET(LIBPMEM CACHE)
ELSE()
ADD_DEFINITIONS(-DHAVE_PMEM)
ENDIF()
ELSEIF(WITH_PMEM STREQUAL "no")
UNSET(HAVE_LIBPMEM_H CACHE)
UNSET(LIBPMEM CACHE)
ELSE()
MESSAGE(FATAL_ERROR "Invalid value for WITH_PMEM. Must be 'yes', 'no', or 'auto'.")
ENDIF()
...@@ -49,7 +49,7 @@ MACRO(CHECK_SYSTEMD) ...@@ -49,7 +49,7 @@ MACRO(CHECK_SYSTEMD)
SET(SYSTEMD_EXECSTARTPRE "ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld") SET(SYSTEMD_EXECSTARTPRE "ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld")
SET(SYSTEMD_EXECSTARTPOST "ExecStartPost=/etc/mysql/debian-start") SET(SYSTEMD_EXECSTARTPOST "ExecStartPost=/etc/mysql/debian-start")
ENDIF() ENDIF()
IF(LIBURING AND HAVE_LIBURING_H AND NOT WITH_URING STREQUAL "no") IF(URING_FOUND)
SET(SYSTEMD_LIMIT "# For liburing and io_uring_setup() SET(SYSTEMD_LIMIT "# For liburing and io_uring_setup()
LimitMEMLOCK=524288") LimitMEMLOCK=524288")
ENDIF() ENDIF()
......
MACRO(CHECK_URING)
IF(CMAKE_SYSTEM_NAME MATCHES "Linux")
INCLUDE(CheckIncludeFiles)
SET(WITH_URING "auto" CACHE STRING "Enable liburing usage")
IF(WITH_URING STREQUAL "yes" OR WITH_URING STREQUAL "auto")
FIND_LIBRARY(LIBURING uring)
CHECK_INCLUDE_FILES(liburing.h HAVE_LIBURING_H)
IF (LIBURING AND HAVE_LIBURING_H)
ADD_DEFINITIONS(-DHAVE_URING)
LINK_LIBRARIES(uring)
ELSE()
IF(WITH_URING STREQUAL "yes")
MESSAGE(FATAL_ERROR "Requested WITH_URING=yes but liburing was not found")
ENDIF()
UNSET(LIBURING CACHE)
UNSET(HAVE_LIBURING_H CACHE)
ENDIF()
ELSEIF(WITH_URING STREQUAL "no")
UNSET(LIBURING CACHE)
UNSET(HAVE_LIBURING_H CACHE)
ELSE()
MESSAGE(FATAL_ERROR "Invalid value for WITH_URING. Must be 'yes', 'no', or 'auto'.")
ENDIF()
ENDIF()
ENDMACRO()
...@@ -336,21 +336,33 @@ SET(INNOBASE_SOURCES ...@@ -336,21 +336,33 @@ SET(INNOBASE_SOURCES
ut/ut0vec.cc ut/ut0vec.cc
ut/ut0wqueue.cc) ut/ut0wqueue.cc)
OPTION(WITH_PMEM "Support redo log in persistent memory" OFF)
FIND_PACKAGE(PMEM)
IF(PMEM_FOUND)
INCLUDE_DIRECTORIES(${LIBPMEM_INCLUDES})
ADD_COMPILE_FLAGS(log/log0log.cc COMPILE_FLAGS "-DHAVE_PMEM")
SET(PMEM_LIBRARY ${LIBPMEM_LIBRARIES})
ELSE()
IF(WITH_PMEM)
MESSAGE(FATAL_ERROR "WITH_PMEM=ON cannot be satisfied")
ENDIF()
ENDIF()
MYSQL_ADD_PLUGIN(innobase ${INNOBASE_SOURCES} STORAGE_ENGINE MYSQL_ADD_PLUGIN(innobase ${INNOBASE_SOURCES} STORAGE_ENGINE
MODULE_OUTPUT_NAME ha_innodb MODULE_OUTPUT_NAME ha_innodb
DEFAULT RECOMPILE_FOR_EMBEDDED DEFAULT RECOMPILE_FOR_EMBEDDED
LINK_LIBRARIES LINK_LIBRARIES
${ZLIB_LIBRARY} ${ZLIB_LIBRARY}
${PMEM_LIBRARY}
${NUMA_LIBRARY} ${NUMA_LIBRARY}
${LIBSYSTEMD} ${LIBSYSTEMD}
${LINKER_SCRIPT} ${LINKER_SCRIPT})
${LIBPMEM})
IF(NOT TARGET innobase) IF(NOT TARGET innobase)
RETURN() RETURN()
ENDIF() ENDIF()
ADD_DEFINITIONS(${SSL_DEFINES}) ADD_DEFINITIONS(${SSL_DEFINES} ${TPOOL_DEFINES})
# A GCC bug causes crash when compiling these files on ARM64 with -O1+ # A GCC bug causes crash when compiling these files on ARM64 with -O1+
# Compile them with -O0 as a workaround. # Compile them with -O0 as a workaround.
......
# Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 2017, 2020, MariaDB Corporation. # Copyright (c) 2017, 2021, MariaDB Corporation.
# #
# This program is free software; you can redistribute it and/or modify # 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 # it under the terms of the GNU General Public License as published by
...@@ -56,12 +56,12 @@ IF(UNIX) ...@@ -56,12 +56,12 @@ IF(UNIX)
ADD_DEFINITIONS("-DUNIV_LINUX -D_GNU_SOURCE=1") ADD_DEFINITIONS("-DUNIV_LINUX -D_GNU_SOURCE=1")
IF (NOT LIBURING) IF (NOT URING_FOUND)
CHECK_INCLUDE_FILES (libaio.h HAVE_LIBAIO_H) CHECK_INCLUDE_FILES (libaio.h HAVE_LIBAIO_H)
CHECK_LIBRARY_EXISTS(aio io_queue_init "" HAVE_LIBAIO) CHECK_LIBRARY_EXISTS(aio io_queue_init "" HAVE_LIBAIO)
IF(HAVE_LIBAIO_H AND HAVE_LIBAIO) IF(HAVE_LIBAIO_H AND HAVE_LIBAIO)
ADD_DEFINITIONS(-DLINUX_NATIVE_AIO=1) ADD_DEFINITIONS(-DLINUX_NATIVE_AIO)
LINK_LIBRARIES(aio) LINK_LIBRARIES(aio)
ENDIF() ENDIF()
ENDIF() ENDIF()
......
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include)
IF(WIN32) IF(WIN32)
SET(EXTRA_SOURCES tpool_win.cc aio_win.cc) SET(EXTRA_SOURCES tpool_win.cc aio_win.cc)
ENDIF() ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
OPTION(WITH_URING "Require that io_uring be used" OFF)
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND LIBURING) FIND_PACKAGE(URING)
SET(EXTRA_SOURCES aio_liburing.cc) IF(URING_FOUND)
ENDIF() SET(URING_FOUND ${URING_FOUND} PARENT_SCOPE)
SET(TPOOL_DEFINES "-DHAVE_URING" PARENT_SCOPE)
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT LIBURING) ADD_DEFINITIONS(-DHAVE_URING)
CHECK_INCLUDE_FILES (libaio.h HAVE_LIBAIO_H) LINK_LIBRARIES(${LIBURING_LIBRARIES})
CHECK_LIBRARY_EXISTS(aio io_queue_init "" HAVE_LIBAIO) INCLUDE_DIRECTORIES(${LIBURING_INCLUDE_DIR})
IF(HAVE_LIBAIO_H AND HAVE_LIBAIO) SET(EXTRA_SOURCES aio_liburing.cc)
ADD_DEFINITIONS(-DLINUX_NATIVE_AIO=1) ELSE()
LINK_LIBRARIES(aio) IF(WITH_URING)
SET(EXTRA_SOURCES aio_linux.cc) MESSAGE(FATAL_ERROR "WITH_URING=ON cannot be satisfied")
ENDIF() ENDIF()
CHECK_INCLUDE_FILES (libaio.h HAVE_LIBAIO_H)
CHECK_LIBRARY_EXISTS(aio io_queue_init "" HAVE_LIBAIO)
IF(HAVE_LIBAIO_H AND HAVE_LIBAIO)
SET(TPOOL_DEFINES "-DLINUX_NATIVE_AIO" PARENT_SCOPE)
ADD_DEFINITIONS(-DLINUX_NATIVE_AIO)
LINK_LIBRARIES(aio)
SET(EXTRA_SOURCES aio_linux.cc)
ENDIF()
ENDIF()
ENDIF() ENDIF()
ADD_LIBRARY(tpool STATIC ADD_LIBRARY(tpool STATIC
...@@ -29,8 +38,6 @@ ADD_LIBRARY(tpool STATIC ...@@ -29,8 +38,6 @@ ADD_LIBRARY(tpool STATIC
${EXTRA_SOURCES} ${EXTRA_SOURCES}
) )
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND LIBURING) IF(URING_FOUND)
ADD_DEPENDENCIES(tpool GenError) ADD_DEPENDENCIES(tpool GenError)
ENDIF() ENDIF()
INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/include)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment