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)
INCLUDE(mysql_add_executable)
INCLUDE(symlinks)
INCLUDE(compile_flags)
INCLUDE(pmem)
INCLUDE(uring)
# Handle options
OPTION(DISABLE_SHARED
......@@ -395,7 +393,7 @@ MYSQL_CHECK_READLINE()
SET(MALLOC_LIBRARY "system")
CHECK_PCRE()
CHECK_URING()
ADD_SUBDIRECTORY(tpool)
CHECK_SYSTEMD()
IF(CMAKE_CROSSCOMPILING)
......@@ -448,7 +446,6 @@ ADD_SUBDIRECTORY(client)
ADD_SUBDIRECTORY(extra)
ADD_SUBDIRECTORY(libservices)
ADD_SUBDIRECTORY(sql/share)
ADD_SUBDIRECTORY(tpool)
IF(NOT WITHOUT_SERVER)
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)
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")
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()
LimitMEMLOCK=524288")
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
ut/ut0vec.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
MODULE_OUTPUT_NAME ha_innodb
DEFAULT RECOMPILE_FOR_EMBEDDED
LINK_LIBRARIES
${ZLIB_LIBRARY}
${PMEM_LIBRARY}
${NUMA_LIBRARY}
${LIBSYSTEMD}
${LINKER_SCRIPT}
${LIBPMEM})
${LINKER_SCRIPT})
IF(NOT TARGET innobase)
RETURN()
ENDIF()
ADD_DEFINITIONS(${SSL_DEFINES})
ADD_DEFINITIONS(${SSL_DEFINES} ${TPOOL_DEFINES})
# A GCC bug causes crash when compiling these files on ARM64 with -O1+
# Compile them with -O0 as a workaround.
......
# 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
# it under the terms of the GNU General Public License as published by
......@@ -56,12 +56,12 @@ IF(UNIX)
ADD_DEFINITIONS("-DUNIV_LINUX -D_GNU_SOURCE=1")
IF (NOT LIBURING)
IF (NOT URING_FOUND)
CHECK_INCLUDE_FILES (libaio.h HAVE_LIBAIO_H)
CHECK_LIBRARY_EXISTS(aio io_queue_init "" HAVE_LIBAIO)
IF(HAVE_LIBAIO_H AND HAVE_LIBAIO)
ADD_DEFINITIONS(-DLINUX_NATIVE_AIO=1)
ADD_DEFINITIONS(-DLINUX_NATIVE_AIO)
LINK_LIBRARIES(aio)
ENDIF()
ENDIF()
......
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/include)
IF(WIN32)
SET(EXTRA_SOURCES tpool_win.cc aio_win.cc)
ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND LIBURING)
SET(EXTRA_SOURCES aio_liburing.cc)
ENDIF()
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND NOT LIBURING)
CHECK_INCLUDE_FILES (libaio.h HAVE_LIBAIO_H)
CHECK_LIBRARY_EXISTS(aio io_queue_init "" HAVE_LIBAIO)
IF(HAVE_LIBAIO_H AND HAVE_LIBAIO)
ADD_DEFINITIONS(-DLINUX_NATIVE_AIO=1)
LINK_LIBRARIES(aio)
SET(EXTRA_SOURCES aio_linux.cc)
ENDIF()
ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Linux")
OPTION(WITH_URING "Require that io_uring be used" OFF)
FIND_PACKAGE(URING)
IF(URING_FOUND)
SET(URING_FOUND ${URING_FOUND} PARENT_SCOPE)
SET(TPOOL_DEFINES "-DHAVE_URING" PARENT_SCOPE)
ADD_DEFINITIONS(-DHAVE_URING)
LINK_LIBRARIES(${LIBURING_LIBRARIES})
INCLUDE_DIRECTORIES(${LIBURING_INCLUDE_DIR})
SET(EXTRA_SOURCES aio_liburing.cc)
ELSE()
IF(WITH_URING)
MESSAGE(FATAL_ERROR "WITH_URING=ON cannot be satisfied")
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()
ADD_LIBRARY(tpool STATIC
......@@ -29,8 +38,6 @@ ADD_LIBRARY(tpool STATIC
${EXTRA_SOURCES}
)
IF(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND LIBURING)
IF(URING_FOUND)
ADD_DEPENDENCIES(tpool GenError)
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