Bug #116044 CMakeLists.txt Incorrectly Sets LINUX Flag
Submitted: 9 Sep 15:38 Modified: 10 Sep 5:15
Reporter: Steven Curry Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Compiling Severity:S3 (Non-critical)
Version:8.0.39 OS:Linux
Assigned to: CPU Architecture:Any

[9 Sep 15:38] Steven Curry
Description:
When building MySQL with the cmake option  -DBUILD_CONFIG=mysql_release , the configuration is supposed to enforce the presence of the  libaio  library on Linux systems, halting the cmake configuration if it is not found.

However, due to the improper order of inclusion in the  CMakeLists.txt , the platform-specific flag (such as LINUX) is not set correctly. Consequently, even when building MySQL from source on Linux with the cmake option  -DBUILD_CONFIG=mysql_release , the build does not halt if the  libaio  library is absent, contrary to expectations.

How to repeat:
1.The issue is present in versions after 8.0 (I have not checked the older versions below 8.0), you can choose any version such as 8.0.39.
2.On any Linux platform, do not install the  libaio  library.
3.Build MySQL from source with the cmake option  -DBUILD_CONFIG=mysql_release

Expected Behavior: 
The cmake configuration should abort with an error message indicating the requirement of the  libaio  library:
aio is required on Linux, you need to install the required library:

          Debian/Ubuntu:              apt-get install libaio-dev
          RedHat/Fedora/Oracle Linux: yum install libaio-devel
          SuSE:                       zypper install libaio-devel

        If you really do not want it, pass -DIGNORE_AIO_CHECK to cmake.

Actual Behavior: The build proceeds normally without  libaio , and the lack of this library is only reported during the make process.

Test Environment:
1.Operating System: Ubuntu 22.04
2.CMake Version: Not related to the version of cmake
3.MySQL Version: Tested with version 8.0.39
4.Compiler: gcc

Suggested fix:
1.The  cmake/build_configurations/mysql_release.cmake  file checks for the LINUX flag and only enters the logic to detect the presence of the  libaio  library if LINUX is set.

2.A global search for the LINUX flag reveals it is only set in  cmake/os/Linux.cmake :
   SET(LINUX 1)

3.However, cmake/os/${platform}.cmake  is included in the  CMakeLists.txt  as follows:# Include the platform-specific file. To allow exceptions, this code
# looks for files in order of how specific they are. If there is, for
# example, a generic Linux.cmake and a version-specific
# Linux-2.6.28-11-generic, it will pick Linux-2.6.28-11-generic and
# include it. It is then up to the file writer to include the generic
# version if necessary.
FOREACH(_base
    ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}-${CMAKE_SYSTEM_PROCESSOR}
    ${CMAKE_SYSTEM_NAME}-${CMAKE_SYSTEM_VERSION}
    ${CMAKE_SYSTEM_NAME})
  SET(_file ${CMAKE_SOURCE_DIR}/cmake/os/${_base}.cmake)
  IF(EXISTS ${_file})
    INCLUDE(${_file})
    BREAK()
  ENDIF()
ENDFOREACH()

4.The inclusion of  cmake/build_configurations/mysql_release.cmake  should be adjusted to occur after the inclusion of  cmake/os/${platform}.cmake  in the  CMakeLists.txt .

By swapping the order of file inclusion in the  CMakeLists.txt , including the platform-specific CMake files before the  BUILD_CONFIG  related files, the issue can be resolved.
[10 Sep 5:15] MySQL Verification Team
Please do not submit the same bug more than once. An existing bug report Bug #116043 already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments to the original bug instead.

Thank you for your interest in MySQL.