From cb545f11169d2425316d96feafc78ac841950e43 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 23 Mar 2021 09:41:50 +0100 Subject: [PATCH] CMake cleanup - use FIND_PACKAGE(LIBAIO) to find libaio - Use standard CMake conventions in Find{PMEM,URING}.cmake - Drop the LIB from LIB{PMEM,URING}_{INCLUDE_DIR,LIBRARIES} It is cleaner, and consistent with how other packages are handled in CMake. e.g successful FIND_PACKAGE(PMEM) now sets PMEM_FOUND, PMEM_LIBRARIES, PMEM_INCLUDE_DIR, not LIBPMEM_{FOUND,LIBRARIES,INCLUDE_DIR}. - Decrease the output. use FIND_PACKAGE with QUIET argument. - for Linux packages, either liburing, or libaio is required If liburing is installed, libaio does not need to be present . Use FIND_PACKAGE([LIBAIO|URING] REQUIRED) if either library is required. --- cmake/FindLIBAIO.cmake | 7 ++++++ cmake/FindPMEM.cmake | 8 +++---- cmake/FindURING.cmake | 8 +++---- .../build_configurations/mysql_release.cmake | 20 ++++------------ storage/innobase/CMakeLists.txt | 6 ++--- storage/innobase/innodb.cmake | 11 --------- tpool/CMakeLists.txt | 23 +++++++++++-------- 7 files changed, 36 insertions(+), 47 deletions(-) create mode 100644 cmake/FindLIBAIO.cmake diff --git a/cmake/FindLIBAIO.cmake b/cmake/FindLIBAIO.cmake new file mode 100644 index 00000000000..db49439f318 --- /dev/null +++ b/cmake/FindLIBAIO.cmake @@ -0,0 +1,7 @@ +find_path(LIBAIO_INCLUDE_DIR NAMES libaio.h) +find_library(LIBAIO_LIBRARIES NAMES aio) + +include(FindPackageHandleStandardArgs) + FIND_PACKAGE_HANDLE_STANDARD_ARGS( + LIBAIO DEFAULT_MSG + LIBAIO_LIBRARIES LIBAIO_INCLUDE_DIR) diff --git a/cmake/FindPMEM.cmake b/cmake/FindPMEM.cmake index d5f0c24364a..7e3fafae560 100644 --- a/cmake/FindPMEM.cmake +++ b/cmake/FindPMEM.cmake @@ -1,9 +1,9 @@ -find_path(LIBPMEM_INCLUDE_DIR NAMES libpmem.h) -find_library(LIBPMEM_LIBRARIES NAMES pmem) +find_path(PMEM_INCLUDE_DIR NAMES libpmem.h) +find_library(PMEM_LIBRARIES NAMES pmem) include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS( PMEM DEFAULT_MSG - LIBPMEM_LIBRARIES LIBPMEM_INCLUDE_DIR) + PMEM_LIBRARIES PMEM_INCLUDE_DIR) -mark_as_advanced(LIBPMEM_INCLUDE_DIR LIBPMEM_LIBRARIES) +mark_as_advanced(PMEM_INCLUDE_DIR PMEM_LIBRARIES) diff --git a/cmake/FindURING.cmake b/cmake/FindURING.cmake index 014e9c31478..6e5e0783b46 100644 --- a/cmake/FindURING.cmake +++ b/cmake/FindURING.cmake @@ -1,9 +1,9 @@ -find_path(LIBURING_INCLUDE_DIR NAMES liburing.h) -find_library(LIBURING_LIBRARIES NAMES uring) +find_path(URING_INCLUDE_DIR NAMES liburing.h) +find_library(URING_LIBRARIES NAMES uring) include(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS( URING DEFAULT_MSG - LIBURING_LIBRARIES LIBURING_INCLUDE_DIR) + URING_LIBRARIES URING_INCLUDE_DIR) -mark_as_advanced(LIBURING_INCLUDE_DIR LIBURING_LIBRARIES) +mark_as_advanced(URING_INCLUDE_DIR URING_LIBRARIES) diff --git a/cmake/build_configurations/mysql_release.cmake b/cmake/build_configurations/mysql_release.cmake index d9e0b490bd7..08eccb7fb6b 100644 --- a/cmake/build_configurations/mysql_release.cmake +++ b/cmake/build_configurations/mysql_release.cmake @@ -135,15 +135,12 @@ IF(UNIX) SET(PLUGIN_AUTH_PAM YES CACHE BOOL "") IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") - IF(NOT IGNORE_AIO_CHECK) - # Ensure aio is available on Linux (required by InnoDB) - CHECK_INCLUDE_FILES(libaio.h HAVE_LIBAIO_H) - CHECK_LIBRARY_EXISTS(aio io_queue_init "" HAVE_LIBAIO) - IF(NOT HAVE_LIBAIO_H OR NOT HAVE_LIBAIO) - UNSET(HAVE_LIBAIO_H CACHE) - UNSET(HAVE_LIBAIO CACHE) + FIND_PACKAGE(URING) + FIND_PACKAGE(LIBAIO) + IF(NOT URING_FOUND AND NOT LIBAIO_FOUND AND NOT IGNORE_AIO_CHECK) MESSAGE(FATAL_ERROR " - aio is required on Linux, you need to install the required library: + Either liburing or libaio is required on Linux. + You can install libaio like this: Debian/Ubuntu: apt-get install libaio-dev RedHat/Fedora/Oracle Linux: yum install libaio-devel @@ -151,15 +148,8 @@ IF(UNIX) If you really do not want it, pass -DIGNORE_AIO_CHECK=YES to cmake. ") - ENDIF() - - # Unfortunately, linking shared libmysqld with static aio - # does not work, unless we add also dynamic one. This also means - # libmysqld.so will depend on libaio.so - #SET(LIBMYSQLD_SO_EXTRA_LIBS aio) ENDIF() ENDIF() - ENDIF() # Compiler options diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt index 9f60b53a042..4a20d6807a6 100644 --- a/storage/innobase/CMakeLists.txt +++ b/storage/innobase/CMakeLists.txt @@ -337,11 +337,11 @@ SET(INNOBASE_SOURCES ut/ut0wqueue.cc) OPTION(WITH_PMEM "Support redo log in persistent memory" OFF) -FIND_PACKAGE(PMEM) +FIND_PACKAGE(PMEM QUIET) IF(PMEM_FOUND) - INCLUDE_DIRECTORIES(${LIBPMEM_INCLUDES}) + INCLUDE_DIRECTORIES(${PMEM_INCLUDES}) ADD_COMPILE_FLAGS(log/log0log.cc COMPILE_FLAGS "-DHAVE_PMEM") - SET(PMEM_LIBRARY ${LIBPMEM_LIBRARIES}) + SET(PMEM_LIBRARY ${PMEM_LIBRARIES}) ELSE() IF(WITH_PMEM) MESSAGE(FATAL_ERROR "WITH_PMEM=ON cannot be satisfied") diff --git a/storage/innobase/innodb.cmake b/storage/innobase/innodb.cmake index 9c57feae3ff..5535be45645 100644 --- a/storage/innobase/innodb.cmake +++ b/storage/innobase/innodb.cmake @@ -53,18 +53,7 @@ ENDIF() # OS tests IF(UNIX) IF(CMAKE_SYSTEM_NAME STREQUAL "Linux") - ADD_DEFINITIONS("-DUNIV_LINUX -D_GNU_SOURCE=1") - - 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) - LINK_LIBRARIES(aio) - ENDIF() - ENDIF() IF(HAVE_LIBNUMA) LINK_LIBRARIES(numa) ENDIF() diff --git a/tpool/CMakeLists.txt b/tpool/CMakeLists.txt index 213cef7b5de..69440d09490 100644 --- a/tpool/CMakeLists.txt +++ b/tpool/CMakeLists.txt @@ -3,24 +3,27 @@ IF(WIN32) SET(EXTRA_SOURCES tpool_win.cc aio_win.cc) ELSEIF(CMAKE_SYSTEM_NAME STREQUAL "Linux") OPTION(WITH_URING "Require that io_uring be used" OFF) - FIND_PACKAGE(URING) + OPTION(WITH_LIBAIO "Require that libaio is used, unless uring is there" OFF) + IF(WITH_URING) + SET(URING_REQUIRED REQUIRED) + ELSEIF(WITH_LIBAIO) + SET(LIBAIO_REQIRED REQUIRED) + ENDIF() + FIND_PACKAGE(URING QUIET ${URING_REQUIRED}) 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}) + LINK_LIBRARIES(${URING_LIBRARIES}) + INCLUDE_DIRECTORIES(${URING_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) + FIND_PACKAGE(LIBAIO QUIET ${LIBAIO_REQUIRED}) + IF(LIBAIO_FOUND) SET(TPOOL_DEFINES "-DLINUX_NATIVE_AIO" PARENT_SCOPE) ADD_DEFINITIONS(-DLINUX_NATIVE_AIO) - LINK_LIBRARIES(aio) + INCLUDE_DIRECTORIES(${LIBAIO_INCLUDE_DIR}) + LINK_LIBRARIES(${LIBAIO_LIBRARIES}) SET(EXTRA_SOURCES aio_linux.cc) ENDIF() ENDIF()