Skip to content

MDEV-37996 CMake: INTERFACE targets for bundled-or-system libraries#5311

Open
vaintroub wants to merge 2 commits into
10.11from
MDEV-37996
Open

MDEV-37996 CMake: INTERFACE targets for bundled-or-system libraries#5311
vaintroub wants to merge 2 commits into
10.11from
MDEV-37996

Conversation

@vaintroub

@vaintroub vaintroub commented Jun 30, 2026

Copy link
Copy Markdown
Member

Stop overwriting the standard find_package() result variables (ZLIB_FOUND, ZLIB_LIBRARIES, ZLIB_INCLUDE_DIR(S), ...), this breaks vcpkg.

Provide namespaced INTERFACE targets that point at either the bundled or the system library and carry their include directories (and, for SSL, the compile definitions):

MariaDB::zlib, MariaDB::OpenSSL, MariaDB::pcre2-8, MariaDB::pcre2-posix,
MariaDB::fmt, MariaDB::readline

Link these consistently instead of the scattered ${*_LIBRARIES} and ${*_INCLUDE_DIR(S)} variables sprinkled across the tree.

@vaintroub vaintroub changed the title MDEV-37996 CMake: MariaDB:: targets for bundled-or-system libraries MDEV-37996 CMake: INTERFACE targets for bundled-or-system libraries Jun 30, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the MariaDB build system to use modern CMake target-based dependency management (such as MariaDB::zlib, MariaDB::OpenSSL, and MariaDB::pcre2) instead of global directory-level include variables. While this is a great improvement, several issues were identified where removing the old include variables will break compilation. Specifically, the mariadb_ssl target must be defined even when SSL is disabled to prevent a fatal CMake error, client tools and performance schema unit tests will fail to compile due to missing transitive zlib and SSL headers, and the sql target needs to explicitly link to MariaDB::zlib to inherit its include directories.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread cmake/ssl.cmake
MESSAGE(FATAL_ERROR
"Wrong option for WITH_SSL. Valid values are: ${WITH_SSL_DOC}")
ENDIF()
ADD_LIBRARY(MariaDB::OpenSSL ALIAS mariadb_ssl)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

If WITH_SSL is set to no or none (disabling SSL), the mariadb_ssl target is never created. This causes a fatal CMake error when ADD_LIBRARY(MariaDB::OpenSSL ALIAS mariadb_ssl) is called unconditionally at the end of the macro. To prevent this, ensure mariadb_ssl is always defined (even as an empty INTERFACE library) if it does not already exist.

  IF(NOT TARGET mariadb_ssl)
    ADD_LIBRARY(mariadb_ssl INTERFACE)
  ENDIF()
  ADD_LIBRARY(MariaDB::OpenSSL ALIAS mariadb_ssl)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can't compile without SSL.

Comment thread client/CMakeLists.txt
${CMAKE_SOURCE_DIR}/mysys_ssl
${ZLIB_INCLUDE_DIRS}
${SSL_INCLUDE_DIRS}
$<TARGET_PROPERTY:mariadb_ssl,INTERFACE_INCLUDE_DIRECTORIES>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The ${ZLIB_INCLUDE_DIRS} variable was removed from the directory-level INCLUDE_DIRECTORIES in client/CMakeLists.txt, but it was not replaced with $<TARGET_PROPERTY:mariadb_zlib,INTERFACE_INCLUDE_DIRECTORIES>. Since client tools (such as mysqldump or mysqlbinlog) directly or transitively include zlib.h, and they do not link directly to MariaDB::zlib (they link to ${CLIENT_LIB} which is libmariadb), this will cause compilation failures when using a bundled or non-standard zlib. Please add the mariadb_zlib interface include directories here.

  $<TARGET_PROPERTY:mariadb_zlib,INTERFACE_INCLUDE_DIRECTORIES>
  $<TARGET_PROPERTY:mariadb_ssl,INTERFACE_INCLUDE_DIRECTORIES>

INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/include/mysql
${PCRE_INCLUDE_DIRS}
${CMAKE_SOURCE_DIR}/sql

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Removing ${SSL_INCLUDE_DIRS} from storage/perfschema/unittest/CMakeLists.txt will break compilation of the performance schema unit tests when SSL is enabled, because they transitively include <openssl/ssl.h> via server headers (e.g., violite.h). Since these unit tests are not plugins and do not use MYSQL_ADD_PLUGIN, they do not inherit the common include directories defined in cmake/plugin.cmake. Please add $<TARGET_PROPERTY:mariadb_ssl,INTERFACE_INCLUDE_DIRECTORIES> to the include directories list.

                    ${CMAKE_SOURCE_DIR}/sql
                    $<TARGET_PROPERTY:mariadb_ssl,INTERFACE_INCLUDE_DIRECTORIES>

Comment thread sql/CMakeLists.txt
tpool
${LIBWRAP} ${LIBCRYPT} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}
${SSL_LIBRARIES}
MariaDB::OpenSSL MariaDB::fmt

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The sql target directly includes and uses zlib.h (e.g., in sql_compress.cc and other files). Since ${ZLIB_INCLUDE_DIRS} was removed from the directory-level INCLUDE_DIRECTORIES in sql/CMakeLists.txt, the sql target should explicitly link to MariaDB::zlib to inherit its include directories and link flags, adhering to the "link what you use" principle.

  MariaDB::OpenSSL MariaDB::fmt MariaDB::zlib

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is no sql_compress.cc

Stop overwriting the standard find_package() result variables (ZLIB_FOUND,
ZLIB_LIBRARIES, ZLIB_INCLUDE_DIR(S), ...), this breaks vcpkg.

Provide namespaced INTERFACE targets that point at either the bundled or
the system library and carry their include directories (and, for SSL, the
compile definitions):

  MariaDB::zlib, MariaDB::OpenSSL, MariaDB::pcre2-8, MariaDB::pcre2-posix,
  MariaDB::fmt, MariaDB::readline

Link these consistently instead of the scattered ${*_LIBRARIES} and
${*_INCLUDE_DIR(S)} variables sprinkled across the tree.
@vaintroub vaintroub force-pushed the MDEV-37996 branch 2 times, most recently from 1c6d18b to c9b660d Compare June 30, 2026 21:41
Remove hack in cmake/mariadb_connector_c.cmake that sets variables
to make connectors FIND_PACKAGE(ZLIB) use server's zlib.
it is not necessary anymore, and is expressed more directly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant